-
Notifications
You must be signed in to change notification settings - Fork 0
147 lines (126 loc) · 5.81 KB
/
version_publish.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
name: Version and publish
run-name: Version and publish
on:
push:
branches:
- develop
- main
env:
VERSION_UPDATED: false
RELEASE: ${{ github.ref == 'refs/heads/main' }}
PREVIOUS_VERSION: ${{ vars.VERSION_MAJOR }}.${{ vars.VERSION_MINOR }}.${{ vars.VERSION_PATCH }}
jobs:
versioning:
runs-on: ubuntu-latest
steps:
- name: Check if version needs to be updated
run: |
COMMIT_NAME="${{ github.event.head_commit.message }}"
if [[ $COMMIT_NAME =~ ^bump:.*$ ]]; then
exit 0
fi
COMMIT_BRANCH="${{ github.ref }}"
VERSION_MAJOR=${{ vars.VERSION_MAJOR }}
VERSION_MINOR=${{ vars.VERSION_MINOR }}
VERSION_PATCH=${{ vars.VERSION_PATCH }}
if [[ $COMMIT_BRANCH == "refs/heads/main" ]]; then
if [[ $COMMIT_NAME =~ ^release:.*$ ]]; then
VERSION_MAJOR=$((VERSION_MAJOR+1))
VERSION_MINOR=0
VERSION_PATCH=0
VERSION_UPDATED=true
curl \
-X PATCH \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.TOKEN }}"\
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/Ekalia/ekalia-injector/actions/variables/VERSION_MAJOR \
-d "{\"name\":\"VERSION_MAJOR\",\"value\":\"$VERSION_MAJOR\"}"
curl \
-X PATCH \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.TOKEN }}"\
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/Ekalia/ekalia-injector/actions/variables/VERSION_MINOR \
-d "{\"name\":\"VERSION_MINOR\",\"value\":\"$VERSION_MINOR\"}"
curl \
-X PATCH \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.TOKEN }}"\
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/Ekalia/ekalia-injector/actions/variables/VERSION_PATCH \
-d "{\"name\":\"VERSION_PATCH\",\"value\":\"$VERSION_PATCH\"}"
fi
elif [[ $COMMIT_BRANCH == "refs/heads/develop" ]]; then
if [[ $COMMIT_NAME =~ ^feat.*:.*$ ]]; then
VERSION_MINOR=$((VERSION_MINOR+1))
VERSION_PATCH=0
VERSION_UPDATED=true
curl \
-X PATCH \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.TOKEN }}"\
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/Ekalia/ekalia-injector/actions/variables/VERSION_MINOR \
-d "{\"name\":\"VERSION_MINOR\",\"value\":\"$VERSION_MINOR\"}"
curl \
-X PATCH \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.TOKEN }}"\
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/Ekalia/ekalia-injector/actions/variables/VERSION_PATCH \
-d "{\"name\":\"VERSION_PATCH\",\"value\":\"$VERSION_PATCH\"}"
elif [[ $COMMIT_NAME =~ ^fix.*:.*$ ]]; then
VERSION_PATCH=$((VERSION_PATCH+1))
VERSION_UPDATED=true
curl \
-X PATCH \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.TOKEN }}"\
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/Ekalia/ekalia-injector/actions/variables/VERSION_PATCH \
-d "{\"name\":\"VERSION_PATCH\",\"value\":\"$VERSION_PATCH\"}"
fi
fi
echo "New project version : v${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}"
echo "VERSION_UPDATED=${VERSION_UPDATED}" >> $GITHUB_ENV
echo "VERSION_MAJOR=${VERSION_MAJOR}" >> $GITHUB_ENV
echo "VERSION_MINOR=${VERSION_MINOR}" >> $GITHUB_ENV
echo "VERSION_PATCH=${VERSION_PATCH}" >> $GITHUB_ENV
- name: Checkout repository
uses: actions/checkout@v3
with:
ref: ${{ github.ref }}
token: ${{ secrets.TOKEN }}
if: ${{ env.VERSION_UPDATED == 'true' }}
- name: Change version if needed
if: ${{ env.VERSION_UPDATED == 'true' }}
run: |
git config --global user.name "OscarLeBot"
git config --global user.email "[email protected]"
cp ./build.gradle.kts ./old.build.gradle.kts && sed 's/version = "${{ env.PREVIOUS_VERSION }}"/version = "${{ env.VERSION_MAJOR }}.${{ env.VERSION_MINOR }}.${{ env.VERSION_PATCH }}"/' ./old.build.gradle.kts > ./build.gradle.kts && rm ./old.build.gradle.kts
git add .
git commit -m "bump: version ${{ env.VERSION_MAJOR }}.${{ env.VERSION_MINOR }}.${{ env.VERSION_PATCH }} [no ci]"
git push origin ${{ github.ref }}
publish:
runs-on: ubuntu-latest
env:
NEXUS_USER: ${{ secrets.NEXUS_USER }}
NEXUS_PASS: ${{ secrets.NEXUS_PASS }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
ref: ${{ github.ref }}
token: ${{ secrets.TOKEN }}
- name: Set up JDK 1.16
uses: actions/setup-java@v1
with:
java-version: 1.16
- name: Make gradlew executable
run: chmod +x ./gradlew
- name: Publish changes
run: |
git pull
rm ~/.m2/settings.xml
./gradlew publish