Skip to content

Commit d1c0d70

Browse files
ci: Add sync-vscode-engine action
1 parent b202f6d commit d1c0d70

1 file changed

Lines changed: 99 additions & 0 deletions

File tree

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# This workflow automatically updates engines.vscode when @types/vscode has a major or minor version change
2+
name: Sync VSCode Engine Version
3+
4+
on:
5+
pull_request:
6+
types: [opened, synchronize, reopened]
7+
paths:
8+
- 'package.json'
9+
- 'package-lock.json'
10+
11+
permissions:
12+
contents: write
13+
pull-requests: write
14+
15+
jobs:
16+
sync-vscode-engine:
17+
# Only run for dependabot PRs
18+
if: github.actor == 'dependabot[bot]'
19+
runs-on: ubuntu-latest
20+
21+
steps:
22+
- name: Checkout PR branch
23+
uses: actions/checkout@v6
24+
with:
25+
ref: ${{ github.head_ref }}
26+
token: ${{ secrets.GITHUB_TOKEN }}
27+
28+
- name: Setup Node.js
29+
uses: actions/setup-node@v6
30+
with:
31+
node-version: '22'
32+
33+
- name: Check if @types/vscode was updated
34+
id: check_update
35+
run: |
36+
# Get the PR title
37+
PR_TITLE="${{ github.event.pull_request.title }}"
38+
echo "PR Title: $PR_TITLE"
39+
40+
# Check if this PR is about @types/vscode
41+
if [[ "$PR_TITLE" == *"@types/vscode"* ]]; then
42+
echo "types_vscode_updated=true" >> $GITHUB_OUTPUT
43+
44+
# Extract version from package.json
45+
TYPES_VERSION=$(node -p "require('./package.json').devDependencies['@types/vscode']" | sed 's/[\^~]//g')
46+
echo "types_version=$TYPES_VERSION" >> $GITHUB_OUTPUT
47+
echo "Found @types/vscode version: $TYPES_VERSION"
48+
else
49+
echo "types_vscode_updated=false" >> $GITHUB_OUTPUT
50+
fi
51+
52+
- name: Update engines.vscode
53+
if: steps.check_update.outputs.types_vscode_updated == 'true'
54+
id: update_engine
55+
run: |
56+
TYPES_VERSION="${{ steps.check_update.outputs.types_version }}"
57+
58+
# Extract major.minor from the version (e.g., 1.109.0 -> 1.109)
59+
MAJOR_MINOR=$(echo "$TYPES_VERSION" | cut -d. -f1,2)
60+
ENGINE_VERSION="^${MAJOR_MINOR}.0"
61+
62+
echo "Setting engines.vscode to: $ENGINE_VERSION"
63+
64+
# Update package.json using node
65+
node -e "
66+
const fs = require('fs');
67+
const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8'));
68+
const currentEngine = pkg.engines.vscode;
69+
const newEngine = '$ENGINE_VERSION';
70+
71+
console.log('Current engines.vscode:', currentEngine);
72+
console.log('New engines.vscode:', newEngine);
73+
74+
if (currentEngine !== newEngine) {
75+
pkg.engines.vscode = newEngine;
76+
fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\n');
77+
console.log('Updated engines.vscode');
78+
console.log('changes_made=true');
79+
} else {
80+
console.log('No update needed');
81+
console.log('changes_made=false');
82+
}
83+
" | tee /tmp/update-output.txt
84+
85+
# Extract the changes_made value from output
86+
if grep -q "changes_made=true" /tmp/update-output.txt; then
87+
echo "changes_made=true" >> $GITHUB_OUTPUT
88+
else
89+
echo "changes_made=false" >> $GITHUB_OUTPUT
90+
fi
91+
92+
- name: Commit changes
93+
if: steps.check_update.outputs.types_vscode_updated == 'true' && steps.update_engine.outputs.changes_made == 'true'
94+
run: |
95+
git config --local user.email "github-actions[bot]@users.noreply.github.com"
96+
git config --local user.name "github-actions[bot]"
97+
git add package.json
98+
git commit -m "chore: update engines.vscode to match @types/vscode version"
99+
git push

0 commit comments

Comments
 (0)