diff --git a/.github/workflows/sync_dependabot-changesets.yml b/.github/workflows/sync_dependabot-changesets.yml index 4f9c90a363..4f3bbee376 100644 --- a/.github/workflows/sync_dependabot-changesets.yml +++ b/.github/workflows/sync_dependabot-changesets.yml @@ -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