Merge pull request #33156 from backstage/freben/dependabot-dedupe
ci: dedupe yarn.lock in Dependabot PR workflow
This commit is contained in:
@@ -21,11 +21,47 @@ 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
|
||||
changed=false
|
||||
|
||||
for dir in . docs-ui microsite; do
|
||||
if [ "$dir" = "." ]; then lockfile=yarn.lock; else lockfile="$dir/yarn.lock"; fi
|
||||
if git diff --name-only HEAD~1 | grep -q "^${lockfile}$"; then
|
||||
yarn --cwd "$dir" dedupe
|
||||
if ! git diff --quiet "$lockfile"; then
|
||||
git add "$lockfile"
|
||||
changed=true
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
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:
|
||||
script: |
|
||||
@@ -50,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');
|
||||
|
||||
@@ -79,5 +109,9 @@ jobs:
|
||||
const { stdout: commitMessage } = await exec.getExecOutput('git show --pretty=format:%s -s HEAD');
|
||||
await createChangeset(fileName, commitMessage, packageNames);
|
||||
await exec.exec('git', ['add', fileName]);
|
||||
await exec.exec('git commit -C HEAD --amend --no-edit');
|
||||
await exec.exec('git push --force');
|
||||
core.setOutput('changed', 'true');
|
||||
- name: Commit and push
|
||||
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