Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add vsce pre-release step to CI #399

Merged
merged 4 commits into from
Jul 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions .github/workflows/bump-version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
const fs = require("fs");
const path = require("path");
const semver = require("semver");

const latestPublish = process.argv[2];

const packageJson = fs.readFileSync(path.join("./", "package.json"), {
encoding: "utf-8",
});

let release = JSON.parse(packageJson).version;

let newVersion = latestPublish;

// If the main release gets a major bump but did not get published yet, the package.json version
// will be higher than the one retrieved from the marketplace, so we need to increment from the main release
// E.g. package.json gets bumped to 1.5.0 -> 1.6.0
if (semver.major(release) - semver.major(latestPublish) === 1) {
newVersion = semver.inc(release, "minor", semver.rel);
}
// A prepublished version must be one minor higher than a regular published version.
// E.g. if package.json has version 1.3.0 and there is no prepublished version yet,
// increment minor by one -> 1.4.0.
else if (semver.minor(latestPublish) === semver.minor(release)) {
newVersion = semver.inc(newVersion, "minor", semver.rel);
}
// Increment the version patch. E.g. if we fetch version 1.4.0 as the latest pre-release,
// increment patch by one -> 1.4.1.
else if (semver.minor(latestPublish) > semver.minor(release)) {
newVersion = semver.inc(newVersion, "patch", semver.rel);
}
// If the main release gets a minor bump but did not get published yet, the package.json version
// will be higher than the one retrieved from the marketplace, so we need to increment from the main release
// E.g. package.json gets bumped to 1.5.0 -> 1.6.0
else if (semver.minor(release) - semver.minor(latestPublish) === 1) {
newVersion = semver.inc(release, "minor", semver.rel);
}
// Otherwise throw an error, because the pre-release version should always be just one
// minor higher than the release version.
else {
throw new Error(
"Version number minors are more than off by one, check package.json and (pre-)published versions manually."
);
}

if (!semver.valid(newVersion)) {
throw new Error("Invalid version string: ", newVersion);
}

console.log(`::set-output name=new_version::${newVersion}`);
53 changes: 47 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,18 @@ jobs:
package:
needs: test
runs-on: ubuntu-18.04

steps:
- uses: actions/checkout@v2.3.4

- name: Use Node.js
uses: actions/setup-node@v2.1.5
with:
node-version: 14.4.0

- run: npm ci
- run: npm run compile

- name: Download MacOS binary
uses: actions/download-artifact@v3.0.0
with:
Expand Down Expand Up @@ -126,11 +126,52 @@ jobs:
env:
COMMIT_SHA: ${{ github.event.pull_request.head.sha || github.sha }}
run: echo "::set-output name=sha_short::${COMMIT_SHA:0:7}"


- name: Get current pre-release version
if: github.ref == 'refs/heads/master'
id: get_pre_release
run: |
JSON=$(npx vsce show chenglou92.rescript-vscode --json)
VERSION=$(echo $JSON | jq '.versions | .[0] | .["version"]')
echo "::set-output name=current_version::${VERSION}"

- name: Increment pre-release version
if: github.ref == 'refs/heads/master'
id: increment_pre_release
run: |
NEW_VERSION=$(echo ${{ steps.get_pre_release.outputs.current_version }})
node .github/workflows/bump-version.js ${NEW_VERSION}

- name: Package Extension
run: npx vsce package -o rescript-vscode-${{ steps.vars.outputs.sha_short }}.vsix

if: github.ref != 'refs/heads/master'
run: npx vsce package -o rescript-vscode-${{ steps.vars.outputs.sha_short }}.vsix

- name: Package Extension
if: github.ref == 'refs/heads/master'
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

- uses: actions/upload-artifact@v2
if: github.ref != 'refs/heads/master'
with:
name: rescript-vscode-${{ steps.vars.outputs.sha_short }}.vsix
path: rescript-vscode-${{ steps.vars.outputs.sha_short }}.vsix

- uses: actions/upload-artifact@v2
if: github.ref == 'refs/heads/master'
with:
name: rescript-vscode-${{ steps.increment_pre_release.outputs.new_version }}.vsix
path: rescript-vscode-${{ steps.increment_pre_release.outputs.new_version }}.vsix

- name: Publish latest master to GitHub
if: github.ref == 'refs/heads/master'
uses: marvinpinto/action-automatic-releases@latest
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
automatic_release_tag: "latest-master"
prerelease: true
title: "Latest master"
files: rescript-vscode-${{ steps.increment_pre_release.outputs.new_version }}.vsix

- name: Publish extension as pre-release
if: github.ref == 'refs/heads/master'
run: npx vsce publish --pat ${{ secrets.MARKETPLACE_TOKEN }} --pre-release ${{ steps.increment_pre_release.outputs.new_version }} --no-git-tag-version
58 changes: 58 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@
"devDependencies": {
"@types/node": "^14.14.41",
"@types/vscode": "1.68.0",
"semver": "^7.3.7",
"typescript": "^4.7.3"
}
}