Skip to content

Commit

Permalink
Automate release (#3335)
Browse files Browse the repository at this point in the history
* Move bump logic to a PR

* Missing parameter, and workflow fix

* Fix release output

* Better names

* Better name for output

* Update docs about release
  • Loading branch information
HarelM committed Nov 9, 2023
1 parent f49098d commit effad76
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 18 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/create-bumb-version-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Create bump version PR

on:
workflow_dispatch:
inputs:
version:
description: Version to change to.
required: true
type: string

jobs:
bump-version-pr:
name: Bump version PR
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:

- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: main

- name: Use Node.js from nvmrc
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'

- name: Bump version
run: |
npm version --commit-hooks false --git-tag-version false ${{ inputs.version }}
./build/bump-version-changelog.js ${{ inputs.version }}
- name: Create Pull Request
uses: peter-evans/create-pull-request@v5
with:
commit-message: Bump version to ${{ inputs.version }}
branch: bump-version-to-${{ inputs.version }}
title: Bump version to ${{ inputs.version }}
56 changes: 39 additions & 17 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,44 @@
name: Release

on:
push:
branches: [main]
workflow_dispatch:
inputs:
version:
description: Version to change to.
required: true
type: string

jobs:
release:
name: Release
release-check:
name: Check if version changed
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: main

- name: Use Node.js from nvmrc
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'

- name: Check if version changed
id: check
uses: EndBug/version-check@v2

outputs:
publish: ${{ steps.check.outputs.changed }}

release-publish:
name: Publish to NPM and GitHub
needs: release-check
if: ${{ needs.release-check.outputs.publish == 'true' }}
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
Expand All @@ -27,24 +49,24 @@ jobs:
with:
node-version-file: '.nvmrc'

- name: Bump version
run: |
npm version --commit-hooks false --git-tag-version false ${{ inputs.version }}
./build/bump-version-changelog.js
- name: Commit and push version bump with a tag
uses: stefanzweifel/git-auto-commit-action@v5
- name: Get version
id: package-version
uses: martinbeentjes/npm-get-version-action@v1.3.1

- name: Tag commit and push
uses: mathieudutour/github-tag-action@v6.1
with:
commit_message: Bump version to ${{ inputs.version }}
tagging_message: ${{ inputs.version }}
github_token: ${{ secrets.GITHUB_TOKEN }}
custom_tag: ${{ steps.package-version.outputs.current-version }}

- name: Install
run: npm ci

- name: Prepare release
id: prepare_release
run: |
echo "version_tag=v${{ inputs.version }}" >> $GITHUB_OUTPUT
RELEASE_TYPE=$(node -e "console.log(require('semver').prerelease('${{ inputs.version }}') ? 'prerelease' : 'regular')")
echo "version_tag=v${{ steps.package-version.outputs.current-version }}" >> $GITHUB_OUTPUT
RELEASE_TYPE=$(node -e "console.log(require('semver').prerelease('${{ steps.package-version.outputs.current-version }}') ? 'prerelease' : 'regular')")
echo "release_type=$RELEASE_TYPE" >> $GITHUB_OUTPUT
- name: Build
Expand Down
3 changes: 2 additions & 1 deletion developer-guides/release-process.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- Double-check that all changes included in the release are [appropriately documented](../CONTRIBUTING.md#changelog-conventions).
- To-be-released changes should be under the "main" header.
- Commit any final changes to the changelog.
2. Run [`release.yml`](https://github.com/maplibre/maplibre-gl-js/actions/workflows/release.yml) by manual workflow dispatch and set the version number in the input. This builds the minified library, tags the commit based on the version in `package.json`, creates a GitHub release, uploads release assets, and publishes the build output to NPM.
2. Run [Create bump version PR](https://github.com/maplibre/maplibre-gl-js/actions/workflows/create-bump-version-pr.yml) by manual workflow dispatch and set the version number in the input. This will create a PR that changes the changelog and `package.json` file to review and merge.
3. Once merged the release action will automatically see that the version was changed and creates a GitHub release, uploads release assets, and publishes the build output to NPM.

The workflow expects `${{ secrets.NPM_ORG_TOKEN }}` organization secret in order to push to NPM registry.

0 comments on commit effad76

Please sign in to comment.