📦 Release patch by @qwqcode #13
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: 📦 Release New Version | |
run-name: 📦 Release ${{ inputs.custom || inputs.semver }} by @${{ github.actor }} | |
on: | |
workflow_dispatch: | |
inputs: | |
semver: | |
type: choice | |
description: Which version you want to increment? | |
options: | |
- patch | |
- minor | |
- major | |
required: true | |
# custom: | |
# description: 'Custom tag name (i.e v1.0.0-rc.1)' | |
# required: false | |
# default: '' | |
env: | |
REPO_DISPATCH_EVENT_TYPE: 'artalk-release' | |
UI_NPM_PKG_FILE: 'ui/packages/artalk/package.json' | |
jobs: | |
release: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v3 | |
- name: Git Fetch | |
run: git fetch --prune --unshallow --tags -f | |
- name: Setup Node | |
uses: actions/setup-node@v3 | |
with: | |
node-version: 18.x | |
registry-url: https://registry.npmjs.org/ | |
- name: Handle Version Number | |
run: | | |
if [ ! -z "${{ inputs.custom }}" ]; then | |
next_version="${{ inputs.custom }}" | |
else | |
npm install -g semver | |
prev_version="$(git describe --tags --abbrev=0)" | |
echo "prev_version: ${prev_version}" | |
next_version="v$(semver --increment ${{ inputs.semver }} ${prev_version})" | |
fi | |
if [[ ! "${next_version}" =~ ^v.* ]]; then | |
echo "[err] custom tag name must be v*." | |
exit 1 | |
fi | |
echo "next_version: ${next_version}" | |
echo "VERSION=${next_version}" >> $GITHUB_ENV | |
- name: Setup git-chglog | |
run: | | |
curl -sL $(curl -s https://api.github.com/repos/git-chglog/git-chglog/releases/latest \ | |
| grep -oP '"https://.+linux_amd64.tar.gz"' | tr -d \") | tar -C /usr/local/bin -xz git-chglog | |
git-chglog --version | |
- name: Version Changelog and Tagging | |
run: | | |
if [ ! $(git tag -l "${VERSION}") ]; then | |
# prepend changelog | |
changelog=$(git-chglog --config .github/chglog/config.yml --next-tag "${VERSION}" "${VERSION}") | |
echo -e "${changelog}\n" | cat - CHANGELOG.md > temp && mv temp CHANGELOG.md | |
# modify the version of `package.json` | |
perl -i -pe 's/"version": ".*?"/"version": "'${VERSION#v}'"/g' "${UI_NPM_PKG_FILE}" | |
# modify the version in docs | |
perl -pi -e 's#"latest"(\W+)?:(\W+)?".*?"#"latest": "'${VERSION#v}'"#g' docs/code/ArtalkVersion.json | |
# git commit and push | |
git config user.name github-actions[bot] | |
git config user.email 41898282+github-actions[bot]@users.noreply.github.com | |
git add . | |
git commit -m "chore: release ${VERSION}" | |
git tag "${VERSION}" | |
git push origin master "${VERSION}" | |
else | |
echo "skipped because git tag already exists." | |
fi | |
- name: Repository Dispatch | |
uses: peter-evans/repository-dispatch@v2 | |
with: | |
event-type: ${{ env.REPO_DISPATCH_EVENT_TYPE }} |