-
Notifications
You must be signed in to change notification settings - Fork 0
213 lines (196 loc) · 6.94 KB
/
build.yml
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
---
name: Build
on:
release:
types: [published]
permissions:
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.ref_name }}
cancel-in-progress: true
jobs:
build-release-archive:
permissions:
contents: write
strategy:
fail-fast: false
matrix:
include:
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
- target: aarch64-unknown-linux-gnu
os: ubuntu-latest
- target: x86_64-unknown-linux-musl
os: ubuntu-latest
- target: aarch64-unknown-linux-musl
os: ubuntu-latest
- target: x86_64-apple-darwin
os: macos-latest
- target: aarch64-apple-darwin
os: macos-latest
- target: x86_64-pc-windows-msvc
os: windows-latest
runs-on: ${{ matrix.os }}
env:
ARCHIVE_FILENAME: >-
hanko-${{ github.ref_name }}-${{ matrix.target }}.${{ startsWith(matrix.os, 'windows') && 'zip' || 'tar.gz' }}
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- uses: dtolnay/rust-toolchain@7b1c307e0dcbda6122208f10795a713336a9b35a
with:
toolchain: stable
targets: "${{ matrix.target }}"
- uses: Swatinem/rust-cache@82a92a6e8fbeee089604da2575dc567ae9ddeaab
- uses: extractions/setup-just@dd310ad5a97d8e7b41793f8ef055398d51ad4de6
- name: Install GCC for aarch64
run: |
sudo apt install -y gcc-aarch64-linux-gnu
echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc" >> $GITHUB_ENV
echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER=aarch64-linux-gnu-gcc" >> $GITHUB_ENV
if: ${{ contains(matrix.target, 'aarch64') && contains(matrix.target, 'linux') }}
- name: Install musl tools
run: sudo apt install -y musl-tools
if: ${{ contains(matrix.target, 'musl') && contains(matrix.target, 'linux') }}
- name: Print versions
shell: bash
run: |
gcc --version || true
rustup -V
rustup toolchain list
rustup default
cargo -V
rustc -V
- name: Create Release Archive
run: just release-archive ${{ matrix.target }} ${{ env.ARCHIVE_FILENAME }}
- name: Upload Release Archive
run: >-
gh release upload "${GITHUB_REF_NAME}"
"${ARCHIVE_FILENAME}"
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
cargo-deb:
permissions:
contents: write
needs: build-release-archive
strategy:
fail-fast: false
matrix:
include:
- target: x86_64-unknown-linux-musl
arch: amd64
- target: aarch64-unknown-linux-musl
arch: arm64
runs-on: ubuntu-latest
env:
TARGET_DIR: target/${{ matrix.target }}
DEB_FILENAME: hanko-${{ github.ref_name }}-${{ matrix.arch }}.deb
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- uses: dtolnay/rust-toolchain@1482605bfc5719782e1267fd0c0cc350fe7646b8
with:
toolchain: stable
- uses: Swatinem/rust-cache@82a92a6e8fbeee089604da2575dc567ae9ddeaab
- uses: taiki-e/install-action@a22e1808bbd53573c0b897cc089c64643401af7d
with:
tool: cargo-deb
- name: Create Target Release Directory
run: mkdir -p ${TARGET_DIR}/release
- name: Download Release Binary
run: >-
gh release download ${GITHUB_REF_NAME} --pattern "*${{ matrix.target }}.tar.gz"
--output - | tar -xz -C ${TARGET_DIR}/release ./hanko
env:
GITHUB_TOKEN: ${{ github.token }}
- name: Create Debian Package
run: >-
cargo deb --no-build --no-strip --target ${{ matrix.target }}
--output ${TARGET_DIR}/debian/${DEB_FILENAME}
- name: Upload Debian Package
run: >-
gh release upload "${GITHUB_REF_NAME}"
"${TARGET_DIR}/debian/${DEB_FILENAME}"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
attest-build-provenance:
permissions:
id-token: write
attestations: write
contents: write
needs:
- build-release-archive
- cargo-deb
runs-on: ubuntu-latest
env:
DOWNLOAD_DIR: release-files
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- name: Download Release Files
run: >-
gh release download ${GITHUB_REF_NAME} --dir ${DOWNLOAD_DIR} --pattern "hanko-*"
env:
GITHUB_TOKEN: ${{ github.token }}
- name: Attest Build Provenance of Release Files
id: provenance
uses: actions/attest-build-provenance@ef244123eb79f2f7a7e75d99086184180e6d0018
with:
subject-path: ${{ env.DOWNLOAD_DIR }}/*
- name: Upload Provenance of Release Files
run: >-
gh release upload ${GITHUB_REF_NAME}
${{ steps.provenance.outputs.bundle-path }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
build-container-image:
permissions:
id-token: write
attestations: write
packages: write
strategy:
fail-fast: false
matrix:
include:
- target: x86_64-unknown-linux-musl
platform: linux/amd64
- target: aarch64-unknown-linux-musl
platform: linux/arm64
needs: build-release-archive
runs-on: ubuntu-latest
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- uses: docker/setup-buildx-action@c47758b77c9736f4b2ef4073d4d51994fabfe349
- name: Container Registry Login
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract Metadata (tags, labels)
id: meta
uses: docker/metadata-action@369eb591f429131d6889c46b94e711f089e6ca96
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Download Release Binary
run: >-
gh release download ${GITHUB_REF_NAME} --pattern "*${{ matrix.target }}.tar.gz"
--output - | tar -xz ./hanko
env:
GITHUB_TOKEN: ${{ github.token }}
- name: Build & Push Image
id: push
uses: docker/build-push-action@48aba3b46d1b1fec4febb7c5d0c644b249a11355
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: ${{ matrix.platform }}
- name: Attest Build Provenance
uses: actions/attest-build-provenance@ef244123eb79f2f7a7e75d99086184180e6d0018
with:
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: true