build: automate release preparation

This commit is contained in:
Andrea Lamparelli 2023-07-06 10:17:14 +02:00
parent 729b380b05
commit 841ddb9125
5 changed files with 94 additions and 5 deletions

50
.github/workflows/prepare-release.yml vendored Normal file
View file

@ -0,0 +1,50 @@
# this workflow prepare the project for the next release, it will update changelog and version based on the previous commits.
# after that it will open a pull request for this change
name: "prepare release"
on:
workflow_dispatch:
inputs:
options:
description: 'Additional release-it options'
required: false
default: ''
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
jobs:
prepare-release:
name: Prepare release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 18
- name: Git config
run: |
git config user.name "${GITHUB_ACTOR}"
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
- name: Npm config
run: npm config set //registry.npmjs.org/:_authToken $NPM_TOKEN
- run: npm ci
- name: Compute next version
run: |
next_version=$(npx release-it --release-version --no-git.requireCleanWorkingDir)
echo "NEXT_VERSION=${next_version}" >> $GITHUB_ENV
- name: Prepare the release changes
run: npm run release:prepare -- --ci --no-git.commit ${{ github.event.inputs.options }}
- name: Create Pull Request
uses: gr2m/create-or-update-pull-request-action@v1.x
with:
title: "chore: release v${{ env.NEXT_VERSION }}"
body: >
Creating changes for the next release.
branch: release/v${{ env.NEXT_VERSION }}
commit-message: "chore: release v${{ env.NEXT_VERSION }}"
reviewers: lampajr

View file

@ -24,12 +24,14 @@ jobs:
uses: actions/setup-node@v3
with:
node-version: 18
- name: git config
- name: Git config
run: |
git config user.name "${GITHUB_ACTOR}"
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
- name: npm config
- name: Npm config
run: npm config set //registry.npmjs.org/:_authToken $NPM_TOKEN
- run: npm ci
# the version/changelog must be already updated on main branch using "npm run release:prepare"
- run: npm run release -- --ci --no-increment --no-git.commit ${{ github.event.inputs.options }}
# or check prepare-release.yml workflow
- name: New version release
run: npm run release -- --ci --no-increment --no-git.commit ${{ github.event.inputs.options }}

View file

