-
Notifications
You must be signed in to change notification settings - Fork 43
81 lines (73 loc) · 3.17 KB
/
check-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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
name: Check version
on:
pull_request:
types: [opened, synchronize, reopened]
concurrency:
group: version-${{ github.head_ref }}
cancel-in-progress: true
jobs:
check-version:
runs-on: ubuntu-latest
steps:
- uses: reviewdog/action-setup@3f401fe1d58fe77e10d665ab713057375e39b887 # v1.3.0
with:
reviewdog_version: v0.17.2
- uses: tibdex/github-app-token@b62528385c34dbc9f38e5f4225ac829252d1ea92
id: generate-token
with:
app_id: ${{ secrets.APP_ID }}
private_key: ${{ secrets.APP_PRIVATE_KEY }}
- name: Checkout repository
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
with:
ref: master
- name: Master version
id: master_version
run: |
#echo version=$(./gradlew properties --no-daemon --console=plain -q | grep "^version:" | awk '{printf $2}') >> $GITHUB_OUTPUT
echo version=$(grep -o 'version = ".*"' build.gradle.kts | grep -o '[0-9\.]*') >> $GITHUB_OUTPUT
- name: Checkout repository
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- name: New version
id: new_version
run: |
#echo version=$(./gradlew properties --no-daemon --console=plain -q | grep "^version:" | awk '{printf $2}') >> $GITHUB_OUTPUT
echo version=$(grep -o 'version = ".*"' build.gradle.kts | grep -o '[0-9\.]*') >> $GITHUB_OUTPUT
- name: test version
id: version_test
run: |
compare_versions() {
IFS='.' read -r -a new_arr <<< $1
IFS='.' read -r -a master_arr <<< $2
local i
for ((i = 0; i < 3; i++)); do
if [ ${new_arr[$i]} -gt ${master_arr[$i]} ]; then
return 0
elif [ ${new_arr[$i]} -lt ${master_arr[$i]} ]; then
return 1
fi
done
return 2
}
compare_versions "${{ steps.new_version.outputs.version }}" "${{ steps.master_version.outputs.version }}" && echo status="ok" >> $GITHUB_OUTPUT || echo status="notok" >> $GITHUB_OUTPUT
- name: version is correct
if: ${{ steps.version_test.outputs.status }} == "ok"
run: echo "New version ${{ steps.new_version.outputs.version }} is OK"
- name: version is incorrect, creating suggestion
if: ${{ steps.version_test.outputs.status }} == "notok"
run: |
IFS='.' read -r -a array <<< "${{ steps.new_version.outputs.version }}"
new_version="${array[0]}.${array[1]}.$((array[2]+1))"
sed -i "s/version = \".*\"/version = \"$new_version\"/" build.gradle.kts
- name: version is incorrect, posting suggestion
if: ${{ steps.version_test.outputs.status }} == "notok"
env:
REVIEWDOG_GITHUB_API_TOKEN: ${{ steps.generate-token.outputs.token }}
run: |
git diff
git diff | reviewdog -f=diff -reporter=github-pr-review
- name: version is incorrect, reporting
if: ${{ steps.version_test.outputs.status }} == "notok"
run: |
echo "New version ${{ steps.new_version.outputs.version }} is NOT OK"
exit 1