-
Notifications
You must be signed in to change notification settings - Fork 9
159 lines (153 loc) · 7.3 KB
/
jreleaser.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
148
149
150
151
152
153
154
155
156
157
158
159
name: Release
on:
workflow_dispatch:
inputs:
version:
description: 'Next release version'
required: true
default: 'patch'
type: choice
options:
- major
- minor
- patch
jobs:
build:
name: Build and release
runs-on: ubuntu-latest
steps:
- uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2
with:
egress-policy: audit
# Setups the environment
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
with:
fetch-depth: 0
token: ${{ secrets.JRELEASER_GITHUB_TOKEN }}
- name: Set up JDK 17
uses: actions/setup-java@8df1039502a15bceb9433410b1a100fbe190c53b # v4
with:
java-version: '17'
distribution: 'temurin'
cache: maven
- name: Set up Maven
uses: stCarolas/setup-maven@d6af6abeda15e98926a57b5aa970a96bb37f97d1 # v5
with:
maven-version: 3.9.6
- name: Set git user
run: |
git config --global user.name "GitHub Actions Bot"
git config --global user.email "<>"
- name: install go
uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5
- name: install semversion
run: go install github.com/ffurrer2/semver/cmd/semver@latest
# Get current version from pom and remove snapshot if present.
- name: Get current version from pom and remove snapshot if present.
run: echo "CURRENT_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout | sed 's/-SNAPSHOT//')" >> $GITHUB_ENV
- name: Get version with snapshot
run: echo "CURRENT_VERSION_WITH_SNAPSHOT=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)" >> $GITHUB_ENV
# Calculate next version:
# - if version is patch, we just increment the patch version
# - if version is minor or major, we increment the minor or major version and set the patch version to 0
# As we are using a snapshot version, we need to run semver next twice to get the next version for mahor and minor releases. Reason: Any X.Y.Z-SNAPSHOT version will be released as X.Y.Z if we run semver next major X.Y.Z-SNAPSHOT
- name: Set next version
if: ${{ github.event.inputs.version == 'patch' }}
run: echo "NEXT_VERSION=$(semver next ${{ github.event.inputs.version }} $CURRENT_VERSION_WITH_SNAPSHOT)" >> $GITHUB_ENV
- name: Set next version
# semver next for a snapshot only releases the snapshot version, so we need to run it 2 times
if: ${{ github.event.inputs.version == 'major' || github.event.inputs.version == 'minor' }}
run: echo "NEXT_VERSION=$(semver next ${{ github.event.inputs.version }} $CURRENT_VERSION)" >> $GITHUB_ENV
- name: run maven-lockfile
uses: chains-project/maven-lockfile@526cd67327ab19c7bd95be6d2d16530d80bf3c9e # v5.2.0
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
include-maven-plugins: true
- name: set branchname to next version
run: echo "BRANCH_NAME=release/$NEXT_VERSION" >> $GITHUB_ENV
- name: Set release version
run: mvn --no-transfer-progress --batch-mode versions:set -DnewVersion=$NEXT_VERSION -DprocessAllModules
- name: Generate Readme
run : mvn generate-resources resources:copy-resources
- name: commit changes
run: |
git checkout -b ${{ env.BRANCH_NAME }}
git commit -am "🔖 Releasing version ${{ env.NEXT_VERSION }}"
git push --set-upstream origin ${{ env.BRANCH_NAME }}
# Now we can run the release
- name: Stage release
run: mvn --no-transfer-progress --batch-mode -Ppublication clean deploy -DaltDeploymentRepository=local::file:./target/staging-deploy
- name: generate buildinfo file
run: mvn org.apache.maven.plugins:maven-artifact-plugin:3.4.1:buildinfo
- name: Print next version
run: mvn help:evaluate -Dexpression=project.version -q -DforceStdout | sed 's/-SNAPSHOT//'
- name: Run JReleaser
uses: jreleaser/release-action@f69e545b05f149483cecb2fb81866247992694b8
with:
setup-java: false
version: 1.15.0
arguments: full-release
env:
JRELEASER_PROJECT_VERSION: ${{ env.NEXT_VERSION }}
JRELEASER_GITHUB_TOKEN: ${{ secrets.JRELEASER_GITHUB_TOKEN }}
JRELEASER_GPG_PASSPHRASE: ${{ secrets.JRELEASER_GPG_PASSPHRASE }}
JRELEASER_GPG_PUBLIC_KEY: ${{ secrets.JRELEASER_GPG_PUBLIC_KEY }}
JRELEASER_GPG_SECRET_KEY: ${{ secrets.JRELEASER_GPG_SECRET_KEY }}
JRELEASER_NEXUS2_MAVEN_CENTRAL_USERNAME: ${{ secrets.JRELEASER_NEXUS2_MAVEN_CENTRAL_USERNAME }}
JRELEASER_NEXUS2_MAVEN_CENTRAL_PASSWORD: ${{ secrets.JRELEASER_NEXUS2_MAVEN_CENTRAL_PASSWORD }}
# Now we can update the changelog
- name: Append changelog from out/jreleaser/CHANGELOG.md to CHANGELOG.md with version as header
run: |
echo "" >> CHANGELOG.md
echo -n "# ${{ env.NEXT_VERSION }}" >> CHANGELOG.md
echo "" >> CHANGELOG.md
cat out/jreleaser/release/CHANGELOG.md >> CHANGELOG.md
echo "" >> CHANGELOG.md
# Time to set the next version: The next version of any Release is a snapshot version of the next patch version
- name : Set next version (patch of release version) with -SNAPSHOT suffix
run: |
echo "NEXT_RELEASE_VERSION=$(semver next patch $NEXT_VERSION)-SNAPSHOT" >> $GITHUB_ENV
echo "NEXT_RELEASE_VERSION_WITHOUT_SNAPSHOT=$(semver next patch $NEXT_VERSION)" >> $GITHUB_ENV
- name: Set release version
run: mvn --no-transfer-progress --batch-mode versions:set -DnewVersion=$NEXT_RELEASE_VERSION -DprocessAllModules
# Time to update some files with the new version
#1 Readme and action.yml
- name: Generate Readme
run : mvn generate-resources resources:copy-resources -q
# Commit and push changes
- name: Commit & Push changes
run: |
git commit -am "🔖 Setting SNAPSHOT version ${{ env.NEXT_RELEASE_VERSION }}"
git push --set-upstream origin ${{ env.BRANCH_NAME }}
- name: Merge Fast Forward
run: |
git checkout main
git merge --ff-only ${{ env.BRANCH_NAME }}
- name: Attempt Push with Retry
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RETRY_MAX_TIME: 600
RETRY_INTERVAL: 10
run: |
gh pr create --base main --head ${{ env.BRANCH_NAME }} --title "Release ${{ env.BRANCH_NAME }} ff-merge" --body "Release ${{ env.BRANCH_NAME }} ff-merge"
START_TIME=$(date +%s)
while true; do
git push origin main && break
ELAPSED_TIME=$(( $(date +%s) - START_TIME ))
if [ "$ELAPSED_TIME" -ge $RETRY_MAX_TIME ]; then
echo "Push failed after $RETRY_MAX_TIME seconds. Exiting..."
exit 1
fi
echo "Push failed. Retrying in $RETRY_INTERVAL seconds..."
sleep $RETRY_INTERVAL
done
# Log failure:
- name: JReleaser release output
if: always()
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4
with:
name: jreleaser-release
path: |
out/jreleaser/trace.log
out/jreleaser/output.properties