Update node release based on maplibre-js release workflow - v2 with changelog (#1995)

Co-authored-by: mwilsnd <mwilsnd@gmail.com>
Co-authored-by: Bart Louwers <bart@emeel.net>
Co-authored-by: Bart Louwers <bart.louwers@gmail.com>
This commit is contained in:
Andrew Calcutt
2024-01-08 12:51:31 -05:00
committed by GitHub
parent 8c940cb7a6
commit 43e52d054e
9 changed files with 159 additions and 387 deletions

View File

@@ -1,54 +1,44 @@
name: node-release
on:
push:
branches: [main]
workflow_dispatch:
inputs:
version:
description: Choose a release type
required: true
type: choice
options:
- prerelease
- prepatch
- preminor
- premajor
- patch
- minor
- major
jobs:
bump_version:
runs-on: ubuntu-20.04
release-check:
name: Check if version is published
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./
shell: bash
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.NODE_PRE_GYP_GITHUB_TOKEN }}
- name: Setup node
- name: Use Node.js from nvmrc
uses: actions/setup-node@v4
with:
node-version: 18
node-version-file: '.nvmrc'
- name: npm version
- name: Check if version is published
id: check
run: |
echo "NPM_VERSION=$(npm version ${{ github.event.inputs.version }} --preid pre --no-git-tag-version)" >> "$GITHUB_ENV"
- name: Push version to git
run: |
git config user.name github-actions
git config user.email github-actions@github.com
git commit -a -m "Update node version to ${{ env.NPM_VERSION }} (${{ github.event.inputs.version }})"
git push
currentVersion="$( node -e "console.log(require('./package.json').version)" )"
isPublished="$( npm view @maplibre/maplibre-gl-native 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_binaries:
needs: release-check
if: ${{ needs.release-check.outputs.published == 'false' }}
runs-on: ${{ matrix.runs-on }}
permissions:
contents: write
strategy:
fail-fast: false
matrix:
@@ -59,14 +49,12 @@ jobs:
arch: arm64
# Disabled until Metal backend is complete
# A release for macOS can be made from the opengl-2 branch
# - runs-on: macos-12
# arch: x86_64
# - runs-on: macos-12-arm
# - runs-on: [self-hosted, macOS, ARM64]
# arch: arm64
- runs-on: windows-2022
arch: x86_64
needs: bump_version
continue-on-error: true
env:
BUILDTYPE: "Release"
@@ -82,9 +70,6 @@ jobs:
with:
fetch-depth: 0
- name: Get Latest Version
run: git pull
- name: Setup submodules
shell: bash
run: |
@@ -129,10 +114,10 @@ jobs:
libwebp-dev
/usr/sbin/update-ccache-symlinks
- name: Setup node
- name: Use Node.js from nvmrc
uses: actions/setup-node@v4
with:
node-version: 20
node-version-file: '.nvmrc'
- name: npm ci
run: npm ci --ignore-scripts
@@ -150,7 +135,7 @@ jobs:
"PATH=$env:PATH" | Out-File -FilePath $env:GITHUB_ENV -Append
- name: Setup cmake (Linux)
if: runner.os == 'Linux' && runner.arch != 'arm64'
if: runner.os == 'Linux' && matrix.arch != 'arm64'
uses: jwlawson/actions-setup-cmake@v1.14
with:
cmake-version: "3.19.x"
@@ -242,30 +227,30 @@ jobs:
cmake --build build
- name: Publish X64 Release to Github
if: github.ref == 'refs/heads/main' && matrix.arch == 'x86_64'
if: matrix.arch == 'x86_64'
env:
PUBLISH: true
BUILDTYPE: RelWithDebInfo
NODE_PRE_GYP_GITHUB_TOKEN: ${{ secrets.NODE_PRE_GYP_GITHUB_TOKEN }}
NODE_PRE_GYP_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
./platform/node/scripts/publish.sh
- name: Publish ARM Release to Github
if: github.ref == 'refs/heads/main' && matrix.arch == 'arm64'
if: matrix.arch == 'arm64'
env:
PUBLISH: true
BUILDTYPE: RelWithDebInfo
NODE_PRE_GYP_GITHUB_TOKEN: ${{ secrets.NODE_PRE_GYP_GITHUB_TOKEN }}
NODE_PRE_GYP_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
./platform/node/scripts/publish.sh --target_arch=arm64
publish_npm:
runs-on: ubuntu-22.04
runs-on: ubuntu-latest
needs: publish_binaries
permissions:
contents: write
defaults:
run:
working-directory: ./
shell: bash
steps:
@@ -273,16 +258,48 @@ jobs:
with:
fetch-depth: 0
- name: Get Latest Version
run: git pull
- name: Setup node
- name: Use Node.js from nvmrc
uses: actions/setup-node@v4
with:
node-version: 20
node-version-file: '.nvmrc'
- name: Get version
id: package-version
uses: martinbeentjes/npm-get-version-action@v1.3.1
- name: npm ci
run: npm ci --ignore-scripts
- name: Prepare release
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 };' platform/node/CHANGELOG.md > changelog_for_version.md
cat changelog_for_version.md
- name: Update Release Notes
id: update_release_notes
uses: ncipollo/release-action@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag: node-v${{ steps.package-version.outputs.current-version }}
name: node-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: github.ref == 'refs/heads/main' && (github.event.inputs.version == 'patch' || github.event.inputs.version == 'minor' || github.event.inputs.version == 'major')
if: ${{ steps.prepare_release.outputs.prerelease == 'false' }}
run: |
npm config set //registry.npmjs.org/:_authToken "${NPM_TOKEN}"
npm publish --access public
@@ -290,7 +307,7 @@ jobs:
NPM_TOKEN: ${{ secrets.NPM_ORG_TOKEN }}
- name: Publish to NPM (prerelease)
if: github.ref == 'refs/heads/main' && (github.event.inputs.version == 'prerelease' || github.event.inputs.version == 'prepatch' || github.event.inputs.version == 'preminor' || github.event.inputs.version == 'premajor')
if: ${{ steps.prepare_release.outputs.prerelease == 'true' }}
run: |
npm config set //registry.npmjs.org/:_authToken "${NPM_TOKEN}"
npm publish --tag next --access public