-
Notifications
You must be signed in to change notification settings - Fork 1
199 lines (168 loc) · 6.5 KB
/
Copy pathrelease-artifacts.yml
File metadata and controls
199 lines (168 loc) · 6.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
name: Release Binaries and Images
run-name: 'Release run by ${{ github.actor }}'
on:
# Release unstable from HEAD on every merge
push:
branches:
- main
# Run manually to release unstable from HEAD
workflow_dispatch:
inputs:
protect_ref:
description: 'Commit/branch/tag'
default: ''
# Official stable versioned release
release:
types:
- published
permissions:
contents: read
jobs:
oci:
name: 'Build and publish ${{ matrix.component }} images'
if: ${{ github.repository_owner == 'edera-dev' && (github.event_name == 'release' || github.event.pull_request.head.repo.full_name == github.repository) }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
component:
- edera-check
permissions:
contents: read
id-token: write
packages: write
steps:
- name: 'Harden runner'
uses: step-security/harden-runner@bf7454d06d71f1098171f2acdf0cd4708d7b5920 # v2.20.0
with:
egress-policy: audit
- name: 'Checkout repository'
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v4.2.0
with:
submodules: recursive
persist-credentials: false
- name: 'Setup docker buildx'
uses: docker/setup-buildx-action@bb05f3f5519dd87d3ba754cc423b652a5edd6d2c # v4.2.0
with:
cache-binary: false
- name: 'Login to ghcr'
uses: docker/login-action@af1e73f918a031802d376d3c8bbc3fe56130a9b0 # v4.4.0
with:
registry: ghcr.io
username: '${{ github.actor }}'
password: '${{ github.token }}'
- name: Docker meta
uses: docker/metadata-action@dc802804100637a589fabce1cb79ff13a1411302 # v6.2.0
id: meta
with:
images: |
ghcr.io/edera-dev/${{ matrix.component }}
tags: |
# Tag with branch on push
type=ref,event=branch
# Tag with short sha on all events
type=sha,prefix=
# Tag version and stable on tag push
type=semver,pattern={{raw}}
type=semver,pattern={{version}}
type=semver,pattern={{major}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern=stable
# Tag nightly on schedule event
type=schedule,pattern=nightly
- name: 'Docker build and push ${{ matrix.component }}'
uses: docker/build-push-action@53b7df96c91f9c12dcc8a07bcb9ccacbed38856a # v7.3.0
id: push
with:
file: images/Containerfile.edera-check
platforms: "linux/amd64,linux/arm64"
tags: '${{ steps.meta.outputs.tags }}'
cache-from: type=gha
cache-to: type=gha,mode=max
push: true
- name: 'Install cosign'
uses: sigstore/cosign-installer@6f9f17788090df1f26f669e9d70d6ae9567deba6 # v4.1.2
- name: 'Cosign sign all images'
shell: bash
run: |
images=""
for tag in ${TAGS}; do
pullstring="${tag}@${DIGEST}"
echo "Signing ${pullstring}"
cosign sign --yes "${pullstring}"
done
env:
TAGS: '${{ steps.meta.outputs.tags }}'
DIGEST: '${{ steps.push.outputs.digest }}'
upload-artifact:
if: ${{ github.repository_owner == 'edera-dev' && (github.event_name == 'release' || github.event.pull_request.head.repo.full_name == github.repository) }}
name: Publish Binaries to Release
permissions:
contents: write
strategy:
fail-fast: false
matrix:
platform:
- { os: linux, arch: x86_64, libc: musl, static: true, on: ubuntu-latest }
- { os: linux, arch: aarch64, libc: musl, static: true, on: ubuntu-24.04-arm }
binary:
- edera-check
runs-on: '${{ matrix.platform.on }}'
steps:
- name: Harden the runner (Audit all outbound calls)
uses: step-security/harden-runner@bf7454d06d71f1098171f2acdf0cd4708d7b5920 # v2.20.0
with:
egress-policy: audit
- name: Checkout repository
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
fetch-depth: 0
persist-credentials: false
- name: 'Build and assemble ${{ matrix.binary }} ${{ matrix.platform.os }}-${{ matrix.platform.arch }}-${{ matrix.platform.libc }}'
run: |
set -e
# Build configuration
TARGET="${{ matrix.platform.arch }}-unknown-linux-${{ matrix.platform.libc }}"
rustup target add "$TARGET"
${{ matrix.platform.static == true && 'export RUSTFLAGS="-Ctarget-feature=+crt-static"' || '' }}
cargo build --release --target "$TARGET"
# Platform name
PLATFORM="${{ matrix.platform.os }}-${{ matrix.platform.arch }}-${{ matrix.platform.libc }}"
# Tag name
TAG="${{ github.event.release.tag_name }}"
[ -z "$TAG" ] && TAG="${{ github.event.repository.default_branch }}"
# Assemble asset
mkdir -p target/assets
BINARY="${{ matrix.binary }}"
OUTPUT_NAME="${BINARY}_${TAG}_${PLATFORM}"
cp "target/${TARGET}/release/${BINARY}" "target/assets/${OUTPUT_NAME}"
cd target/assets
if command -v sha256sum >/dev/null 2>&1; then
sha256sum "${OUTPUT_NAME}" > "${OUTPUT_NAME}.sha256"
else
shasum -a 256 "${OUTPUT_NAME}" > "${OUTPUT_NAME}.sha256"
fi
- name: 'Upload ${{ matrix.binary }} to workflow run'
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: ${{ matrix.binary }}-${{ matrix.platform.os }}-${{ matrix.platform.arch }}-${{ matrix.platform.libc }}
path: target/assets/${{ matrix.binary }}_*
- name: Generate cultivator token
uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
id: generate-token
with:
app-id: "${{ secrets.EDERA_CULTIVATION_APP_ID }}"
private-key: "${{ secrets.EDERA_CULTIVATION_APP_PRIVATE_KEY }}"
# Scope to what `gh release upload` needs: write release assets.
permission-contents: write
- name: 'Upload release artifacts with retry'
uses: nick-fields/retry@ad984534de44a9489a53aefd81eb77f87c70dc60 # v4.0.0
with:
timeout_minutes: 5
max_attempts: 10
retry_wait_seconds: 1
command: |
cd target/assets
gh release upload "${{ github.event.release.tag_name }}" --clobber ./*
env:
GITHUB_TOKEN: "${{ steps.generate-token.outputs.token }}"