Skip to content

Commit 959ee8b

Browse files
Add vsce pre-release step to CI
1 parent 35ac5f2 commit 959ee8b

File tree

4 files changed

+145
-7
lines changed

4 files changed

+145
-7
lines changed

.github/workflows/bump-version.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
const fs = require("fs");
2+
const path = require("path");
3+
const semver = require("semver");
4+
5+
const latestPublish = process.argv[2];
6+
7+
const packageJson = fs.readFileSync(path.join("./", "package.json"), {
8+
encoding: "utf-8",
9+
});
10+
11+
let release = JSON.parse(packageJson).version;
12+
13+
let newVersion = latestPublish;
14+
15+
// A prepublished version must be one minor higher than a regular published version.
16+
// E.g. if package.json has version 1.3.0 and there is no prepublished version yet,
17+
// increment minor by one -> 1.4.0.
18+
if (semver.minor(latestPublish) === semver.minor(release)) {
19+
newVersion = semver.inc(newVersion, "minor", semver.rel);
20+
}
21+
// Increment the version patch. E.g. if we fetch version 1.4.0 as the latest pre-release,
22+
// increment patch by one -> 1.4.1.
23+
else if (semver.minor(latestPublish) > semver.minor(release)) {
24+
newVersion = semver.inc(newVersion, "patch", semver.rel);
25+
}
26+
// Otherwise throw an error, because the pre-release version should always be just one
27+
// minor higher than the release version.
28+
else {
29+
throw new Error(
30+
"Version number minors are more than off by one, check package.json and (pre-)published versions manually."
31+
);
32+
}
33+
34+
if (!semver.valid(newVersion)) {
35+
throw new Error("Invalid version string: ", newVersion);
36+
}
37+
38+
console.log(`::set-output name=new_version::${newVersion}`);

.github/workflows/ci.yml

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,18 +81,18 @@ jobs:
8181
package:
8282
needs: test
8383
runs-on: ubuntu-18.04
84-
84+
8585
steps:
8686
- uses: actions/checkout@v2.3.4
87-
87+
8888
- name: Use Node.js
8989
uses: actions/setup-node@v2.1.5
9090
with:
9191
node-version: 14.4.0
9292

9393
- run: npm ci
9494
- run: npm run compile
95-
95+
9696
- name: Download MacOS binary
9797
uses: actions/download-artifact@v3.0.0
9898
with:
@@ -126,11 +126,52 @@ jobs:
126126
env:
127127
COMMIT_SHA: ${{ github.event.pull_request.head.sha || github.sha }}
128128
run: echo "::set-output name=sha_short::${COMMIT_SHA:0:7}"
129-
129+
130+
- name: Get current pre-release version
131+
if: github.ref == 'refs/heads/master'
132+
id: get_pre_release
133+
run: |
134+
JSON=$(npx vsce show chenglou92.rescript-vscode --json)
135+
VERSION=$(echo $JSON | jq '.versions | .[0] | .["version"]')
136+
echo "::set-output name=current_version::${VERSION}"
137+
138+
- name: Increment pre-release version
139+
if: github.ref == 'refs/heads/master'
140+
id: increment_pre_release
141+
run: |
142+
NEW_VERSION=$(echo ${{ steps.get_pre_release.outputs.current_version }})
143+
node .github/workflows/bump-version.js ${NEW_VERSION}
144+
130145
- name: Package Extension
131-
run: npx vsce package -o rescript-vscode-${{ steps.vars.outputs.sha_short }}.vsix
132-
146+
if: github.ref != 'refs/heads/master'
147+
run: npx vsce package -o rescript-vscode-${{ steps.vars.outputs.sha_short }}.vsix
148+
149+
- name: Package Extension
150+
if: github.ref == 'refs/heads/master'
151+
run: npx vsce package -o rescript-vscode-${{ steps.increment_pre_release.outputs.new_version }}.vsix ${{ steps.increment_pre_release.outputs.new_version }} --no-git-tag-version
152+
133153
- uses: actions/upload-artifact@v2
154+
if: github.ref != 'refs/heads/master'
134155
with:
135156
name: rescript-vscode-${{ steps.vars.outputs.sha_short }}.vsix
136157
path: rescript-vscode-${{ steps.vars.outputs.sha_short }}.vsix
158+
159+
- uses: actions/upload-artifact@v2
160+
if: github.ref == 'refs/heads/master'
161+
with:
162+
name: rescript-vscode-${{ steps.increment_pre_release.outputs.new_version }}.vsix
163+
path: rescript-vscode-${{ steps.increment_pre_release.outputs.new_version }}.vsix
164+
165+
- name: Publish latest master to GitHub
166+
if: github.ref == 'refs/heads/master'
167+
uses: marvinpinto/action-automatic-releases@latest
168+
with:
169+
repo_token: "${{ secrets.GITHUB_TOKEN }}"
170+
automatic_release_tag: "latest-master"
171+
prerelease: true
172+
title: "Latest master"
173+
files: rescript-vscode-${{ steps.increment_pre_release.outputs.new_version }}.vsix
174+
175+
- name: Publish extension as pre-release
176+
if: github.ref == 'refs/heads/master'
177+
run: npx vsce publish --pat ${{ secrets.MARKETPLACE_TOKEN }} --pre-release ${{ steps.increment_pre_release.outputs.new_version }} --no-git-tag-version

package-lock.json

Lines changed: 58 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@
184184
"devDependencies": {
185185
"@types/node": "^14.14.41",
186186
"@types/vscode": "1.68.0",
187-
"typescript": "^4.7.3"
187+
"typescript": "^4.7.3",
188+
"semver": "^7.3.7"
188189
}
189190
}

0 commit comments

Comments
 (0)