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

Release workflow #744

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
107 changes: 107 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
name: release

on:
push:
branches: [master]
workflow_dispatch:

jobs:
release-check:
name: Check if version is published
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: 22

- name: Check if version is published
id: check
run: |
currentVersion="$( node -e "console.log(require('./package.json').version)" )"
isPublished="$( npm view @mapbox/node-pre-gyp versions --json | jq -c --arg cv "$currentVersion" 'any(. == $cv)' )"
echo "published=$isPublished" >> "$GITHUB_OUTPUT"
echo "currentVersion: $currentVersion"
echo "isPublished: $isPublished"
outputs:
published: ${{ steps.check.outputs.published }}

publish:
needs: release-check
if: ${{ needs.release-check.outputs.published == 'false' }}
runs-on: ubuntu-latest
permissions:
contents: write
defaults:
run:
shell: bash

steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: 22

- run: npm ci

- run: npm audit

- run: npm run lint

- run: npm run update-crosswalk # To support newer versions of Node.js

- run: npm run build --if-present

- run: npm test

- name: Get version
id: package-version
uses: martinbeentjes/[email protected]

- name: Prepare release changelog
id: prepare_release
run: |
RELEASE_TYPE="$(node -e "console.log(require('semver').prerelease('${{ steps.package-version.outputs.current-version }}') ? 'prerelease' : 'regular')")"
if [[ $RELEASE_TYPE == 'regular' ]]; then
echo "prerelease=false" >> "$GITHUB_OUTPUT"
else
echo "prerelease=true" >> "$GITHUB_OUTPUT"
fi

- name: Extract changelog for version
run: |
awk '/^##/ { p = 0 }; p == 1 { print }; $0 == "## ${{ steps.package-version.outputs.current-version }}" { p = 1 };' CHANGELOG.md > changelog_for_version.md
cat changelog_for_version.md

- name: Publish to Github
uses: ncipollo/release-action@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag: v${{ steps.package-version.outputs.current-version }}
name: v${{ steps.package-version.outputs.current-version }}
bodyFile: changelog_for_version.md
allowUpdates: true
draft: false
prerelease: ${{ steps.prepare_release.outputs.prerelease }}

- name: Publish to NPM (release)
if: ${{ steps.prepare_release.outputs.prerelease == 'false' }}
run: |
npm config set //registry.npmjs.org/:_authToken "${NPM_TOKEN}"
npm publish --access public
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Publish to NPM (prerelease)
if: ${{ steps.prepare_release.outputs.prerelease == 'true' }}
run: |
npm config set //registry.npmjs.org/:_authToken "${NPM_TOKEN}"
npm publish --tag next --access public
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
13 changes: 13 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Instructions for making a release

1. Change the version number in package.json. on the command line, in the package root directory, run the following command, replacing <update_type> with one of the semantic versioning release types (prerelease, prepatch, preminor, premajor, patch, minor, major):

npm version <update_type> --preid pre --no-git-tag-version

2. Update the changelog, which can be found in `CHANGELOG.md`. The heading must match `## <VERSION>` exactly, or it will not be picked up. For example, for version 1.0.11:

```
## 1.0.11
```

3. Commit and push the changes. On push the release workflow will automaticlly check if the release has been published on npm. If the release has not yet been published, the workflow will update the abi crosswalk file and publish a new npm release.