@ -30,6 +30,7 @@ Table of content
* **[Supported git services](#supported-git-services)**
* **[GitHub action](#github-action)**
* **[Future works](#future-works)**
* **[Release](#release)**
* **[Contributing](#contributing)**
* **[License](#license)**
@ -203,6 +204,41 @@ For a complete description of all inputs see [Inputs section](#inputs).
- Integrate it into other CI/CD services like gitlab CI.
- Provide some reusable *GitHub* workflows.
## Release
The release of this package is entirely based on [release-it](https://github.com/release-it/release-it) tool. I created some useful scripts that can make the release itself quite easy.
### Automated release
The first step is to prepare the changes for the next release, this is done by running:
```bash
$ npm run release:prepare:all
```
> NOTE: running locally this requires `npm login`, please consider using `.github/workflows/prepare-release.yml` if you don't have permission on the npm package.
This script performs the following steps:
1. Automatically computes the next version based on the last commits
2. Create a new branch `release/v${computed_version}`
3. Apply all changes, like version and changelog upgrade
4. Commit those changes: `chore: release v${compute_version}`
After that you should just push the new branch and open the pull request.
> NOTE: if you don't want to run this preparation from you local environment, there is already a workflow that does all these steps, including the pull request. See [Prepare release](.github/workflows/prepare-release.yml) workflow.
Once the release preparion pull request got merged, you can run [Release package](.github/workflows/release.yml) workflow that automatically performs the release itself, including npm publishing, git tag and github release.
### Manual release
In case we would like to perform a manual release, it would be enough to open a pull request changing the following items:
- Package version inside the `package.json`
- Provide exhaustive changelog information inside `CHANGELOG.md`
- Commit like `chore: release v<version>`
Once the release preparion pull request got merged, run [Release package](.github/workflows/release.yml) workflow.
## Contributing
This is an open source project, and you are more than welcome to contribute :heart:!

2
dist/cli/index.js vendored
View file

@ -23331,7 +23331,7 @@ module.exports = axios;
/***/ ((module) => {
"use strict";
module.exports = JSON.parse('{"name":"@lampajr/bper","version":"3.1.0","description":"BPer is a tool to execute automatic git backporting.","author":"","license":"MIT","private":false,"main":"./dist/gha/index.js","bin":{"bper":"./dist/cli/index.js"},"files":["dist/cli/index.js"],"scripts":{"prepare":"husky install","clean":"rm -rf ./build ./dist","compile":"tsc -p tsconfig.json && tsc-alias -p tsconfig.json","package":"npm run package:cli && npm run package:gha","package:cli":"ncc build ./build/src/bin/cli.js -o dist/cli","package:gha":"ncc build ./build/src/bin/gha.js -o dist/gha","build":"npm run clean && npm run compile && npm run package","test":"jest","test:report":"npm test -- --coverage --testResultsProcessor=jest-sonar-reporter","lint":"eslint . --ext .ts","lint:fix":"npm run lint -- --fix","ts-node":"ts-node","postversion":"npm run build && git add dist && rm -rf build","release":"release-it","release:branch":"git checkout -b release/$(release-it --release-version) main","release:prepare":"npm run release:branch && release-it --ci --no-npm.publish --no-github.release --no-git.push --no-git.tag --no-git.requireUpstream"},"repository":{"type":"git","url":"git+https://github.com/lampajr/backporting.git"},"keywords":["backporting","pull-requests","github-action","cherry-pick"],"bugs":{"url":"https://github.com/lampajr/backporting/issues"},"homepage":"https://github.com/lampajr/backporting#readme","devDependencies":{"@commitlint/cli":"^17.4.0","@commitlint/config-conventional":"^17.4.0","@gitbeaker/rest":"^39.1.0","@kie/mock-github":"^1.1.0","@release-it/conventional-changelog":"^5.1.1","@types/fs-extra":"^9.0.13","@types/jest":"^29.2.4","@types/node":"^18.11.17","@typescript-eslint/eslint-plugin":"^5.47.0","@typescript-eslint/parser":"^5.47.0","@vercel/ncc":"^0.36.0","eslint":"^8.30.0","husky":"^8.0.2","jest":"^29.0.0","jest-sonar-reporter":"^2.0.0","release-it":"^15.6.0","semver":"^7.3.8","ts-jest":"^29.0.0","ts-node":"^10.8.1","tsc-alias":"^1.8.2","tsconfig-paths":"^4.1.0","typescript":"^4.9.3","@octokit/webhooks-types":"^6.8.0"},"dependencies":{"@actions/core":"^1.10.0","@octokit/rest":"^18.12.0","axios":"^1.4.0","commander":"^9.3.0","fs-extra":"^11.1.0","https":"^1.0.0","simple-git":"^3.15.1"}}');
module.exports = JSON.parse('{"name":"@lampajr/bper","version":"3.1.0","description":"BPer is a tool to execute automatic git backporting.","author":"","license":"MIT","private":false,"main":"./dist/gha/index.js","bin":{"bper":"./dist/cli/index.js"},"files":["dist/cli/index.js"],"scripts":{"prepare":"husky install","clean":"rm -rf ./build ./dist","compile":"tsc -p tsconfig.json && tsc-alias -p tsconfig.json","package":"npm run package:cli && npm run package:gha","package:cli":"ncc build ./build/src/bin/cli.js -o dist/cli","package:gha":"ncc build ./build/src/bin/gha.js -o dist/gha","build":"npm run clean && npm run compile && npm run package","test":"jest","test:report":"npm test -- --coverage --testResultsProcessor=jest-sonar-reporter","lint":"eslint . --ext .ts","lint:fix":"npm run lint -- --fix","ts-node":"ts-node","postversion":"npm run build && git add dist && rm -rf build","release":"release-it","release:branch":"git checkout -b release/$(release-it --release-version) main","release:prepare":"release-it --no-npm.publish --no-github.release --no-git.push --no-git.tag --no-git.requireUpstream","release:prepare:all":"npm run release:branch && npm run release:prepare"},"repository":{"type":"git","url":"git+https://github.com/lampajr/backporting.git"},"keywords":["backporting","pull-requests","github-action","cherry-pick"],"bugs":{"url":"https://github.com/lampajr/backporting/issues"},"homepage":"https://github.com/lampajr/backporting#readme","devDependencies":{"@commitlint/cli":"^17.4.0","@commitlint/config-conventional":"^17.4.0","@gitbeaker/rest":"^39.1.0","@kie/mock-github":"^1.1.0","@release-it/conventional-changelog":"^5.1.1","@types/fs-extra":"^9.0.13","@types/jest":"^29.2.4","@types/node":"^18.11.17","@typescript-eslint/eslint-plugin":"^5.47.0","@typescript-eslint/parser":"^5.47.0","@vercel/ncc":"^0.36.0","eslint":"^8.30.0","husky":"^8.0.2","jest":"^29.0.0","jest-sonar-reporter":"^2.0.0","release-it":"^15.6.0","semver":"^7.3.8","ts-jest":"^29.0.0","ts-node":"^10.8.1","tsc-alias":"^1.8.2","tsconfig-paths":"^4.1.0","typescript":"^4.9.3","@octokit/webhooks-types":"^6.8.0"},"dependencies":{"@actions/core":"^1.10.0","@octokit/rest":"^18.12.0","axios":"^1.4.0","commander":"^9.3.0","fs-extra":"^11.1.0","https":"^1.0.0","simple-git":"^3.15.1"}}');
/***/ }),

View file

@ -28,7 +28,8 @@
"postversion": "npm run build && git add dist && rm -rf build",
"release": "release-it",
"release:branch": "git checkout -b release/$(release-it --release-version) main",
"release:prepare": "npm run release:branch && release-it --ci --no-npm.publish --no-github.release --no-git.push --no-git.tag --no-git.requireUpstream"
"release:prepare": "release-it --no-npm.publish --no-github.release --no-git.push --no-git.tag --no-git.requireUpstream",
"release:prepare:all": "npm run release:branch && npm run release:prepare"
},
"repository": {
"type": "git",