-
Notifications
You must be signed in to change notification settings - Fork 7
64 lines (56 loc) · 2.01 KB
/
autoincrement-project-version.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
name: Autoincrement project version
on:
pull_request:
branches:
- main
- master
types: [opened,edited,reopened,synchronize]
jobs:
increment_version:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.head_ref }}
path: ${{ github.head_ref }}
- uses: actions/checkout@v2
with:
ref: ${{ github.base_ref }}
path: ${{ github.base_ref }}
- name: Set up Node
uses: actions/setup-node@v2
with:
node-version: '20.9.0'
- name: Set Project Version
env:
event: ${{ github.event.action }}
event_label_name: ${{ github.event.label.name }}
run: |
cd ${{ github.workspace }}/${{ github.base_ref }}
curent_version=`npm -s run-script get-version`
echo "Curent version: $curent_version"
cd ${{ github.workspace }}/${{ github.head_ref }}
merge_version=`npm -s run-script get-version`
echo "New version: $merge_version"
max_version=`printf '%s\n' "$merge_version" "$curent_version" | sort -V | tail -n 1`
echo "Max version: $max_version"
if [ "$max_version" == "$curent_version" ]
then
echo "Increment project version"
echo "From:"
npm version $max_version --no-git-tag-version --allow-same-version
echo "To:"
npm version patch --no-git-tag-version
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git commit -am "Autoincrement version to $curent_version"
else
echo "Keep project version:"
npm version $merge_version --no-git-tag-version --allow-same-version
fi
- name: Push changes
uses: ad-m/github-push-action@v0.6.0
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.head_ref }}
directory: ${{ github.head_ref }}