Skip to content

Commit 16b9400

Browse files
chore: update engines.vscode to ^1.109.0 and add auto-sync workflow
Co-authored-by: unknowIfGuestInDream <57802425+unknowIfGuestInDream@users.noreply.github.com>
1 parent 33761b7 commit 16b9400

2 files changed

Lines changed: 95 additions & 1 deletion

File tree

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
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+
run: |
55+
TYPES_VERSION="${{ steps.check_update.outputs.types_version }}"
56+
57+
# Extract major.minor from the version (e.g., 1.109.0 -> 1.109)
58+
MAJOR_MINOR=$(echo "$TYPES_VERSION" | cut -d. -f1,2)
59+
ENGINE_VERSION="^${MAJOR_MINOR}.0"
60+
61+
echo "Setting engines.vscode to: $ENGINE_VERSION"
62+
63+
# Update package.json using node
64+
node -e "
65+
const fs = require('fs');
66+
const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8'));
67+
const currentEngine = pkg.engines.vscode;
68+
const newEngine = '$ENGINE_VERSION';
69+
70+
console.log('Current engines.vscode:', currentEngine);
71+
console.log('New engines.vscode:', newEngine);
72+
73+
if (currentEngine !== newEngine) {
74+
pkg.engines.vscode = newEngine;
75+
fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\n');
76+
console.log('Updated engines.vscode');
77+
process.exit(0);
78+
} else {
79+
console.log('No update needed');
80+
process.exit(1);
81+
}
82+
"
83+
84+
# Store the exit code
85+
echo "update_needed=$?" >> $GITHUB_ENV
86+
87+
- name: Commit changes
88+
if: steps.check_update.outputs.types_vscode_updated == 'true' && env.update_needed == '0'
89+
run: |
90+
git config --local user.email "github-actions[bot]@users.noreply.github.com"
91+
git config --local user.name "github-actions[bot]"
92+
git add package.json
93+
git commit -m "chore: update engines.vscode to match @types/vscode version"
94+
git push

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
},
1515
"homepage": "https://github.com/tlcsdm/vscode-java-method-sorter#readme",
1616
"engines": {
17-
"vscode": "^1.108.0"
17+
"vscode": "^1.109.0"
1818
},
1919
"categories": [
2020
"Formatters",

0 commit comments

Comments
 (0)