Repository navigation
239 lines (216 loc) · 9.33 KB
/
Copy pathrelease-please.yml
File metadata and controls
239 lines (216 loc) · 9.33 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
name: Release Please
# Two ways in:
#
# push to main Release Please collects commits into a release PR.
# Merging that PR tags the version and publishes it.
#
# workflow_dispatch Re-publish a release that was already tagged. Needed
# when publishing failed after the tag was created, which
# otherwise leaves a release stranded with no way back,
# for example when Hangar rejects a platform version.
"on":
push:
branches:
- main
workflow_dispatch:
inputs:
tag:
description: "Release tag to publish, e.g. v1.2.0"
required: true
type: string
ref:
description: "Git ref to build from. Defaults to the tag itself. Point this at main when the tagged commit is what broke publishing."
required: false
type: string
permissions:
contents: read
jobs:
release-please:
name: Release Please
if: github.event_name == 'push'
runs-on: ubuntu-latest
permissions:
contents: write # to create the tag and the GitHub release
pull-requests: write # to open and update the release PR
outputs:
release_created: ${{ steps.release.outputs.release_created }}
tag_name: ${{ steps.release.outputs.tag_name }}
version: ${{ steps.release.outputs.version }}
steps:
# GITHUB_TOKEN-opened release PRs leave their checks in "action_required"
# until GitHub fails them after 30 days; the release bot app avoids that.
- name: Create release bot token
id: app-token
uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510 # v3.3.0
with:
client-id: ${{ secrets.RELEASE_PLEASE_APP_CLIENT_ID }}
private-key: ${{ secrets.RELEASE_PLEASE_APP_PRIVATE_KEY }}
permission-contents: write
permission-pull-requests: write
- name: Release Please
id: release
uses: googleapis/release-please-action@45996ed1f6d02564a971a2fa1b5860e934307cf7 # v5.0.0
with:
token: ${{ steps.app-token.outputs.token }}
config-file: release-please-config.json
manifest-file: .release-please-manifest.json
# Builds, publishes nothing. Everything public waits behind security-gate.
build:
name: Build Release Artifacts
needs: release-please
# always() because release-please is skipped on workflow_dispatch, and a
# skipped dependency would otherwise skip this job too.
if: >-
always() &&
(needs.release-please.outputs.release_created == 'true' ||
github.event_name == 'workflow_dispatch')
runs-on: ubuntu-latest
permissions:
contents: read
outputs:
version: ${{ steps.resolve.outputs.version }}
ref: ${{ steps.resolve.outputs.ref }}
env:
TAG_NAME: ${{ github.event_name == 'workflow_dispatch' && inputs.tag || needs.release-please.outputs.tag_name }}
BUILD_REF: ${{ github.event_name == 'workflow_dispatch' && (inputs.ref || inputs.tag) || needs.release-please.outputs.tag_name }}
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.event_name == 'workflow_dispatch' && (inputs.ref || inputs.tag) || needs.release-please.outputs.tag_name }}
- name: Resolve version
id: resolve
run: |
version="${TAG_NAME#v}"
declared="$(sed -n 's/^version = "\([^"]*\)".*/\1/p' build.gradle.kts)"
if [ "$version" != "$declared" ]; then
echo "::error::Tag $TAG_NAME expects version $version, but build.gradle.kts declares $declared. Refusing to publish mismatched artifacts."
exit 1
fi
echo "version=$version" >> "$GITHUB_OUTPUT"
echo "ref=$BUILD_REF" >> "$GITHUB_OUTPUT"
- name: Validate Gradle Wrapper
uses: gradle/actions/wrapper-validation@3f5f9adaf7d9fecd50b5935e54106014257a94e6 # v6.4.0
- name: Setup Java
uses: actions/setup-java@de7274f081f381c8f8158605e0321c36c376e2e6 # v6.0.1
with:
distribution: temurin
java-version: 25
- name: Setup Gradle
uses: gradle/actions/setup-gradle@3f5f9adaf7d9fecd50b5935e54106014257a94e6 # v6.4.0
- name: Build
run: ./gradlew check shadowJar cyclonedxBom
- name: Upload plugin JAR
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: plugin-jar
path: |
build/libs/BetterGoPaint-*.jar
!build/libs/*-unshaded.jar
if-no-files-found: error
retention-days: 14
- name: Upload SBOM artifact
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: sbom
path: build/reports/cyclonedx/bom.xml
if-no-files-found: error
retention-days: 14
- name: Upload build reports
if: always()
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: publish-reports
path: build/reports/**
if-no-files-found: ignore
retention-days: 14
# The point of no return. Everything below this job is public, so a HIGH or
# CRITICAL finding in the jar we are about to ship stops the release here.
# Scans the built artifact, not the source tree: for a shaded jar that is the
# only target that sees what actually ships.
security-gate:
name: Security Gate
needs: build
permissions:
contents: read
security-events: write # SARIF upload to code scanning
uses: OneLiteFeatherNET/workflows/.github/workflows/security-scan.yml@ec5d37fed94ad59e54868d63af6ea4ef4ee4e84c # v2.9.0
with:
scan-type: rootfs
artifact-name: plugin-jar
severity: "CRITICAL,HIGH"
fail-on-findings: true
secrets: inherit
publish:
name: Publish Release
needs: [release-please, build, security-gate]
# No always() here - a failed gate must stop the release, and always()
# would run this job anyway.
if: >-
!cancelled() &&
needs.security-gate.result == 'success' &&
(needs.release-please.outputs.release_created == 'true' ||
github.event_name == 'workflow_dispatch')
runs-on: ubuntu-latest
permissions:
contents: write # to upload assets to the GitHub release
env:
TAG_NAME: ${{ github.event_name == 'workflow_dispatch' && inputs.tag || needs.release-please.outputs.tag_name }}
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ needs.build.outputs.ref }}
- name: Download plugin JAR
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: plugin-jar
path: build/libs
# Deliberately before the platform uploads. Hangar and Modrinth reject
# versions for reasons outside this repository's control; when that
# happens the artifact should still be attached to the GitHub release
# rather than lost with the failed run.
- name: Upload JAR to GitHub Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: gh release upload "$TAG_NAME" build/libs/BetterGoPaint-*.jar --clobber
- name: Setup Java
uses: actions/setup-java@de7274f081f381c8f8158605e0321c36c376e2e6 # v6.0.1
with:
distribution: temurin
java-version: 25
- name: Setup Gradle
uses: gradle/actions/setup-gradle@3f5f9adaf7d9fecd50b5935e54106014257a94e6 # v6.4.0
- name: Publish to Hangar and Modrinth
env:
HANGAR_SECRET: ${{ secrets.HANGAR_KEY }}
MODRINTH_TOKEN: ${{ secrets.MODRINTH_KEY }}
run: ./gradlew publishAllPublicationsToHangar modrinth
# The store page (docs/store-page.md) is a description, not the release itself. The jar is already
# live at this point, so a rejected description must not fail the run: continue-on-error keeps the
# job green, and --continue lets the Modrinth sync run even if the Hangar sync failed. The step only
# runs after a successful publish (the default if:), so it never runs against a half-published release.
- name: Sync store page to Hangar and Modrinth
continue-on-error: true
env:
HANGAR_SECRET: ${{ secrets.HANGAR_KEY }}
MODRINTH_TOKEN: ${{ secrets.MODRINTH_KEY }}
run: ./gradlew --continue syncAllPagesToHangar modrinthSyncBody
# Separate job so Dependency-Track being down, or rejecting the API key,
# cannot take the release with it. With the SBOM upload inside the publish
# job, one rejected platform version would cost the JAR, both
# platform releases and the SBOM at once.
sbom:
name: Publish SBOM
needs: [build, publish]
uses: OneLiteFeatherNET/workflows/.github/workflows/sbom-publish.yml@ec5d37fed94ad59e54868d63af6ea4ef4ee4e84c # v2.9.0
with:
project-name: "BetterGoPaint"
project-version: ${{ needs.build.outputs.version }}
project-tags: "bukkit,paper,plugin"
parent-uuid: "682857a9-0cd2-4ffd-a2b3-098eeba5ab74"
# The CycloneDX Gradle plugin resolves the dependency graph better than
# an external scanner, so hand it the artifact the build produced.
artifact-name: "sbom"
sbom-path: "bom.xml"
secrets: inherit