-
Notifications
You must be signed in to change notification settings - Fork 24
125 lines (113 loc) · 4.13 KB
/
release.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
name: Release
on:
release:
types:
- published
jobs:
sonar:
if: "!contains(github.event.head_commit.message, '[version bump]')"
runs-on: ubuntu-latest
steps:
- name: Checkout project
uses: actions/checkout@v4
- name: Setup Java
uses: actions/setup-java@v4
with:
distribution: 'microsoft'
java-version: '17'
cache: 'maven'
- name: Build and Analyze
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: mvn -B verify sonar:sonar -Dgpg.skip
publish:
if: "!contains(github.event.head_commit.message, '[version bump]')"
runs-on: ubuntu-latest
needs: [ sonar ]
steps:
- name: Checkout project
uses: actions/checkout@v4
- name: Setup Java
uses: actions/setup-java@v4
with:
distribution: 'microsoft'
java-version: '17'
cache: 'maven'
server-id: 'central'
server-username: SONATYPE_USERNAME
server-password: SONATYPE_PASSWORD
gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }}
gpg-passphrase: GPG_PASSPHRASE
- name: Configure Git user
run: |
git config user.email "[email protected]"
git config user.name "GitHub Actions"
- name: Get version from POM without SNAPSHOT
run: |
VERSION_PARTS=($(mvn help:evaluate -Dexpression=project.version -q -DforceStdout | cut -d- -f1 | tr "." "\n"))
echo "MAJOR=${VERSION_PARTS[0]}" >> $GITHUB_ENV
echo "MINOR=${VERSION_PARTS[1]}" >> $GITHUB_ENV
echo "PATCH=${VERSION_PARTS[2]}" >> $GITHUB_ENV
- name: Setup release version
run: |
NEW_VERSION="$((MAJOR)).$((MINOR)).$((PATCH))"
echo "NEW_VERSION=${NEW_VERSION}" >> $GITHUB_ENV
- name: Update POM Version
run: |
echo "New version is: $NEW_VERSION"
mvn versions:set -DnewVersion=${NEW_VERSION} -DgenerateBackupPoms=false -B
- name: Build and Publish
run: |
mvn \
--no-transfer-progress \
--batch-mode \
-DskipTests=true \
-Psonatype-deploy \
deploy
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
- name: Commit files
run: |
git commit -m "[version bump]" -a
git tag -a release-$NEW_VERSION -m "[version bump]"
git push origin release-$NEW_VERSION
bump:
if: "!contains(github.event.head_commit.message, '[version bump]')"
runs-on: ubuntu-latest
needs: [ publish ]
steps:
- name: Checkout Branch
uses: actions/checkout@v4
- name: Setup Java
uses: actions/setup-java@v4
with:
distribution: 'microsoft'
java-version: '17'
cache: 'maven'
- name: Configure Git user
run: |
git config user.email "[email protected]"
git config user.name "GitHub Actions"
- name: Get version from POM without SNAPSHOT
run: |
VERSION_PARTS=($(mvn help:evaluate -Dexpression=project.version -q -DforceStdout | cut -d- -f1 | tr "." "\n"))
echo "MAJOR=${VERSION_PARTS[0]}" >> $GITHUB_ENV
echo "MINOR=${VERSION_PARTS[1]}" >> $GITHUB_ENV
echo "PATCH=${VERSION_PARTS[2]}" >> $GITHUB_ENV
- name: Bump And Update POM Version to new Development version
run: |
NEW_VERSION="$((MAJOR)).$((MINOR)).$((PATCH+1))-SNAPSHOT"
echo "New development version is: $NEW_VERSION"
mvn versions:set -DnewVersion=${NEW_VERSION} -DgenerateBackupPoms=false
- name: Commit files
run: |
git commit -m "[version bump] new dev version" -a
- name: Push Development Version to Branch
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{github.event.release.target_commitish || 'main'}}