-
-
Notifications
You must be signed in to change notification settings - Fork 1
212 lines (201 loc) · 8.19 KB
/
deploy_to_maven_central.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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# Source: https://docs.github.com/en/actions/publishing-packages/publishing-java-packages-with-maven
name: Deploy to Maven Central
on:
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
# One can look up a project's profileId by running:
# mvn nexus-staging:rc-list-profiles -DserverId=maven-central-releases -DnexusUrl=https://oss.sonatype.org/
STAGING_PROFILE_ID: "3799bb102c7f24"
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
OSSRH_TOKEN: ${{ secrets.OSSRH_TOKEN }}
MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }}
jobs:
open-release:
runs-on: ubuntu-latest
outputs:
INITIAL_REF_POSITION: ${{ steps.open-staging.outputs.INITIAL_REF_POSITION }}
TAG: ${{ steps.open-staging.outputs.TAG }}
STAGING_REPOSITORY_ID: ${{ steps.open-staging.outputs.STAGING_REPOSITORY_ID }}
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.ref }}
fetch-depth: 0
- uses: actions/setup-java@v3
with:
distribution: zulu
java-version: |
8
17
server-id: maven-central-releases
# Server authentication corresponds to "user token" returned by https://oss.sonatype.org/
server-username: OSSRH_USERNAME
server-password: OSSRH_TOKEN
gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }}
gpg-passphrase: MAVEN_GPG_PASSPHRASE
- name: Cache Dependencies
uses: actions/cache@v3
with:
# Avoid caching generated artifacts
path: |
~/.m2/repository/*
!~/.m2/repository/com/github/cowwoc/pouch
key: ${{ runner.OS }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.OS }}-maven-
- name: Configure Git User
run: |
git config user.email "[email protected]"
git config user.name "Gili Tzabari"
# Maven command-line options:
# --batch-mode: recommended in CI to inform maven to not run in interactive mode (less logs)
# -V: strongly recommended in CI, will display the JDK and Maven versions in use.
# Very useful to be quickly sure the selected versions were the ones you think.
# -e: Display stack-traces on failure
#
# Getting the current git tag: https://stackoverflow.com/a/50465671/14731
#
# Setting a GitHub Action output parameter:
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-output-parameter
#
# "release:prepare" must skip integration tests because "binaries-on-path-test" requires artifacts
# to be deployed to local repository.
- name: Open staging repository
id: open-staging
run: |
echo "INITIAL_REF_POSITION=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
./mvnw release:prepare --batch-mode -V -e -Darguments="-Ddeploy -Dinvoker.skip=true"
echo "TAG=$(git describe --tag --abbrev=0)" >> $GITHUB_OUTPUT
output=$(./mvnw --batch-mode -e -DstagingProfileId=${{ env.STAGING_PROFILE_ID }} nexus-staging:rc-open)
echo "output: ${output}"
[[ "$output" =~ Opened\ (comgithubcowwoc-[[:digit:]]+) ]]
stagingRepositoryId="${BASH_REMATCH[1]}"
echo "STAGING_REPOSITORY_ID=$stagingRepositoryId" >> $GITHUB_OUTPUT
deploy:
needs: open-release
runs-on: ubuntu-latest
steps:
- uses: ac tions/checkout@v3
with:
ref: ${{ needs.open-release.outputs.TAG }}
- uses: actions/setup-java@v3
with:
distribution: zulu
java-version: |
8
17
server-id: maven-central-releases
# Server authentication corresponds to "user token" returned by https://oss.sonatype.org/
server-username: OSSRH_USERNAME
server-password: OSSRH_TOKEN
gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }}
gpg-passphrase: MAVEN_GPG_PASSPHRASE
- name: Cache Dependencies
uses: actions/cache@v3
with:
# Avoid caching generated artifacts
path: |
~/.m2/repository/*
!~/.m2/repository/com/github/cowwoc/pouch
key: ${{ runner.OS }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.OS }}-maven-
- name: Deploy to Maven Central
run: >
./mvnw --batch-mode -V -e -Ddeploy -DstagingProfileId=${{ env.STAGING_PROFILE_ID }}
-DstagingRepositoryId=${{ needs.open-release.outputs.STAGING_REPOSITORY_ID }}
deploy
close-release:
needs: [ open-release, deploy ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ needs.open-release.outputs.TAG }}
- uses: actions/setup-java@v3
with:
distribution: zulu
java-version: |
8
17
server-id: maven-central-releases
# Server authentication corresponds to "user token" returned by https://oss.sonatype.org/
server-username: OSSRH_USERNAME
server-password: OSSRH_TOKEN
gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }}
gpg-passphrase: MAVEN_GPG_PASSPHRASE
- name: Cache Dependencies
uses: actions/cache@v3
with:
# Avoid caching generated artifacts
path: |
~/.m2/repository/*
!~/.m2/repository/com/github/cowwoc/pouch
key: ${{ runner.OS }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.OS }}-maven-
- name: Close staging repository
run: >
./mvnw --batch-mode -V -e -DstagingProfileId=${{ env.STAGING_PROFILE_ID }}
-DstagingRepositoryId=${{ needs.open-release.outputs.STAGING_REPOSITORY_ID }}
nexus-staging:rc-close
# Cleanup on failure: https://stackoverflow.com/a/74562058/14731
on-failure:
needs: [ open-release, deploy, close-release ]
runs-on: ubuntu-latest
if: ${{ always() && contains(needs.*.result, 'failure') }}
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.ref }}
fetch-depth: 0
- uses: actions/setup-java@v3
with:
distribution: zulu
java-version: |
8
17
server-id: maven-central-releases
# Server authentication corresponds to "user token" returned by https://oss.sonatype.org/
server-username: OSSRH_USERNAME
server-password: OSSRH_TOKEN
gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }}
gpg-passphrase: MAVEN_GPG_PASSPHRASE
- name: Cache Dependencies
uses: actions/cache@v3
with:
# Avoid caching generated artifacts
path: |
~/.m2/repository/*
!~/.m2/repository/com/github/cowwoc/pouch
key: ${{ runner.OS }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.OS }}-maven-
- name: Configure Git User
run: |
git config user.email "[email protected]"
git config user.name "Gili Tzabari"
- name: Restore the workflow ref to its original position
if: needs.open-release.outputs.INITIAL_REF_POSITION != ''
run: |
CURRENT_REF_POSITION=$(git rev-parse HEAD)
if [ "${CURRENT_REF_POSITION}" != "${{ needs.open-release.outputs.INITIAL_REF_POSITION }}" ]; then
git reset --hard ${{ needs.open-release.outputs.INITIAL_REF_POSITION }}
if [ "${{ github.ref_type }}" == "tag" ]; then
git ${{ github.ref_type }} -f ${{ github.ref_name }}
fi
git push -f origin ${{ github.ref_name }}
fi
- name: Delete tag
if: needs.open-release.outputs.TAG != ''
run: |
git push --delete origin ${{ needs.open-release.outputs.TAG }}
- name: Drop staging repository
if: needs.open-release.outputs.STAGING_REPOSITORY_ID != ''
run: >
./mvnw --batch-mode -V -e -DstagingProfileId=${{ env.STAGING_PROFILE_ID }}
-DstagingRepositoryId=${{ needs.open-release.outputs.STAGING_REPOSITORY_ID }}
nexus-staging:rc-drop