-
Notifications
You must be signed in to change notification settings - Fork 7
79 lines (77 loc) · 3.28 KB
/
release-previous-stable.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# 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