Publish a patch change by bold-nima #36
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: Publish Package | |
run-name: Publish a ${{ inputs.releaseType }} change by ${{ github.actor }} | |
on: | |
workflow_dispatch: | |
inputs: | |
releaseType: | |
description: 'Type of Change' | |
required: true | |
default: 'patch' | |
type: choice | |
options: | |
- minor | |
- major | |
- patch | |
jobs: | |
publish: | |
name: Publish Package | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
env: | |
GH_TOKEN: ${{ github.token }} | |
outputs: | |
new_version: ${{ steps.set_new_version.outputs.new_version }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-tags: 'true' | |
- uses: actions/setup-node@v3 | |
with: | |
node-version-file: '.nvmrc' | |
cache: 'yarn' | |
registry-url: 'https://registry.npmjs.org' | |
scope: '@boldcommerce' | |
- run: yarn --frozen-lockfile --no-progress | |
- run: yarn lint-ci | |
- run: yarn test-ci | |
- run: yarn build | |
- name: Get and set version number | |
id: set_new_version | |
run: | | |
git fetch --tags | |
last_release=$( git tag --sort=committerdate | sort -nr | head -n1 | sed 's/v//g' ) | |
release_type=${{ inputs.releaseType }} | |
echo "Creating new ${release_type} release after ${last_release}" | |
major=$(echo ${last_release} | cut -d v -f 2 | cut -d . -f 1) | |
minor=$(echo ${last_release} | cut -d . -f 2) | |
patch=$(echo ${last_release} | cut -d . -f 3) | |
case ${release_type} in | |
"major") | |
major="$(( $major + 1 ))" | |
minor=0 | |
patch=0 | |
;; | |
"minor") | |
minor="$(( $minor + 1 ))" | |
patch=0 | |
;; | |
"patch") | |
patch="$(( $patch + 1 ))" | |
;; | |
esac | |
new_version="${major}.${minor}.${patch}" | |
echo "New release is ${new_version}" | |
echo "new_version=${new_version}" >> "$GITHUB_OUTPUT" | |
npm version --no-git-tag-version --allow-same-version $new_version || exit 0 | |
- name: Publish the package | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
run: npm publish --access public | |
- name: Commit the changes | |
env: | |
new_version: ${{ steps.set_new_version.outputs.new_version }} | |
run: | | |
git reset --hard | |
git config --global user.email '[email protected]' | |
git config --global user.name 'bold-github-ci' | |
npm version --no-git-tag-version --allow-same-version $new_version || exit 0 | |
git add package.json | |
git commit -m 'Bump version number for release' || exit 0 | |
git push origin || exit 0 | |
- name: Create github release | |
env: | |
new_version: ${{ steps.set_new_version.outputs.new_version }} | |
run: | | |
gh release create ${new_version} --generate-notes --latest |