Skip to content

Commit 6f39729

Browse files
author
Oryan M
committed
Add release workflows
1 parent ba72daf commit 6f39729

File tree

4 files changed

+128
-21
lines changed

4 files changed

+128
-21
lines changed

.github/workflows/pull-request.yml

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: "Pull request"
1+
name: Pull request
22
on:
33
pull_request:
44
types: [ opened, reopened, synchronize ]
@@ -24,23 +24,3 @@ jobs:
2424
restore-keys: ${{ runner.os }}-m2
2525
- name: Build with Maven
2626
run: mvn --batch-mode --update-snapshots verify
27-
analyze:
28-
runs-on: ubuntu-latest
29-
steps:
30-
- name: Checkout
31-
uses: actions/checkout@v2
32-
- name: Setup java
33-
uses: actions/setup-java@v2
34-
with:
35-
java-version: '8'
36-
distribution: 'adopt'
37-
- name: Cache Maven packages
38-
uses: actions/cache@v2
39-
with:
40-
path: ~/.m2
41-
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
42-
restore-keys: ${{ runner.os }}-m2
43-
- name: Analyze with SonarCloud
44-
run: mvn -B clean verify sonar:sonar -Dsonar.login=${{ secrets.SONAR_TOKEN }}
45-
env:
46-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/release.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Release
2+
on: [ workflow_dispatch ]
3+
jobs:
4+
build:
5+
runs-on: ubuntu-latest
6+
steps:
7+
- name: Checkout
8+
uses: actions/checkout@v2
9+
- name: Setup java
10+
uses: actions/setup-java@v2
11+
with:
12+
java-version: '8'
13+
distribution: 'adopt'
14+
- name: Build with Maven
15+
run: mvn --batch-mode --update-snapshots verify
16+
17+
publish:
18+
runs-on: ubuntu-latest
19+
needs: build
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@v2
23+
- name: Setup Bintray
24+
uses: actions/setup-java@v2
25+
with:
26+
java-version: '8'
27+
distribution: 'adopt'
28+
server-id: bintray
29+
server-username: BINTRAY_USER
30+
server-password: BINTRAY_PASSWORD
31+
- name: Publish release
32+
run: bash github-build.sh
33+
env:
34+
MAVEN_USERNAME: ${{ secrets.OSS_USER_TOKEN_KEY }}
35+
MAVEN_PASSWORD: ${{ secrets.OSS_USER_TOKEN_PASS }}

.github/workflows/snapshot.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Release Snapshot
2+
on:
3+
push:
4+
branches:
5+
- master
6+
jobs:
7+
build:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Checkout
11+
uses: actions/checkout@v2
12+
- name: Setup java
13+
uses: actions/setup-java@v2
14+
with:
15+
java-version: '8'
16+
distribution: 'adopt'
17+
- name: Build with Maven
18+
run: mvn --batch-mode --update-snapshots verify
19+
20+
publish:
21+
runs-on: ubuntu-latest
22+
needs: build
23+
steps:
24+
- name: Checkout
25+
uses: actions/checkout@v2
26+
- name: Setup Bintray
27+
uses: actions/setup-java@v2
28+
with:
29+
java-version: '8'
30+
distribution: 'adopt'
31+
server-id: bintray
32+
server-username: BINTRAY_USER
33+
server-password: BINTRAY_PASSWORD
34+
- name: Publish release
35+
run: mvn --batch-mode -Pbintray deploy
36+
env:
37+
MAVEN_USERNAME: ${{ secrets.OSS_USER_TOKEN_KEY }}
38+
MAVEN_PASSWORD: ${{ secrets.OSS_USER_TOKEN_PASS }}

github-build.sh

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/bin/bash
2+
set -ev
3+
4+
getVersion() {
5+
grep -m1 -o '[^<>]*-SNAPSHOT' pom.xml
6+
}
7+
8+
removeSnapshots() {
9+
sed -i 's/-SNAPSHOT//' pom.xml
10+
}
11+
12+
commitRelease() {
13+
local APP_VERSION=$(getVersion)
14+
git commit -a -m "Update version for release"
15+
git tag -a "v${APP_VERSION}" -m "Tag release version"
16+
}
17+
18+
bumpVersion() {
19+
echo "Bump version number"
20+
local APP_VERSION=$(getVersion | xargs)
21+
local SEMANTIC_REGEX='^([0-9]+)\.([0-9]+)(\.([0-9]+))?$'
22+
if [[ ${APP_VERSION} =~ ${SEMANTIC_REGEX} ]]; then
23+
if [[ ${BASH_REMATCH[4]} ]]; then
24+
nextVersion=$((BASH_REMATCH[4] + 1))
25+
nextVersion="${BASH_REMATCH[1]}.${BASH_REMATCH[2]}.${nextVersion}-SNAPSHOT"
26+
else
27+
nextVersion=$((BASH_REMATCH[2] + 1))
28+
nextVersion="${BASH_REMATCH[1]}.${nextVersion}-SNAPSHOT"
29+
fi
30+
31+
echo "Next version: ${nextVersion}"
32+
sed -i "'0,/<version>.*<\/version>/s//<version>${nextVersion}<\/version>/'" pom.xml
33+
34+
else
35+
echo "No semantic version and therefore cannot publish to maven repository: '${APP_VERSION}'"
36+
fi
37+
}
38+
39+
commitNextVersion() {
40+
git commit -a -m "Update version for release"
41+
}
42+
43+
git config --global user.email "actions@github.com"
44+
git config --global user.name "GitHub Actions"
45+
46+
echo "Deploying release to Bintray"
47+
removeSnapshots
48+
49+
mvn release:clean release:prepare release:perform -B -e -Pbintray
50+
51+
commitRelease
52+
bumpVersion
53+
commitNextVersion
54+
git push --follow-tags

0 commit comments

Comments
 (0)