Skip to content

Commit a894629

Browse files
authored
ci: fix added commits breaking CI validation (#7393)
The added commit does not match our permission claim, so we just skip that part in case it is not pushed by dependabot anymore.
1 parent 1f1a502 commit a894629

File tree

3 files changed

+49
-2
lines changed

3 files changed

+49
-2
lines changed

.github/workflows/dependabot-automation.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,27 @@ jobs:
1515
dependabot:
1616
if: github.event.pull_request.user.login == 'dependabot[bot]'
1717
runs-on: ubuntu-latest
18+
# Keep this job as a stable, always-green check on Dependabot PRs, even when the workflow is
19+
# re-triggered by an automation commit (e.g., vendoring). Sensitive operations (OIDC token mint,
20+
# approving, enabling auto-merge) are delegated to `dependabot-automation` below.
21+
permissions:
22+
contents: read
23+
steps:
24+
- name: Status
25+
run: |
26+
echo "Dependabot PR detected."
27+
if [ "${{ github.actor }}" = "dependabot[bot]" ]; then
28+
echo "Automation steps will run in the 'dependabot-automation' job."
29+
else
30+
echo "Skipping automation: workflow actor is '${{ github.actor }}'."
31+
fi
32+
33+
dependabot-automation:
34+
# Only run automation on the initial Dependabot-triggered run. If an automation commit is pushed
35+
# (e.g. vendor output), GitHub re-triggers this workflow with `github.actor == 'dd-octo-sts[bot]'`.
36+
# We intentionally avoid minting tokens / approving / enabling auto-merge on that follow-up run.
37+
if: github.event.pull_request.user.login == 'dependabot[bot]' && github.actor == 'dependabot[bot]'
38+
runs-on: ubuntu-latest
1839
permissions:
1940
id-token: write
2041
steps:
@@ -150,6 +171,11 @@ jobs:
150171
with:
151172
scope: DataDog/dd-trace-js
152173
policy: dependabot-automation
174+
- name: Dependabot metadata
175+
id: metadata
176+
uses: dependabot/fetch-metadata@21025c705c08248db411dc16f3619e6b5f9ea21a # 2.5.0
177+
with:
178+
github-token: "${{ steps.octo-sts.outputs.token }}"
153179
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
154180
with:
155181
token: ${{ steps.octo-sts.outputs.token }}
@@ -209,6 +235,22 @@ jobs:
209235
auth_header="AUTHORIZATION: basic $(printf 'x-access-token:%s' "$DD_OCTO_STS_TOKEN" | base64 | tr -d '\n')"
210236
git -c "http.https://github.com/.extraheader=$auth_header" push origin "HEAD:$TARGET_BRANCH"
211237
238+
# If branch protection is configured to dismiss stale approvals when new commits are pushed,
239+
# the vendoring commit will invalidate the earlier approval. Re-approve and (re-)enable
240+
# auto-merge after pushing so Dependabot PRs can still merge automatically.
241+
- name: Approve a PR (after vendoring commit)
242+
if: contains(fromJSON(env.GROUPS), steps.metadata.outputs.dependency-group)
243+
run: gh pr review --approve "$PR_URL"
244+
env:
245+
PR_URL: ${{ github.event.pull_request.html_url }}
246+
GH_TOKEN: ${{ steps.octo-sts.outputs.token }}
247+
- name: Enable auto-merge for Dependabot PRs (after vendoring commit)
248+
if: contains(fromJSON(env.GROUPS), steps.metadata.outputs.dependency-group)
249+
run: gh pr merge --auto --squash "$PR_URL"
250+
env:
251+
PR_URL: ${{ github.event.pull_request.html_url }}
252+
GH_TOKEN: ${{ steps.octo-sts.outputs.token }}
253+
212254
vendor-validate:
213255
# Run validation after the generated vendor patch has been pushed, to ensure the PR contains
214256
# the committed `vendor/dist/*` outputs. This runs inside the same workflow as the push, so it

.github/workflows/project.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,10 @@ jobs:
198198
if-no-files-found: error
199199

200200
yarn-dedupe-push:
201-
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository && needs.yarn-dedupe.outputs.has_changes == 'true'
201+
# If this job pushes a commit, GitHub will re-trigger the workflow on `pull_request:synchronize`
202+
# with `github.actor == 'dd-octo-sts[bot]'`. Never attempt to mint another token / push again on
203+
# that follow-up run.
204+
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository && needs.yarn-dedupe.outputs.has_changes == 'true' && github.actor != 'dd-octo-sts[bot]'
202205
runs-on: ubuntu-latest
203206
needs: yarn-dedupe
204207
# Security: this job has an STS-minted token, but never runs installs/builds.

.github/workflows/update-3rdparty-licenses.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ jobs:
7070
PR_USER_TYPE: ${{ github.event.pull_request.user.type }}
7171
GITHUB_EVENT_NAME: ${{ github.event_name }}
7272
GITHUB_HEAD_REF: ${{ github.head_ref }}
73+
PR_HEAD_REPO: ${{ github.event.pull_request.head.repo.full_name }}
74+
BASE_REPO: ${{ github.repository }}
7375
run: |
7476
set -e
7577
@@ -78,7 +80,7 @@ jobs:
7880
else
7981
echo "📝 LICENSE-3rdparty.csv was modified by license attribution command"
8082
81-
if [[ "$PR_USER_TYPE" == "Bot" ]] && [[ "${GITHUB_EVENT_NAME}" == "pull_request" ]]; then
83+
if [[ "$PR_USER_TYPE" == "Bot" ]] && [[ "${GITHUB_EVENT_NAME}" == "pull_request" ]] && [[ "$PR_HEAD_REPO" == "$BASE_REPO" ]]; then
8284
echo "🤖 Bot-created PR detected. Auto-committing LICENSE-3rdparty.csv changes..."
8385
8486
git config --local user.email "[email protected]"

0 commit comments

Comments
 (0)