Skip to content

Commit 75a32e0

Browse files
committed
Add a workflow to help with BCD updates
This attempts to automate many of the existing manual steps: * Checks out the branch * Checks for removed BCD keys * Checks for features with an empty definition * Checks for baseline status changes Where possible it automatically updates to removed BCD keys. So far it doesn't attempt to figure out the correct replacement for removed keys. It is designed to output a GitHub comment indicating the changes, to speed up human review.
1 parent 859cef3 commit 75a32e0

4 files changed

Lines changed: 600 additions & 1 deletion

File tree

.github/workflows/bcd_upgrade.yml

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
name: BCD upgrade automation
2+
3+
on:
4+
pull_request:
5+
types: [opened]
6+
7+
jobs:
8+
check-metadata:
9+
name: Check if BCD upgrade
10+
runs-on: ubuntu-latest
11+
if: github.event.pull_request.user.login == 'dependabot[bot]'
12+
outputs:
13+
is-bcd-upgrade: ${{ steps.metadata.outputs.is-bcd-upgrade }}
14+
steps:
15+
- name: Fetch Dependabot metadata
16+
id: fetch-metadata
17+
continue-on-error: true
18+
uses: dependabot/fetch-metadata@08eff52bf64351f401fb50d4972fa95b9f2c2d1b #v2.4.0
19+
20+
- id: metadata
21+
run: echo "is-bcd-upgrade=${{ contains(steps.fetch-metadata.outputs.dependency-names, '@mdn/browser-compat-data') }}" >> "$GITHUB_OUTPUT"
22+
23+
automate:
24+
name: Automate BCD upgrade
25+
needs: check-metadata
26+
if: needs.check-metadata.outputs.is-bcd-upgrade == 'true'
27+
runs-on: ubuntu-latest
28+
permissions:
29+
contents: write
30+
pull-requests: write
31+
steps:
32+
- uses: actions/checkout@v4
33+
with:
34+
ref: ${{ github.head_ref }}
35+
token: ${{ secrets.GITHUB_TOKEN }}
36+
37+
- uses: actions/setup-node@v4
38+
with:
39+
node-version-file: .nvmrc
40+
cache: npm
41+
42+
- run: |
43+
git config user.name "github-actions[bot]"
44+
git config user.email "github-actions[bot]@users.noreply.github.com"
45+
npm install
46+
47+
- name: Remove deleted BCD keys and snapshot baseline
48+
id: pre-dist
49+
run: |
50+
npx tsx scripts/bcd-upgrade.ts pre-dist --state-path bcd-update-state.json
51+
52+
- name: Commit key removals
53+
run: |
54+
if ! git diff --quiet features/; then
55+
git add features/
56+
git commit -m "Remove deleted BCD keys from web-features definitions"
57+
fi
58+
59+
- name: Rebuild dist files
60+
if: steps.pre-dist.outcome == 'success'
61+
run: npm run dist
62+
63+
- name: Commit dist changes
64+
if: steps.pre-dist.outcome == 'success'
65+
run: |
66+
if ! git diff --quiet features/; then
67+
git add features/
68+
git commit -m "Refresh dist"
69+
fi
70+
71+
- name: Push changes
72+
run: git push origin ${{ github.head_ref }}
73+
74+
- name: Format PR comment
75+
id: comment
76+
run: |
77+
BODY=$(npx tsx scripts/bcd-upgrade.ts post-dist \
78+
--state-path bcd-update-state.json)
79+
{
80+
echo 'body<<EOF'
81+
echo "$BODY"
82+
echo 'EOF'
83+
} >> "$GITHUB_OUTPUT"
84+
85+
- name: Post PR comment
86+
if: steps.comment.outputs.body != ''
87+
uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 #v4.0.0
88+
with:
89+
issue-number: ${{ github.event.number }}
90+
body: ${{ steps.comment.outputs.body }}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
},
1818
"scripts": {
1919
"audit-consumers": "tsx scripts/audit-consumers.ts",
20+
"bcd-upgrade": "tsx scripts/bcd-upgrade.ts",
2021
"build": "tsx scripts/build.ts package",
2122
"dist": "tsx scripts/dist.ts",
2223
"undist": "tsx scripts/undist.ts",

0 commit comments

Comments
 (0)