Skip to content

Commit

Permalink
Removes manual steps in creating a version (#3330)
Browse files Browse the repository at this point in the history
  • Loading branch information
HarelM authored Nov 9, 2023
1 parent ba72cb9 commit 4e7d477
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 16 deletions.
29 changes: 18 additions & 11 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
name: Release

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

jobs:
release:
Expand All @@ -22,27 +27,29 @@ jobs:
with:
node-version-file: '.nvmrc'

- name: Get version
id: package-version
uses: martinbeentjes/npm-get-version-action@v1.3.1

# - name: Check tag does not exist yet
# run: if git rev-list v${{ steps.package-version.outputs.current-version }}; then echo "Tag already exists. Aborting the release process."; exit 1; fi

- name: Bump version
run: |
npm version --commit-hooks false --git-tag-version false ${{ inputs.version }}
./build/bump-version-changelog.js
git commit -m "Bump version to ${{ inputs.version }}"
- name: Push changes
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
- name: Tag commit and push
uses: mathieudutour/github-tag-action@v6.1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
custom_tag: ${{ steps.package-version.outputs.current-version }}
custom_tag: ${{ inputs.version }}

- name: Install
run: npm ci

- name: Prepare release
id: prepare_release
run: |
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 "version_tag=v${{ inputs.version }}" >> $GITHUB_OUTPUT
RELEASE_TYPE=$(node -e "console.log(require('semver').prerelease('${{ inputs.version }}') ? 'prerelease' : 'regular')")
echo "release_type=$RELEASE_TYPE" >> $GITHUB_OUTPUT
- name: Build
Expand Down
26 changes: 26 additions & 0 deletions build/bump-version-changelog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env node

/**
* This script updates the changelog.md file with the version given in the arguments
* It replaces ## main with ## <version>
* Removes _...Add new stuff here..._
* And adds on top a ## main with add stuff here.
*/

import * as fs from 'fs';

const changelogPath = 'CHANGELOG.md';
let changelog = fs.readFileSync(changelogPath, 'utf8');
changelog = changelog.replace('## main', `## ${process.argv[2]}`);
changelog = changelog.replaceAll('- _...Add new stuff here..._\n', '');
changelog = `## main
### ✨ Features and improvements
- _...Add new stuff here..._
### 🐞 Bug fixes
- _...Add new stuff here..._
` + changelog;

fs.writeFileSync(changelogPath, changelog, 'utf8');
7 changes: 2 additions & 5 deletions developer-guides/release-process.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@

1. Review [`CHANGELOG.md`](../CHANGELOG.md)
- Double-check that all changes included in the release are [appropriately documented](../CONTRIBUTING.md#changelog-conventions).
- To-be-released changes should be under a placeholder header. Update that header to the version number which is about to be released. This project uses [semantic versioning](https://docs.npmjs.com/about-semantic-versioning).
- To-be-released changes should be under the "main" header.
- Commit any final changes to the changelog.
2. Bump the version number with `npm version VERSIONTYPE --no-git-tag-version`
- e.g. if making a backwards-compatible release with new features, run `npm version minor --no-git-tag-version`
- [`npm version`](https://docs.npmjs.com/cli/commands/npm-version) will increment the version in `package.json` and `package-lock.json`.
3. Run [`release.yml`](https://github.com/maplibre/maplibre-gl-js/actions/workflows/release.yml) by manual workflow dispatch. 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 [`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.

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

0 comments on commit 4e7d477

Please sign in to comment.