Skip to content

Release previous major version #1

Release previous major version

Release previous major version #1

# 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
- run: npm i -D @actions/core
shell: bash
- name: Bump and commit version
run: |
node -e 'const core = require("@actions/core");
const versions = JSON.parse(process.argv[1]).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(".");
try {
core.exportVariable('publishVersion', newVersion);
core.exportVariable('publishVersionMajor', versionParts[0]);
} catch (error) {
core.setFailed(error.message);
}' $(npm view . versions --json | tr -d '\n ')
npm version ${{ env.publishVersion }} --git-tag-version=false
env:
VERSION_TYPE: ${{ github.event.inputs.version_type }}
- name: Publish version
run: npm publish --tag stable-v${{ env.publishVersionMajor }} --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.GRAVITY_UI_BOT_NPM_TOKEN }}
shell: bash