Skip to content

Commit 38cf4aa

Browse files
CopilotBoshen
andauthored
chore(tasks): Add GitHub Action workflow to automatically update compat-table dependency (#13213)
Co-authored-by: Boshen <boshenc@gmail.com>
1 parent 06ec43c commit 38cf4aa

File tree

1 file changed

+112
-0
lines changed

1 file changed

+112
-0
lines changed
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
name: Update Compat Table
2+
3+
permissions: {}
4+
5+
on:
6+
schedule:
7+
# Run weekly on Monday at 00:00 UTC
8+
- cron: "0 0 * * 1"
9+
workflow_dispatch: # Allow manual trigger
10+
11+
concurrency:
12+
group: ${{ github.workflow }}-${{ github.ref_name }}
13+
cancel-in-progress: true
14+
15+
jobs:
16+
update:
17+
name: Update compat-table SHA
18+
runs-on: ubuntu-latest
19+
permissions:
20+
contents: write
21+
pull-requests: write
22+
steps:
23+
- uses: taiki-e/checkout-action@b13d20b7cda4e2f325ef19895128f7ff735c0b3d # v1.3.1
24+
25+
- uses: oxc-project/setup-node@f42e3bda950c7454575e78ee4eaac880a077700c # v1.0.0
26+
- uses: oxc-project/setup-rust@cd82e1efec7fef815e2c23d296756f31c7cdc03d # v1.0.0
27+
with:
28+
cache-key: warm
29+
components: rustfmt
30+
31+
- name: Get latest compat-table SHA
32+
id: get-sha
33+
run: |
34+
# Clone compat-table repository temporarily to get latest SHA
35+
git clone --depth=1 https://github.com/compat-table/compat-table.git temp-compat-table
36+
LATEST_SHA=$(cd temp-compat-table && git rev-parse HEAD)
37+
echo "latest_sha=$LATEST_SHA" >> $GITHUB_OUTPUT
38+
rm -rf temp-compat-table
39+
echo "Latest compat-table SHA: $LATEST_SHA"
40+
41+
- name: Get current SHA from package.json
42+
id: current-sha
43+
working-directory: tasks/compat_data
44+
run: |
45+
CURRENT_SHA=$(grep -o '#[a-f0-9]*' package.json | sed 's/#//')
46+
echo "current_sha=$CURRENT_SHA" >> $GITHUB_OUTPUT
47+
echo "Current SHA in package.json: $CURRENT_SHA"
48+
49+
- name: Check if update is needed
50+
id: check-update
51+
env:
52+
LATEST_SHA: ${{ steps.get-sha.outputs.latest_sha }}
53+
CURRENT_SHA: ${{ steps.current-sha.outputs.current_sha }}
54+
run: |
55+
if [ "$LATEST_SHA" != "$CURRENT_SHA" ]; then
56+
echo "update_needed=true" >> $GITHUB_OUTPUT
57+
echo "Update needed: $CURRENT_SHA -> $LATEST_SHA"
58+
else
59+
echo "update_needed=false" >> $GITHUB_OUTPUT
60+
echo "No update needed, SHAs are the same"
61+
fi
62+
63+
- name: Update package.json with new SHA
64+
if: steps.check-update.outputs.update_needed == 'true'
65+
working-directory: tasks/compat_data
66+
env:
67+
LATEST_SHA: ${{ steps.get-sha.outputs.latest_sha }}
68+
CURRENT_SHA: ${{ steps.current-sha.outputs.current_sha }}
69+
run: |
70+
# Update the SHA in package.json
71+
sed -i "s/#$CURRENT_SHA/#$LATEST_SHA/g" package.json
72+
echo "Updated package.json with new SHA"
73+
74+
- name: Install dependencies and run build
75+
if: steps.check-update.outputs.update_needed == 'true'
76+
working-directory: tasks/compat_data
77+
run: |
78+
rm -rf compat-table
79+
pnpm run init
80+
pnpm run build
81+
cargo run -p oxc_compat_data
82+
cargo fmt
83+
84+
- name: Check for changes
85+
if: steps.check-update.outputs.update_needed == 'true'
86+
id: changes
87+
run: |
88+
if git diff --quiet; then
89+
echo "has_changes=false" >> $GITHUB_OUTPUT
90+
echo "No files were changed after build"
91+
else
92+
echo "has_changes=true" >> $GITHUB_OUTPUT
93+
echo "Files changed:"
94+
git diff --name-only
95+
fi
96+
97+
- name: Create Pull Request
98+
if: steps.check-update.outputs.update_needed == 'true' && steps.changes.outputs.has_changes == 'true'
99+
uses: peter-evans/create-pull-request@271a8d0340265f705b14b6d32b9829c1cb33d45e # v7.0.8
100+
with:
101+
token: ${{ secrets.OXC_BOT_PAT }}
102+
commit-message: "chore(compat_data): update compat-table to ${{ steps.get-sha.outputs.latest_sha }}"
103+
branch: update-compat-table
104+
branch-suffix: timestamp
105+
base: main
106+
title: "chore(compat_data): update compat-table to latest commit"
107+
assignees: Boshen
108+
body: |
109+
Updates compat-table dependency to the latest commit.
110+
111+
- Previous SHA: `${{ steps.current-sha.outputs.current_sha }}`
112+
- New SHA: `${{ steps.get-sha.outputs.latest_sha }}`

0 commit comments

Comments
 (0)