-
-
Notifications
You must be signed in to change notification settings - Fork 6
96 lines (75 loc) · 3 KB
/
version.js.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
name: Bumps - Semver version
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
on:
push:
branches: [ main ]
workflow_dispatch:
env:
node_version: 16.x
jobs:
version:
name: Bump version
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, 'chore')"
env:
old_version: ''
new_version: ''
steps:
- uses: actions/checkout@v3
- name: Setup Node.js ${{ env.node_version }}
uses: actions/setup-node@v3
with:
node-version: ${{ env.node_version }}
cache: 'yarn'
- name: Bump version
run: |
# Save old version to env
echo "old_version=$(jq -r .version package.json)" >> $GITHUB_ENV
# extract commit version
message=$(git log -1 --pretty=format:"%s")
# install standard-version
yarn add global standard-version
# bump version
yarn version
# Save new version to env
echo "new_version=$(jq -r .version package.json)" >> $GITHUB_ENV
- name: Write version to manifest.json
run: |
# Move to src folder
cd ./src
# Replace manifest version to align with package.json
manifest_version=$(jq -r .version manifest.json)
tmp=$(mktemp)
jq --arg new_version "$new_version" '.version = $new_version' manifest.json > "$tmp" && mv "$tmp" manifest.json
echo "Manifest version changed from '$manifest_version' to '$(jq -r .version manifest.json)'"
- name: Commit files
run: |
# setup the username and email. I tend to use 'GitHub Actions Bot' with no email by default
git config user.name "GitHub Bump Version Bot"
git config user.email "<>"
# Stage the file, commit and push
git status
git diff --color -U0 | cat
git add package.json yarn.lock src/manifest.json
git commit -m "chore(version): bumping version from '${{ env.old_version }}' to '${{ env.new_version }}'"
git push origin
- name: Tag release candidate
run: |
old_tag="v${{ env.old_version }}-rc"
new_tag="v${{ env.new_version }}-rc"
# create new release candidate tag
echo "New release candidate tag $new_tag"
git tag "$new_tag"
git push origin "$new_tag"
# delete previous release candidate tag
git ls-remote --exit-code -q origin "refs/tags/$old_tag"
if [ "$?" == 0 ]; then
echo "Old release candidate tag found $old_tag"
git push --delete origin "$old_tag"
else
echo "No tag found for $old_tag"
fi