ci: add upfront dependabot branch check
Move the branch verification to a separate step right after checkout, and gate all subsequent steps on its output. Removes the redundant branch check from inside the changeset generation script. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Fredrik Adelöw <freben@spotify.com>
This commit is contained in:
@@ -21,15 +21,27 @@ jobs:
|
||||
fetch-depth: 2
|
||||
ref: ${{ github.head_ref }}
|
||||
token: ${{ secrets.GH_SERVICE_ACCOUNT_TOKEN }}
|
||||
- name: Verify Dependabot branch
|
||||
id: verify
|
||||
run: |
|
||||
if git branch --show-current | grep -q '^dependabot/'; then
|
||||
echo "is_dependabot=true" >> "$GITHUB_OUTPUT"
|
||||
else
|
||||
echo "Not a dependabot branch, skipping"
|
||||
echo "is_dependabot=false" >> "$GITHUB_OUTPUT"
|
||||
fi
|
||||
- name: Configure Git
|
||||
if: steps.verify.outputs.is_dependabot == 'true'
|
||||
run: |
|
||||
git config --global user.email noreply@backstage.io
|
||||
git config --global user.name 'Github changeset workflow'
|
||||
- name: Setup Node
|
||||
if: steps.verify.outputs.is_dependabot == 'true'
|
||||
uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0
|
||||
with:
|
||||
node-version: 22.x
|
||||
- name: Dedupe lockfiles
|
||||
if: steps.verify.outputs.is_dependabot == 'true'
|
||||
id: dedupe
|
||||
run: |
|
||||
corepack enable
|
||||
@@ -48,6 +60,7 @@ jobs:
|
||||
|
||||
echo "changed=$changed" >> "$GITHUB_OUTPUT"
|
||||
- name: Generate changeset
|
||||
if: steps.verify.outputs.is_dependabot == 'true'
|
||||
id: changeset
|
||||
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
|
||||
with:
|
||||
@@ -73,12 +86,6 @@ jobs:
|
||||
await fs.writeFile(fileName, body);
|
||||
}
|
||||
|
||||
const branch = await exec.getExecOutput('git branch --show-current');
|
||||
if (!branch.stdout.startsWith('dependabot/')) {
|
||||
console.log('Not a dependabot branch, skipping');
|
||||
return;
|
||||
}
|
||||
|
||||
const diffOutput = await exec.getExecOutput('git diff --name-only HEAD~1');
|
||||
const diffFiles = diffOutput.stdout.split('\n');
|
||||
|
||||
@@ -104,7 +111,7 @@ jobs:
|
||||
await exec.exec('git', ['add', fileName]);
|
||||
core.setOutput('changed', 'true');
|
||||
- name: Commit and push
|
||||
if: steps.dedupe.outputs.changed == 'true' || steps.changeset.outputs.changed == 'true'
|
||||
if: steps.verify.outputs.is_dependabot == 'true' && (steps.dedupe.outputs.changed == 'true' || steps.changeset.outputs.changed == 'true')
|
||||
run: |
|
||||
git commit -C HEAD --amend --no-edit
|
||||
git push --force
|
||||
|
||||
Reference in New Issue
Block a user