Repository navigation
163 lines (146 loc) · 6.35 KB
/
Copy pathrelease.yml
File metadata and controls
163 lines (146 loc) · 6.35 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
name: Release
on:
push:
tags:
- "v*.*.*"
workflow_dispatch:
permissions:
contents: write
packages: write
jobs:
release:
name: Scan, sign off and publish
runs-on: ubuntu-26.04
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
- name: Verify the tag is on main
run: |
git fetch --no-tags origin main:refs/remotes/origin/main
if ! git merge-base --is-ancestor "$GITHUB_SHA" origin/main; then
echo "::error::Tag $GITHUB_REF_NAME points at a commit that is not on main."
exit 1
fi
echo "Tag is on main: $GITHUB_SHA"
- name: Set up JDK 21
uses: actions/setup-java@d1374f8ac74474200d16ef8ecee22c7ae7a51880 # v6
with:
distribution: temurin
java-version: "21"
cache: maven
- name: Build jar and SBOM
run: ./mvnw -B -DskipTests package
# --- supply chain: checksums -------------------------------------------
- name: Collect SBOM
run: cp path-gateway/target/classes/META-INF/sbom/application.cdx.json path-gateway/target/bom.json
- name: Write SHA-256 checksums
run: |
cd path-gateway/target
sha256sum path-*.jar bom.json | sort -k2 > checksums.txt
ls -l path-*.jar bom.json checksums.txt
cat checksums.txt
- name: Verify the checksums we just wrote
run: cd path-gateway/target && sha256sum -c checksums.txt
# --- container: build, scan, push --------------------------------------
- name: Set up QEMU
uses: docker/setup-qemu-action@99012661954931238ded8c8b007157a8430204e1 # v4
- name: Set up Buildx
uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4
- name: Log in to GHCR
uses: docker/login-action@8aa5831fb8d48d8f76594c7ddde61ae58019f550 # v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# Only an unversioned sha- tag is pushed before the scan. A failed scan then leaves
# nothing a deployment could pull by version, and the version number stays unused for
# the retry. The version tag and latest are created after the gate, by promoting this
# exact digest instead of rebuilding.
- name: Build and push the candidate image
id: image
uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7
with:
context: .
push: true
platforms: linux/amd64,linux/arm64
tags: |
ghcr.io/${{ github.repository }}:sha-${{ github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Scan the published image
uses: aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25 # v0.36.0
env:
TRIVY_USERNAME: ${{ github.actor }}
TRIVY_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
with:
image-ref: ghcr.io/${{ github.repository }}:sha-${{ github.sha }}
# CRITICAL blocks the release; HIGH is visible in the scan output but the
# Debian base image rotates packages too often to gate on it.
#
# trivy-action's input is `trivyignores` (plural, comma-separated), not the
# CLI's `--ignorefile`; passing the wrong name is only a warning, so the scan
# silently ran without the exceptions. The YAML form is not auto-detected, so
# it has to be named explicitly.
trivyignores: .trivyignore.yaml
severity: CRITICAL
exit-code: "1"
ignore-unfixed: true
# The scan passed, so the same digest can carry the version. imagetools copies the
# multi-arch manifest; nothing is rebuilt and the digest recorded below is the one
# Trivy scanned.
- name: Promote the scanned digest to the version and latest
run: |
docker buildx imagetools create \
-t "ghcr.io/${{ github.repository }}:${{ github.ref_name }}" \
-t "ghcr.io/${{ github.repository }}:latest" \
"ghcr.io/${{ github.repository }}:sha-${{ github.sha }}"
- name: Record the image digest
run: |
digest="$(docker buildx imagetools inspect \
--format '{{.Manifest.Digest}}' \
"ghcr.io/${{ github.repository }}:${{ github.ref_name }}")"
echo "### Container digest" >> "$GITHUB_STEP_SUMMARY"
echo '```' >> "$GITHUB_STEP_SUMMARY"
echo "ghcr.io/${{ github.repository }}@${digest}" >> "$GITHUB_STEP_SUMMARY"
echo '```' >> "$GITHUB_STEP_SUMMARY"
echo "Also kept for traceability: ghcr.io/${{ github.repository }}:sha-${{ github.sha }}"
# --- Maven Central (optional) -------------------------------------------
- name: Publish to Maven Central
if: vars.PUBLISH_TO_CENTRAL == 'true'
env:
MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }}
CENTRAL_USERNAME: ${{ secrets.CENTRAL_USERNAME }}
CENTRAL_PASSWORD: ${{ secrets.CENTRAL_PASSWORD }}
run: |
mkdir -p ~/.gnupg && chmod 700 ~/.gnupg
printf '%s' "${{ secrets.MAVEN_GPG_PRIVATE_KEY }}" | gpg --batch --import
mkdir -p ~/.m2
cat > ~/.m2/settings.xml <<XML
<settings>
<servers>
<server>
<id>central</id>
<username>${CENTRAL_USERNAME}</username>
<password>${CENTRAL_PASSWORD}</password>
</server>
</servers>
</settings>
XML
./mvnw -B -P release -DskipTests deploy
# --- publish -----------------------------------------------------------
- name: Extract release notes from CHANGELOG.md
run: |
python3 tools/changelog.py "${GITHUB_REF_NAME}" > /tmp/release-notes.md
test -s /tmp/release-notes.md
cat /tmp/release-notes.md
- name: Create GitHub release
uses: softprops/action-gh-release@8a0cd651e5b2365bd640854a3fa5dfc70e4875f3 # v3
with:
name: ${{ github.ref_name }}
body_path: /tmp/release-notes.md
files: |
path-gateway/target/path-*.jar
path-gateway/target/bom.json
path-gateway/target/checksums.txt
fail_on_unmatched_files: true