Repository navigation
247 lines (226 loc) · 9.93 KB
/
Copy pathrelease.yaml
File metadata and controls
247 lines (226 loc) · 9.93 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
name: Release
# Publishes the chart to ghcr.io/appwrite/charts/appwrite when its version
# changes on main: OCI push, keyless cosign signature, build provenance
# attestation, GitHub release and Artifact Hub metadata.
#
# Every step checks before it acts, so a re-run finishes a release that
# failed half-way: the chart is pushed only if the registry says the version
# doesn't exist, and the signature, attestation and GitHub release are only
# created when they're missing.
on:
push:
branches: [main]
paths:
- charts/appwrite/Chart.yaml
workflow_dispatch:
permissions:
contents: read
concurrency:
group: release
cancel-in-progress: false
env:
REGISTRY: ghcr.io
REPOSITORY: ${{ github.repository_owner }}/charts
CHART: appwrite
COSIGN_VERSION: v3.1.3
ORAS_VERSION: 1.3.4
# The signer docs/security.md tells users to verify against.
CERT_IDENTITY: https://github.com/${{ github.repository }}/.github/workflows/release.yaml@refs/heads/main
CERT_OIDC_ISSUER: https://token.actions.githubusercontent.com
jobs:
release:
# Only main publishes (a manual run from another branch does nothing).
# Publishing signs the chart in the public Rekor log and needs public
# packages for attestations: only release once the repository is public.
if: ${{ github.ref == 'refs/heads/main' && !github.event.repository.private }}
runs-on: ubuntu-latest
permissions:
contents: write # GitHub release
packages: write # push to GHCR
id-token: write # keyless signing and attestations
attestations: write
steps:
- uses: step-security/harden-runner@e14015d583714f6e62063499dc959a02595150a1 # v2.21.1
with:
egress-policy: audit
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: azure/setup-helm@9bc31f4ebc9c6b171d7bfbaa5d006ae7abdb4310 # v5.0.1
with:
version: v4.3.0
- name: Read the chart version
id: chart
run: |
version=$(yq '.version' "charts/${CHART}/Chart.yaml")
echo "version=${version}" >> "$GITHUB_OUTPUT"
echo "ref=${REGISTRY}/${REPOSITORY}/${CHART}" >> "$GITHUB_OUTPUT"
- name: Release notes from CHANGELOG.md
env:
VERSION: ${{ steps.chart.outputs.version }}
run: |
awk -v v="$VERSION" '
index($0, "## [" v "]") == 1 {found=1; next}
found && /^## / {exit}
found {print}
' CHANGELOG.md > "${RUNNER_TEMP}/changelog.md"
if ! grep -q '[^[:space:]]' "${RUNNER_TEMP}/changelog.md"; then
echo "::error file=CHANGELOG.md::CHANGELOG.md has no entries under \"## [${VERSION}]\": rename [Unreleased] to [${VERSION}] before releasing (see RELEASING.md)."
exit 1
fi
cat "${RUNNER_TEMP}/changelog.md"
- name: Log in to GHCR
env:
GH_TOKEN: ${{ github.token }}
run: printf '%s' "$GH_TOKEN" | helm registry login "${REGISTRY}" -u "${GITHUB_ACTOR}" --password-stdin
- name: Look the version up in the registry
id: published
env:
GH_TOKEN: ${{ github.token }}
VERSION: ${{ steps.chart.outputs.version }}
run: |
# Only a 404 means "not published": any other answer fails the job
# rather than pushing the version again.
token=$(curl -fsS -u "${GITHUB_ACTOR}:${GH_TOKEN}" \
"https://${REGISTRY}/token?service=${REGISTRY}&scope=repository:${REPOSITORY}/${CHART}:pull" | jq -er .token)
status=$(curl -sS --head -o /dev/null -D "${RUNNER_TEMP}/headers" -w '%{http_code}' \
-H "Authorization: Bearer ${token}" \
-H 'Accept: application/vnd.oci.image.manifest.v1+json' \
"https://${REGISTRY}/v2/${REPOSITORY}/${CHART}/manifests/${VERSION}")
case "$status" in
200)
digest=$(tr -d '\r' < "${RUNNER_TEMP}/headers" | awk 'tolower($1) == "docker-content-digest:" {print $2}')
echo "Version ${VERSION} is already published (${digest}): finishing any missing steps."
echo "exists=true" >> "$GITHUB_OUTPUT"
echo "digest=${digest}" >> "$GITHUB_OUTPUT"
;;
404)
echo "Version ${VERSION} isn't published yet."
echo "exists=false" >> "$GITHUB_OUTPUT"
;;
*)
echo "::error::Unexpected HTTP ${status} looking up ${CHART}:${VERSION} in ${REGISTRY}."
exit 1
;;
esac
- name: Package and push
id: push
if: steps.published.outputs.exists == 'false'
env:
VERSION: ${{ steps.chart.outputs.version }}
run: |
helm package "charts/${CHART}" --destination dist
output=$(helm push "dist/${CHART}-${VERSION}.tgz" "oci://${REGISTRY}/${REPOSITORY}" 2>&1)
echo "$output"
digest=$(grep -oE 'sha256:[a-f0-9]{64}' <<<"$output" | head -1)
echo "digest=${digest}" >> "$GITHUB_OUTPUT"
- name: Resolve the digest
id: digest
env:
DIGEST: ${{ steps.push.outputs.digest || steps.published.outputs.digest }}
run: |
[[ "$DIGEST" =~ ^sha256:[a-f0-9]{64}$ ]] || { echo "::error::No chart digest (got '${DIGEST}')."; exit 1; }
echo "digest=${DIGEST}" >> "$GITHUB_OUTPUT"
- name: Pull the published chart
env:
REF: ${{ steps.chart.outputs.ref }}
VERSION: ${{ steps.chart.outputs.version }}
run: |
mkdir -p "${RUNNER_TEMP}/release"
helm pull "oci://${REF}" --version "${VERSION}" --destination "${RUNNER_TEMP}/release"
- uses: sigstore/cosign-installer@6f9f17788090df1f26f669e9d70d6ae9567deba6 # v4.1.2
with:
cosign-release: ${{ env.COSIGN_VERSION }}
- name: Sign with cosign (keyless) unless already signed
env:
GH_TOKEN: ${{ github.token }}
SUBJECT: ${{ steps.chart.outputs.ref }}@${{ steps.digest.outputs.digest }}
run: |
printf '%s' "$GH_TOKEN" | cosign login "${REGISTRY}" -u "${GITHUB_ACTOR}" --password-stdin
if cosign verify "$SUBJECT" --certificate-identity "$CERT_IDENTITY" \
--certificate-oidc-issuer "$CERT_OIDC_ISSUER" >/dev/null 2>&1; then
echo "Already signed by this workflow."
else
cosign sign --yes "$SUBJECT"
fi
- name: Verify the signature
env:
REF: ${{ steps.chart.outputs.ref }}
VERSION: ${{ steps.chart.outputs.version }}
# The same command docs/security.md gives users.
run: |
cosign verify "${REF}:${VERSION}" --certificate-identity "$CERT_IDENTITY" \
--certificate-oidc-issuer "$CERT_OIDC_ISSUER" >/dev/null
echo "Signature verified for ${CERT_IDENTITY}."
- name: Look for a provenance attestation
id: attested
env:
GH_TOKEN: ${{ github.token }}
SUBJECT: ${{ steps.chart.outputs.ref }}@${{ steps.digest.outputs.digest }}
run: |
if gh attestation verify "oci://${SUBJECT}" --repo "$GITHUB_REPOSITORY" >/dev/null 2>&1; then
echo "Already attested."
echo "exists=true" >> "$GITHUB_OUTPUT"
else
echo "exists=false" >> "$GITHUB_OUTPUT"
fi
- name: Attest build provenance
if: steps.attested.outputs.exists != 'true'
uses: actions/attest-build-provenance@4d101475d8b20a2381f78447822ac1eab6504dd8 # v4.2.2
with:
subject-name: ${{ steps.chart.outputs.ref }}
subject-digest: ${{ steps.digest.outputs.digest }}
push-to-registry: true
- name: Verify the attestation
env:
GH_TOKEN: ${{ github.token }}
REF: ${{ steps.chart.outputs.ref }}
VERSION: ${{ steps.chart.outputs.version }}
run: gh attestation verify "oci://${REF}:${VERSION}" --repo "$GITHUB_REPOSITORY"
- name: Create the GitHub release unless it exists
env:
GH_TOKEN: ${{ github.token }}
REF: ${{ steps.chart.outputs.ref }}
VERSION: ${{ steps.chart.outputs.version }}
DIGEST: ${{ steps.digest.outputs.digest }}
run: |
tag="${CHART}-${VERSION}"
asset="${RUNNER_TEMP}/release/${CHART}-${VERSION}.tgz"
if out=$(gh release view "$tag" --json tagName 2>&1); then
echo "Release ${tag} exists; making sure it has the chart archive."
gh release upload "$tag" "$asset" --clobber
exit 0
elif [[ "$out" != *"release not found"* ]]; then
echo "$out"
exit 1
fi
{
cat "${RUNNER_TEMP}/changelog.md"
echo
echo "## Install"
echo
echo '```console'
echo "helm install appwrite oci://${REF} --version ${VERSION}"
echo '```'
echo
echo "Digest: \`${DIGEST}\`"
} > "${RUNNER_TEMP}/notes.md"
flags=()
# Pre-1.0 and pre-release versions are marked as pre-releases.
if [[ "$VERSION" == 0.* || "$VERSION" == *-* ]]; then
flags+=(--prerelease)
fi
gh release create "$tag" "$asset" --target "$GITHUB_SHA" \
--title "${CHART} ${VERSION}" --notes-file "${RUNNER_TEMP}/notes.md" "${flags[@]}"
- uses: oras-project/setup-oras@005458ad77f1c8facd38a094e4af2e69e5607ff4 # v2.0.2
with:
version: ${{ env.ORAS_VERSION }}
- name: Publish Artifact Hub metadata
env:
GH_TOKEN: ${{ github.token }}
REF: ${{ steps.chart.outputs.ref }}
run: |
printf '%s' "$GH_TOKEN" | oras login "${REGISTRY}" -u "${GITHUB_ACTOR}" --password-stdin
oras push "${REF}:artifacthub.io" \
--config /dev/null:application/vnd.cncf.artifacthub.config.v1+yaml \
artifacthub-repo.yml:application/vnd.cncf.artifacthub.repository-metadata.layer.v1.yaml