Skip to content

📦 Release patch by @qwqcode (🧪 dry-run) #23

📦 Release patch by @qwqcode (🧪 dry-run)

📦 Release patch by @qwqcode (🧪 dry-run) #23

Workflow file for this run

name: 📦 Release New Version
run-name: 📦 Release ${{ inputs.custom || inputs.semver }} by @${{ github.actor }} ${{ inputs.dry-run && '(🧪 dry-run)' || '' }}
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: ''
dry-run:
description: 'Dry run?'
type: boolean
required: false
default: false
env:
REPO_DISPATCH_EVENT_TYPE: 'artalk-release'
UI_NPM_PKG_FILE: 'ui/artalk/package.json'
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
fetch-tags: true
- name: Setup Node
uses: actions/setup-node@v4
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}"
echo "PREV_VERSION=${prev_version}" >> $GITHUB_ENV
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: Print Next Version
run: echo "${VERSION}"
- 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
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
if [ "${{ inputs.dry-run }}" = "false" ]; then
git push origin master "${VERSION}"
else
git diff HEAD^ HEAD
fi
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 }}
client-payload: '{"version": ${{ toJSON(inputs.dry-run && env.PREV_VERSION || env.VERSION) }}, "dry_run": ${{ toJSON(inputs.dry-run) }}}'