-
Notifications
You must be signed in to change notification settings - Fork 0
80 lines (66 loc) · 2.61 KB
/
publish.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
name: Publish VS Code Extension
on:
release:
types: [published]
jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
# Setup Node.js and install dependencies
- uses: actions/setup-node@v4
with:
node-version: '20'
registry-url: 'https://registry.npmjs.org'
# Install dependencies
- run: npm run install:all
# Get the release version from the GitHub tag and remove the 'v' prefix
- name: Get release version
run: |
VERSION="${GITHUB_REF##*/}"
CLEAN_VERSION="${VERSION#v}" # Remove 'v' from tag name
echo "RELEASE_VERSION=$CLEAN_VERSION" >> $GITHUB_ENV
# Compare the release version with the current package.json version
- name: Compare versions
id: compare_versions
run: |
CURRENT_VERSION=$(node -p "require('./package.json').version")
RELEASE_VERSION=${{ env.RELEASE_VERSION }}
compare_versions() {
if [ "$(printf '%s\n' "$1" "$2" | sort -V | head -n1)" = "$1" ] && [ "$1" != "$2" ]; then
return 0
else
return 1
fi
}
if compare_versions "$CURRENT_VERSION" "$RELEASE_VERSION"; then
echo "The release version ($RELEASE_VERSION) is greater than the current version ($CURRENT_VERSION)."
echo "SHOULD_UPDATE=true" >> $GITHUB_ENV
else
echo "The release version ($RELEASE_VERSION) is not greater than the current version ($CURRENT_VERSION)."
echo "SHOULD_UPDATE=false" >> $GITHUB_ENV
fi
# Update package.json and package-lock.json with the next version
- name: Update Version in package.json
if: env.SHOULD_UPDATE == 'true'
run: |
npm version ${{ env.RELEASE_VERSION }} --no-git-tag-version
npm install # Ensure package-lock.json is updated
# Commit the updated package.json if the version was updated
- name: Commit version update
if: env.SHOULD_UPDATE == 'true'
run: |
git config --local user.name "GitHub Actions"
git config --local user.email "[email protected]"
git add package.json package-lock.json
git commit -m "Bump version to ${{ env.RELEASE_VERSION }}"
git push origin HEAD:main
# Install vsce globally
- run: npm i -g vsce
# Build the extension
- run: npm run build:webview
# Publish the extension
- name: Publish
run: vsce publish -p ${{ secrets.VSCE_PAT }} --allow-missing-repository