Skip to content

Commit 4e81d6d

Browse files
Test vsce pre-release
1 parent ff757df commit 4e81d6d

File tree

4 files changed

+191
-53
lines changed

4 files changed

+191
-53
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: 91 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -81,54 +81,95 @@ jobs:
8181
package:
8282
needs: test
8383
runs-on: ubuntu-18.04
84-
85-
steps:
86-
- uses: actions/checkout@v2.3.4
87-
88-
- name: Use Node.js
89-
uses: actions/setup-node@v2.1.5
90-
with:
91-
node-version: 14.4.0
92-
93-
- run: npm ci
94-
- run: npm run compile
95-
96-
- name: Download MacOS binary
97-
uses: actions/download-artifact@v3.0.0
98-
with:
99-
name: macos-latest
100-
path: ./server/analysis_binaries
101-
- run: tar -xvf binary.tar
102-
working-directory: ./server/analysis_binaries
103-
104-
- name: Download Linux binary
105-
uses: actions/download-artifact@v3.0.0
106-
with:
107-
name: ubuntu-18.04
108-
path: ./server/analysis_binaries
109-
- run: tar -xvf binary.tar
110-
working-directory: ./server/analysis_binaries
11184

112-
- name: Download Windows binary
113-
uses: actions/download-artifact@v3.0.0
114-
with:
115-
name: windows-latest
116-
path: ./server/analysis_binaries
117-
- run: tar -xvf binary.tar
118-
working-directory: ./server/analysis_binaries
119-
120-
- name: Cleanup tar file
121-
run: rm binary.tar
122-
working-directory: ./server/analysis_binaries
123-
124-
- name: Store short commit SHA for filename
125-
id: vars
126-
run: echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"
127-
128-
- name: Package Extension
129-
run: npx vsce package -o rescript-vscode-${{ steps.vars.outputs.sha_short }}.vsix
130-
131-
- uses: actions/upload-artifact@v2
132-
with:
133-
name: rescript-vscode-${{ steps.vars.outputs.sha_short }}.vsix
134-
path: rescript-vscode-${{ steps.vars.outputs.sha_short }}.vsix
85+
steps:
86+
- uses: actions/checkout@v2.3.4
87+
88+
- name: Use Node.js
89+
uses: actions/setup-node@v2.1.5
90+
with:
91+
node-version: 14.4.0
92+
93+
- run: npm ci
94+
- run: npm run compile
95+
96+
- name: Download MacOS binary
97+
uses: actions/download-artifact@v3.0.0
98+
with:
99+
name: macos-latest
100+
path: ./server/analysis_binaries
101+
- run: tar -xvf binary.tar
102+
working-directory: ./server/analysis_binaries
103+
104+
- name: Download Linux binary
105+
uses: actions/download-artifact@v3.0.0
106+
with:
107+
name: ubuntu-18.04
108+
path: ./server/analysis_binaries
109+
- run: tar -xvf binary.tar
110+
working-directory: ./server/analysis_binaries
111+
112+
- name: Download Windows binary
113+
uses: actions/download-artifact@v3.0.0
114+
with:
115+
name: windows-latest
116+
path: ./server/analysis_binaries
117+
- run: tar -xvf binary.tar
118+
working-directory: ./server/analysis_binaries
119+
120+
- name: Cleanup tar file
121+
run: rm binary.tar
122+
working-directory: ./server/analysis_binaries
123+
124+
- name: Store short commit SHA for filename
125+
id: vars
126+
run: echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"
127+
128+
- name: Get current pre-release version
129+
id: get_pre_release
130+
run: |
131+
JSON=$(npx vsce show chenglou92.rescript-vscode --json)
132+
VERSION=$(echo $JSON | jq '.versions | .[0] | .["version"]')
133+
echo "${VERSION}"
134+
echo "::set-output name=current_version::${VERSION}"
135+
136+
- name: Increment pre-release version
137+
id: increment_pre_release
138+
run: |
139+
NEW_VERSION=$(echo ${{ steps.get_pre_release.outputs.current_version }})
140+
node .github/workflows/bump-version.js ${NEW_VERSION}
141+
echo "${VERSION}"
142+
143+
- name: Package Extension
144+
if: github.ref != 'refs/heads/master'
145+
run: npx vsce package -o rescript-vscode-${{ steps.vars.outputs.sha_short }}.vsix
146+
147+
- name: Package Extension
148+
if: github.ref == 'refs/heads/master'
149+
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
150+
151+
- uses: actions/upload-artifact@v2
152+
if: github.ref != 'refs/heads/master'
153+
with:
154+
name: rescript-vscode-${{ steps.vars.outputs.sha_short }}.vsix
155+
path: rescript-vscode-${{ steps.vars.outputs.sha_short }}.vsix
156+
157+
- uses: actions/upload-artifact@v2
158+
if: github.ref == 'refs/heads/master'
159+
with:
160+
name: rescript-vscode-${{ steps.increment_pre_release.outputs.new_version }}.vsix
161+
path: rescript-vscode-${{ steps.increment_pre_release.outputs.new_version }}.vsix
162+
163+
- name: Publish latest master to GitHub
164+
if: github.ref == 'refs/heads/master'
165+
uses: marvinpinto/action-automatic-releases@latest
166+
with:
167+
repo_token: "${{ secrets.GITHUB_TOKEN }}"
168+
automatic_release_tag: "latest-master"
169+
prerelease: true
170+
title: "latest-master"
171+
files: rescript-vscode-${{ steps.increment_pre_release.outputs.new_version }}.vsix
172+
173+
- name: Publish extension as pre-release
174+
if: github.ref == 'refs/heads/master'
175+
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: 59 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"language-server"
2222
],
2323
"engines": {
24-
"vscode": "^1.55.0"
24+
"vscode": "^1.63.0"
2525
},
2626
"activationEvents": [
2727
"onLanguage:rescript"
@@ -165,6 +165,7 @@
165165
"devDependencies": {
166166
"@types/node": "^14.14.41",
167167
"@types/vscode": "1.55.0",
168-
"typescript": "^4.2.4"
168+
"typescript": "^4.2.4",
169+
"semver": "^7.3.7"
169170
}
170171
}

0 commit comments

Comments
 (0)