-
Notifications
You must be signed in to change notification settings - Fork 41
291 lines (273 loc) · 10.5 KB
/
publish-release.yml
File metadata and controls
291 lines (273 loc) · 10.5 KB
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
name: Publish Release
on:
workflow_run:
workflows: [Build Release]
types:
- completed
branches:
- '**'
- '!main'
- '!dependabot/**'
permissions:
contents: read # to fetch code (actions/checkout)
env:
LANG: 'en_US.UTF-8'
jobs:
check-version:
# only run in the official pmd/pmd-eclipse-plugin repo, where we have access to the secrets and not on forks
# and only run for _successful_ push workflow runs on tags.
if: ${{ github.repository == 'pmd/pmd-eclipse-plugin'
&& contains(fromJSON('["push", "workflow_dispatch"]'), github.event.workflow_run.event)
&& github.event.workflow_run.head_branch != 'main'
&& github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-latest
timeout-minutes: 10
defaults:
run:
shell: bash
outputs:
VERSION: ${{ steps.version.outputs.VERSION }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.workflow_run.head_branch }}
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '21'
- name: Cache local Maven repository
uses: actions/cache@v4
with:
path: |
~/.m2/repository
net.sourceforge.pmd.eclipse.plugin/japicmp-data
# re-cache on changes in the pom and target files
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml', '**/*.target') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Determine Version
id: version
env:
REF: ${{ github.event.workflow_run.head_branch }}
run: |
if ! git show-ref --exists "refs/tags/$REF"; then
echo "::error ::Tag $REF does not exist, aborting."
exit 1
fi
VERSION=$(./mvnw --batch-mode --no-transfer-progress help:evaluate -Dexpression=project.version -q -DforceStdout)
echo "Determined VERSION=$VERSION"
if [[ "$VERSION" = *-SNAPSHOT ]]; then
echo "::error ::VERSION=$VERSION is a snapshot version, aborting."
exit 1
fi
echo "VERSION=$VERSION" >> "$GITHUB_OUTPUT"
- name: Add Job Summary
env:
WORKFLOW_RUN_DISPLAY_TITLE: ${{ github.event.workflow_run.display_title }}
WORKFLOW_RUN_NAME: ${{ github.event.workflow_run.name }}
WORKFLOW_RUN_NUMBER: ${{ github.event.workflow_run.run_number }}
WORKFLOW_RUN_HTML_URL: ${{ github.event.workflow_run.html_url }}
VERSION: ${{ steps.version.outputs.VERSION }}
TAG: ${{ github.event.workflow_run.head_branch }}
run: |
echo "### Run Info" >> "${GITHUB_STEP_SUMMARY}"
echo "Building Version: ${VERSION}" >> "${GITHUB_STEP_SUMMARY}"
echo "" >> "${GITHUB_STEP_SUMMARY}"
echo "Tag: ${TAG}" >> "${GITHUB_STEP_SUMMARY}"
echo "" >> "${GITHUB_STEP_SUMMARY}"
echo "Called by [${WORKFLOW_RUN_DISPLAY_TITLE} (${WORKFLOW_RUN_NAME} #${WORKFLOW_RUN_NUMBER})](${WORKFLOW_RUN_HTML_URL})" >> "${GITHUB_STEP_SUMMARY}"
echo "" >> "${GITHUB_STEP_SUMMARY}"
create-signed-update-site:
needs: check-version
runs-on: ubuntu-latest
timeout-minutes: 30
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.workflow_run.head_branch }}
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: '21'
gpg-private-key: ${{ secrets.PMD_CI_GPG_PRIVATE_KEY }}
- name: Cache local Maven repository
uses: actions/cache@v4
with:
path: |
~/.m2/repository
net.sourceforge.pmd.eclipse.plugin/japicmp-data
# re-cache on changes in the pom and target files
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml', '**/*.target') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Build
env:
MAVEN_GPG_PASSPHRASE: ${{ secrets.PMD_CI_GPG_PASSPHRASE }}
run: |
./mvnw --show-version --errors --batch-mode \
verify \
-Psign -DskipTests
- name: Upload update-site
uses: actions/upload-artifact@v4
with:
name: update-site
path: net.sourceforge.pmd.eclipse.p2updatesite/target/net.sourceforge.pmd.eclipse.p2updatesite-*.zip
create-release:
needs: [check-version, create-signed-update-site]
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: write # to create a release (via gh cli)
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.workflow_run.head_branch }}
- uses: actions/download-artifact@v4
with:
name: update-site
- name: Prepare Release Notes
run: .ci/files/prepare_release_notes.sh
- name: Create Release
env:
# Token required for GH CLI:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAG_NAME: ${{ github.event.workflow_run.head_branch }}
VERSION: ${{ needs.check-version.outputs.VERSION }}
run: |
RELEASE_NAME="PMD For Eclipse ${VERSION}"
gh release create "$TAG_NAME" "net.sourceforge.pmd.eclipse.p2updatesite-${VERSION}.zip" \
--verify-tag \
--notes-file release_notes_prepared.md \
--title "$RELEASE_NAME"
deploy-to-sourceforge-files:
needs: [check-version, create-signed-update-site]
# use environment sourceforge, where secrets/vars are configured for PMD_WEB_SOURCEFORGE_NET_DEPLOY_KEY
# and PMD_WEB_SOURCEFORGE_NET_KNOWN_HOSTS
environment:
name: sourceforge
url: https://sourceforge.net/projects/pmd/files/pmd-eclipse/zipped/
runs-on: ubuntu-latest
timeout-minutes: 10
defaults:
run:
shell: bash
steps:
- uses: actions/download-artifact@v4
with:
name: update-site
- name: Setup ssh key for sourceforge
env:
WEB_SF_DEPLOY_KEY: ${{ secrets.PMD_WEB_SOURCEFORGE_NET_DEPLOY_KEY }}
WEB_SF_KNOWN_HOSTS: ${{ vars.PMD_WEB_SOURCEFORGE_NET_KNOWN_HOSTS }}
run: |
mkdir -p "${HOME}/.ssh"
chmod 700 "${HOME}/.ssh"
printenv WEB_SF_DEPLOY_KEY > "${HOME}/.ssh/web.sourceforge.net_deploy_key"
chmod 600 "${HOME}/.ssh/web.sourceforge.net_deploy_key"
echo "
Host web.sourceforge.net
IdentityFile=$HOME/.ssh/web.sourceforge.net_deploy_key
" > "$HOME/.ssh/config"
echo "${WEB_SF_KNOWN_HOSTS}" > "$HOME/.ssh/known_hosts"
- name: Upload to sourceforge
id: upload
env:
VERSION: ${{ needs.check-version.outputs.VERSION }}
PMD_SF_USER: adangel
run: |
uploadUrl="${PMD_SF_USER}@web.sourceforge.net:/home/frs/project/pmd/pmd-eclipse/zipped/"
rsync -avh \
"net.sourceforge.pmd.eclipse.p2updatesite-${VERSION}.zip" \
"${uploadUrl}/net.sourceforge.pmd.eclipse.p2updatesite-${VERSION}.zip"
- name: Cleanup ssh
if: ${{ always() }}
run: |
rm -rf "${HOME}/.ssh"
deploy-to-pmd-eclipse-plugin-p2-site:
needs: [check-version, create-signed-update-site]
environment:
name: github-pages
url: https://pmd.github.io/pmd-eclipse-plugin-p2-site/
runs-on: ubuntu-latest
timeout-minutes: 10
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.workflow_run.head_branch }}
- uses: actions/download-artifact@v4
with:
name: update-site
- uses: actions/create-github-app-token@v2
id: pmd-actions-helper-app-token
with:
app-id: ${{ secrets.PMD_ACTIONS_HELPER_ID }}
private-key: ${{ secrets.PMD_ACTIONS_HELPER_PRIVATE_KEY }}
owner: pmd
repositories: pmd-eclipse-plugin-p2-site
permission-contents: write
- name: Prepare Local P2 Repository
uses: actions/checkout@v4
with:
repository: pmd/pmd-eclipse-plugin-p2-site
ref: gh-pages
path: current-p2-site
token: ${{ steps.pmd-actions-helper-app-token.outputs.token }}
- name: Update Local P2 Repository
env:
VERSION: ${{ needs.check-version.outputs.VERSION }}
run: |
cd current-p2-site
# https://api.github.com/users/pmd-actions-helper[bot]
git config user.name "pmd-actions-helper[bot]"
git config user.email "207160486+pmd-actions-helper[bot]@users.noreply.github.com"
unzip -q -d "${VERSION}" "../net.sourceforge.pmd.eclipse.p2updatesite-${VERSION}.zip"
git add "${VERSION}"
../.ci/files/regenerate_metadata.sh
# create a new single commit
git checkout --orphan=gh-pages-2
git commit -a -m "Update pmd/pmd-eclipse-plugin-p2-site"
git push --force origin gh-pages-2:gh-pages
create-sourceforge-blog-post:
needs: [check-version, create-signed-update-site]
# use environment sourceforge, where secrets/vars are configured for PMD_SF_BEARER_TOKEN
environment:
name: sourceforge
url: ${{ steps.upload.outputs.url_output }}
runs-on: ubuntu-latest
timeout-minutes: 10
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.workflow_run.head_branch }}
- name: Prepare Release Notes
run: .ci/files/prepare_release_notes.sh
- name: Create Blog Post
id: upload
env:
TAG_NAME: ${{ github.event.workflow_run.head_branch }}
VERSION: ${{ needs.check-version.outputs.VERSION }}
PMD_SF_BEARER_TOKEN: ${{ secrets.PMD_SF_BEARER_TOKEN }}
run: |
RELEASE_NAME="PMD For Eclipse ${VERSION}"
# See https://sourceforge.net/p/forge/documentation/Allura%20API/
url_output=$(curl --silent --include --request POST \
--header "Authorization: Bearer ${PMD_SF_BEARER_TOKEN}" \
--form "labels=pmd-eclipse-plugin,release" \
--form "state=published" \
--form "text=<release_notes_prepared.md" \
--form "title=${RELEASE_NAME}" \
https://sourceforge.net/rest/p/pmd/news | grep -i "location: "|cut -d " " -f 2|tr -d "\r\n")
echo "url_output=${url_output}" >> "$GITHUB_OUTPUT"