Skip to content

Commit 838debd

Browse files
committed
Automatically publish extension to marketplaces
* Publish pre-release extension on every push to main * Upload VSIX to the VS Code Marketplace and Open VSX on tag push
1 parent 5165ade commit 838debd

File tree

2 files changed

+246
-8
lines changed

2 files changed

+246
-8
lines changed

.github/workflows/pre-release.yaml

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
name: Pre-Release
2+
on:
3+
push:
4+
branches:
5+
- main
6+
7+
jobs:
8+
package:
9+
name: Package
10+
runs-on: ubuntu-22.04
11+
outputs:
12+
packageName: ${{ steps.setup.outputs.packageName }}
13+
version: ${{ steps.version.outputs.version }}
14+
steps:
15+
- uses: actions/checkout@v5
16+
17+
- uses: actions/setup-node@v5
18+
with:
19+
node-version: "22"
20+
21+
- name: Install dependencies
22+
run: |
23+
yarn
24+
npm install -g @vscode/vsce ovsx
25+
26+
- name: Generate pre-release version
27+
id: version
28+
run: |
29+
BASE_VERSION=$(node -e "console.log(require('./package.json').version)")
30+
IFS='.' read -r MAJOR MINOR PATCH <<< "$BASE_VERSION"
31+
32+
PRE_MINOR=$((MINOR + 1))
33+
34+
DATE_PREFIX=$(date +%Y%m%d)
35+
BUILD_SUFFIX=$(printf "%02d" $((GITHUB_RUN_NUMBER % 100)))
36+
DATE_PATCH="${DATE_PREFIX}${BUILD_SUFFIX}"
37+
38+
# Final version: MAJOR.(MINOR+1).YYYYMMDDNN
39+
NUMERIC_VERSION="${MAJOR}.${PRE_MINOR}.${DATE_PATCH}${{ github.run_number }}"
40+
41+
echo "version=$NUMERIC_VERSION" >> $GITHUB_OUTPUT
42+
43+
echo "Pre-release version: $NUMERIC_VERSION"
44+
45+
# Update package.json with the numeric version
46+
npm version $NUMERIC_VERSION --no-git-tag-version
47+
48+
- name: Setup package path
49+
id: setup
50+
run: |
51+
PACKAGE_NAME="${{ github.event.repository.name }}-pre-${{ steps.version.outputs.version }}.vsix"
52+
echo "packageName=$PACKAGE_NAME" >> $GITHUB_OUTPUT
53+
54+
- name: Package extension
55+
run: vsce package --pre-release --out "${{ steps.setup.outputs.packageName }}"
56+
57+
- name: Upload artifact
58+
uses: actions/upload-artifact@v4
59+
with:
60+
name: extension-build-${{ github.run_number }}
61+
path: ${{ steps.setup.outputs.packageName }}
62+
if-no-files-found: error
63+
retention-days: 7
64+
65+
publishMS:
66+
name: Publish to VS Marketplace
67+
runs-on: ubuntu-22.04
68+
needs: package
69+
steps:
70+
- uses: actions/checkout@v5
71+
72+
- uses: actions/setup-node@v5
73+
with:
74+
node-version: "22"
75+
76+
- name: Install vsce
77+
run: npm install -g @vscode/vsce
78+
79+
- uses: actions/download-artifact@v5
80+
with:
81+
name: extension-build-${{ github.run_number }}
82+
83+
- name: Publish to VS Marketplace
84+
run: |
85+
echo "Publishing version ${{ needs.package.outputs.version }} to VS Marketplace"
86+
vsce publish --pre-release --packagePath "./${{ needs.package.outputs.packageName }}" -p ${{ secrets.VSCE_PAT }}
87+
88+
publishOVSX:
89+
name: Publish to Open VSX
90+
runs-on: ubuntu-22.04
91+
needs: package
92+
steps:
93+
- uses: actions/checkout@v5
94+
95+
- uses: actions/setup-node@v5
96+
with:
97+
node-version: "22"
98+
99+
- name: Install ovsx
100+
run: npm install -g ovsx
101+
102+
- uses: actions/download-artifact@v5
103+
with:
104+
name: extension-build-${{ github.run_number }}
105+
106+
- name: Publish to Open VSX
107+
run: |
108+
echo "Publishing version ${{ needs.package.outputs.version }} to Open VSX"
109+
ovsx publish "./${{ needs.package.outputs.packageName }}" --pre-release -p ${{ secrets.OVSX_PAT }}
110+
111+
publishGH:
112+
name: Update Latest Pre-Release
113+
runs-on: ubuntu-22.04
114+
needs: package
115+
permissions:
116+
contents: write
117+
steps:
118+
- uses: actions/checkout@v5
119+
120+
- uses: actions/download-artifact@v5
121+
with:
122+
name: extension-build-${{ github.run_number }}
123+
124+
- name: Update Rolling Release
125+
env:
126+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
127+
run: |
128+
# Delete old release and tag
129+
gh release delete latest-pre-release --cleanup-tag -y || true
130+
131+
# Create new release with heredoc for formatting
132+
cat << EOF | gh release create latest-pre-release \
133+
--target ${{ github.sha }} \
134+
--title "Latest Pre-Release Build" \
135+
--notes-file - \
136+
--prerelease \
137+
--latest=false \
138+
${{ needs.package.outputs.packageName }}
139+
## Latest Pre-Release: v${{ needs.package.outputs.version }}
140+
141+
**Build:** #${{ github.run_number }} | **Commit:** ${{ github.sha }}
142+
143+
## Changes
144+
${{ github.event.head_commit.message }}
145+
146+
---
147+
*This release is automatically updated with each push to main. The tag `latest-pre-release` always points to the most recent build.*
148+
EOF

