Skip to content

Publish a minor change by bCWarkent #12

Publish a minor change by bCWarkent

Publish a minor change by bCWarkent #12

Workflow file for this run

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'
registry-url: 'https://registry.npmjs.org'
scope: '@boldcommerce'
cache: 'yarn'
- name: Yarn install and build
run: |
yarn install --immutable --no-progress
yarn lint-ci
yarn test-ci
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"
git pull --rebase
npm version --no-git-tag-version --allow-same-version $new_version || exit 0
- name: Commit the changes
continue-on-error: true
run: |
git config --global user.email '[email protected]'
git config --global user.name 'bold-github-ci'
git add package.json package-lock.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
- run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}