Skip to content

Commit ce82d03

Browse files
committed
update release workflow
1 parent 3df3b4f commit ce82d03

File tree

1 file changed

+90
-11
lines changed

1 file changed

+90
-11
lines changed

.github/workflows/release.yml

Lines changed: 90 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,122 @@
11
name: Release
2+
23
permissions:
34
contents: write
4-
on: workflow_dispatch
5+
packages: write
6+
7+
on:
8+
workflow_dispatch:
9+
inputs:
10+
releaseType:
11+
type: choice
12+
description: "Release type"
13+
required: true
14+
default: minor
15+
options:
16+
- patch
17+
- minor
18+
- major
19+
520
jobs:
621
release:
722
runs-on: ubuntu-latest
823
steps:
9-
- uses: actions/checkout@v4
24+
- name: Checkout repository
25+
uses: actions/checkout@v4
1026

11-
- uses: actions/cache@v4
27+
- name: Setup cache
28+
uses: actions/cache@v4
1229
with:
1330
path: ~/.m2/repository
1431
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
1532
restore-keys: |
1633
${{ runner.os }}-maven-
17-
- name: Set up JDK 21
34+
35+
- name: Setup JDK 21
1836
uses: actions/setup-java@v4
1937
with:
2038
java-version: 21
2139
distribution: zulu
22-
- uses: whelk-io/maven-settings-xml-action@v22
40+
cache: maven
41+
42+
- name: Setup Maven
43+
uses: whelk-io/maven-settings-xml-action@v22
2344
with:
2445
servers: >
2546
[
2647
{ "id": "central", "username": "${{ secrets.MAVEN_CENTRAL_TOKEN_USER }}", "password": "${{ secrets.MAVEN_CENTRAL_TOKEN_PASS }}" }
2748
]
2849
29-
- run: git config --global user.name phocasadmin; git config --global user.email [email protected]
50+
- name: Get current development version
51+
id: get_version
52+
run: |
53+
VERSION=$( mvn help:evaluate -Dexpression=project.version -q -DforceStdout | sed 's/-SNAPSHOT//' )
54+
echo "version=$VERSION" >> $GITHUB_OUTPUT
55+
56+
- name: Generate versions
57+
id: generate_versions
58+
uses: WyriHaximus/[email protected]
59+
with:
60+
version: ${{ steps.get_version.outputs.version }}
3061

31-
- name: add key
62+
- name: Pick release version
63+
id: pick_release_version
64+
run: |
65+
VERSION=$(
66+
case ${{ github.event.inputs.releaseType }} in
67+
("minor") echo "${{ steps.generate_versions.outputs.minor }}" ;;
68+
("major") echo "${{ steps.generate_versions.outputs.major }}" ;;
69+
("patch") echo "${{ steps.generate_versions.outputs.patch }}" ;;
70+
esac
71+
)
72+
echo "version=$VERSION" >> $GITHUB_OUTPUT
73+
74+
- name: Setup Git
75+
run: |
76+
git config --global user.name phocasadmin;
77+
git config --global user.email [email protected]
78+
79+
- name: Setup key
3280
run: |
3381
echo "${{ secrets.MAVEN_PRIVATE_KEY }}" | base64 -d > private.key
3482
gpg --batch --import ./private.key
3583
rm ./private.key
3684
gpg --list-secret-keys --keyid-format LONG
3785
38-
- name: prepare
86+
- name: Maven prepare release
3987
run: |
40-
mvn release:prepare -Dusername=${{ secrets.GITHUB_TOKEN }} -P sonatype -DscmForceUpdate=true
41-
- name: release
88+
mvn release:prepare -DreleaseVersion=${release_version} \
89+
-DdevelopmentVersion=${release_version}-SNAPSHOT \
90+
-Dusername=${{ secrets.GITHUB_TOKEN }} \
91+
-P sonatype -DscmForceUpdate=true
92+
env:
93+
release_version: ${{ steps.pick_release_version.outputs.version }}
94+
95+
- name: Maven perform release
96+
run: |
97+
mvn release:perform -DreleaseVersion=${release_version} \
98+
-DdevelopmentVersion=${release_version}-SNAPSHOT \
99+
-Dusername=${{ secrets.GITHUB_TOKEN }} \
100+
-P sonatype -DscmForceUpdate=true
101+
env:
102+
release_version: ${{ steps.pick_release_version.outputs.version }}
103+
104+
- name: Create GitHub release
42105
run: |
43-
mvn release:perform -Dusername=${{ secrets.GITHUB_TOKEN }} -P sonatype -DscmForceUpdate=true
106+
repo_name="${GITHUB_REPOSITORY#*/}"
107+
prior_release_tag=$(git tag --list "${repo_name}-*" --sort=-creatordate | sed -n '2p')
108+
if [ -z "$prior_release_tag" ]; then
109+
gh release create "${repo_name}-${release_version}" \
110+
--repo="$GITHUB_REPOSITORY" \
111+
--title="${release_version}" \
112+
--generate-notes
113+
else
114+
gh release create "${repo_name}-${release_version}" \
115+
--repo="$GITHUB_REPOSITORY" \
116+
--title="${release_version}" \
117+
--generate-notes \
118+
--notes-start-tag "${prior_release_tag}"
119+
fi
120+
env:
121+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
122+
release_version: ${{ steps.pick_release_version.outputs.version }}

0 commit comments

Comments
 (0)