.github/workflows/release.yaml

Lines changed: 98 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,123 @@
1+
name: Release
12
on:
23
push:
34
tags:
45
- "v*"
56

6-
name: release
7-
87
permissions:
98
# Required to publish a release
109
contents: write
11-
pull-requests: "read"
10+
pull-requests: read
1211

1312
jobs:
1413
package:
14+
name: Package
15+
runs-on: ubuntu-22.04
16+
outputs:
17+
packageName: ${{ steps.setup.outputs.packageName }}
18+
version: ${{ steps.version.outputs.version }}
19+
steps:
20+
- uses: actions/checkout@v5
21+
22+
- uses: actions/setup-node@v5
23+
with:
24+
node-version: "22"
25+
26+
- name: Install dependencies
27+
run: |
28+
yarn
29+
npm install -g @vscode/vsce ovsx
30+
31+
- name: Extract version from tag
32+
id: version
33+
run: |
34+
# Extract version from tag (remove 'v' prefix)
35+
VERSION=${GITHUB_REF#refs/tags/v}
36+
echo "version=$VERSION" >> $GITHUB_OUTPUT
37+
echo "Release version: $VERSION"
38+
39+
- name: Setup package path
40+
id: setup
41+
run: |
42+
PACKAGE_NAME="${{ github.event.repository.name }}-${{ steps.version.outputs.version }}.vsix"
43+
echo "packageName=$PACKAGE_NAME" >> $GITHUB_OUTPUT
44+
45+
- name: Package extension
46+
run: vsce package --out "${{ steps.setup.outputs.packageName }}"
47+
48+
- name: Upload artifact
49+
uses: actions/upload-artifact@v4
50+
with:
51+
name: extension-release-${{ steps.version.outputs.version }}
52+
path: ${{ steps.setup.outputs.packageName }}
53+
if-no-files-found: error
54+
retention-days: 30
55+
56+
publishMS:
57+
name: Publish to VS Marketplace
1558
runs-on: ubuntu-22.04
59+
needs: package
1660
steps:
1761
- uses: actions/checkout@v5
1862

1963
- uses: actions/setup-node@v5
2064
with:
2165
node-version: "22"
2266

23-
- run: yarn
67+
- name: Install vsce
68+
run: npm install -g @vscode/vsce
69+
70+
- uses: actions/download-artifact@v5
71+
with:
72+
name: extension-release-${{ needs.package.outputs.version }}
73+
74+
- name: Publish to VS Marketplace
75+
run: |
76+
echo "Publishing version ${{ needs.package.outputs.version }} to VS Marketplace"
77+
vsce publish --packagePath "./${{ needs.package.outputs.packageName }}" -p ${{ secrets.VSCE_PAT }}
2478
25-
- run: npx @vscode/vsce package
79+
publishOVSX:
80+
name: Publish to Open VSX
81+
runs-on: ubuntu-22.04
82+
needs: package
83+
steps:
84+
- uses: actions/checkout@v5
85+
86+
- uses: actions/setup-node@v5
87+
with:
88+
node-version: "22"
89+
90+
- name: Install ovsx
91+
run: npm install -g ovsx
92+
93+
- uses: actions/download-artifact@v5
94+
with:
95+
name: extension-release-${{ needs.package.outputs.version }}
96+
97+
- name: Publish to Open VSX
98+
run: |
99+
echo "Publishing version ${{ needs.package.outputs.version }} to Open VSX"
100+
ovsx publish "./${{ needs.package.outputs.packageName }}" -p ${{ secrets.OVSX_PAT }}
101+
102+
publishGH:
103+
name: Create GitHub Release
104+
runs-on: ubuntu-22.04
105+
needs: package
106+
permissions:
107+
contents: write
108+
steps:
109+
- uses: actions/checkout@v5
110+
111+
- uses: actions/download-artifact@v5
112+
with:
113+
name: extension-release-${{ needs.package.outputs.version }}
26114

27-
- uses: "marvinpinto/action-automatic-releases@latest"
115+
- name: Create Release
116+
uses: marvinpinto/action-automatic-releases@latest
28117
with:
29-
repo_token: "${{ secrets.GITHUB_TOKEN }}"
118+
repo_token: ${{ secrets.GITHUB_TOKEN }}
30119
prerelease: false
31120
draft: true
121+
title: "Release v${{ needs.package.outputs.version }}"
32122
files: |
33-
*.vsix
123+
${{ needs.package.outputs.packageName }}

0 commit comments

Comments
 (0)