Skip to content

Release previous major version #9

Release previous major version

Release previous major version #9

# Build and publish previous major version for @gravity-ui/navigation
# Runs manually in Actions tabs in github
# Runs on any branch except main
name: Release previous major version
on:
workflow_dispatch:
inputs:
version_type:
type: choice
description: Select type of version for release
options:
- patch
- minor
jobs:
build:
runs-on: ubuntu-latest
steps:
- run: |
if [ "${{ github.event.inputs.version_type }}" == "" ]; then
echo "version_type must be defined"
exit 1
fi
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 18
registry-url: 'https://registry.npmjs.org'
- run: npm ci
shell: bash
- run: npm test
shell: bash
- name: Get package versions
id: npm_versions
run: |
npm_view_output=$(npm view . versions --json | tr -d '\n ')
echo ${npm_view_output}
echo "name=npm_versions::${npm_view_output}" >> $GITHUB_OUTPUT
- name: Bump and commit version
uses: actions/github-script@v7
with:
script: |
core.info(`versions: ${process.env.VERSIONS}`);
const versions = JSON.parse(process.env.VERSIONS).reverse();
const currMajor = versions[0].split(".")[0];
const prevVersion = versions.find(v => !v.startsWith(`${currMajor}.`));
if (!prevVersion) {
throw Error("Previous major versions not found");
}
const versionParts = prevVersion.split(".");
if (versionParts.length !== 3) {
throw Error(`Cannot parse version ${prevVersion}`);
}
if (process.env.VERSION_TYPE === "minor") {
versionParts[1] = `${Number(versionParts[1])+1}`;
}
else {
versionParts[2] = `${Number(versionParts[2])+1}`;
}
const newVersion = versionParts.join(".");
core.info(`New version: ${newVersion}`);
try {
core.exportVariable('PUBLISH_VERSION', newVersion);
core.exportVariable('PUBLISH_VERSION_MAJOR', versionParts[0]);
} catch (error) {
core.setFailed(error.message);
}
env:
VERSION_TYPE: ${{ github.event.inputs.version_type }}
VERSIONS: ${{ steps.npm_versions.outputs.npm_versions }}
- name: Set version
run: |
npm version ${{ env.PUBLISH_VERSION }} --git-tag-version=false
- name: Publish version
run: npm publish --tag stable-v${{ env.PUBLISH_VERSION_MAJOR }} --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.GRAVITY_UI_BOT_NPM_TOKEN }}
shell: bash