Skip to content

Commit 94e1bdb

Browse files
authored
Add workflow to sync rush.json version on changes (#241)
This workflow automates the synchronization of rush.json version when changes are detected in package.json or rush.json. It includes steps for detecting changes, updating rush.json, running rush update, and committing the changes.
1 parent ae70e0d commit 94e1bdb

1 file changed

Lines changed: 84 additions & 0 deletions

File tree

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
name: Sync Rush.json Version
2+
on:
3+
pull_request:
4+
types: [opened, synchronize]
5+
paths:
6+
- "**/package.json"
7+
- "rush.json"
8+
- "common-versions.json"
9+
10+
permissions:
11+
contents: write
12+
pull-requests: write
13+
14+
jobs:
15+
detect:
16+
runs-on: ubuntu-latest
17+
if: github.actor == 'dependabot[bot]'
18+
outputs:
19+
rush_changed: ${{ steps.detect.outputs.rush_changed }}
20+
steps:
21+
- uses: actions/checkout@v6
22+
with:
23+
fetch-depth: 2 # Fetch current commit + previous commit
24+
- name: Detect Rush bump
25+
id: detect
26+
run: |
27+
# Look for @microsoft/rush in the diff
28+
if git diff -U0 HEAD~1 -- package.json | grep '"@microsoft/rush"'; then
29+
echo "rush_changed=true" >> $GITHUB_OUTPUT
30+
echo "Rush change detected"
31+
else
32+
echo "rush_changed=false" >> $GITHUB_OUTPUT
33+
echo "No Rush change detected"
34+
fi
35+
36+
update:
37+
runs-on: ubuntu-latest
38+
needs: detect
39+
if: needs.detect.outputs.rush_changed == 'true'
40+
steps:
41+
- uses: actions/checkout@v6
42+
with:
43+
token: ${{ secrets.GITHUB_TOKEN }}
44+
fetch-depth: 0
45+
ref: ${{ github.head_ref }}
46+
47+
- name: Setup Node
48+
uses: actions/setup-node@v6
49+
with:
50+
node-version: 20
51+
52+
- name: Install Rush
53+
run: npm install -g @microsoft/rush
54+
55+
- name: Sync rush.json
56+
run: |
57+
echo "Syncing rush.json with Dependabot bump..."
58+
# Extract new Rush version from package.json
59+
NEW_VERSION=$(jq -r '.devDependencies["@microsoft/rush"] // .dependencies["@microsoft/rush"]' package.json)
60+
61+
# Update rush.json version field
62+
jq ".rushVersion = \"$NEW_VERSION\"" rush.json > rush.tmp.json
63+
mv rush.tmp.json rush.json
64+
65+
- name: Run rush update
66+
run: |
67+
rush update --full
68+
69+
- name: Commit changes
70+
run: |
71+
git config --global user.name "dependabot-sync[bot]"
72+
git config --global user.email "dependabot-sync[bot]@users.noreply.github.com"
73+
# Add files that exist
74+
if [ -f rush.json ]; then git add rush.json; fi
75+
if [ -f common-versions.json ]; then git add common-versions.json; fi
76+
if [ -f common/config/rush/npm-shrinkwrap.json ]; then git add common/config/rush/npm-shrinkwrap.json; fi
77+
# Add all changes in common/scripts folder if it exists
78+
if [ -d common/scripts ]; then git add common/scripts/; fi
79+
if git diff --staged --quiet; then
80+
echo "No changes to commit."
81+
else
82+
git commit -m "chore: sync rush.json and regenerate lockfiles"
83+
git push
84+
fi

0 commit comments

Comments
 (0)