-
-
Notifications
You must be signed in to change notification settings - Fork 5
214 lines (182 loc) · 6.17 KB
/
ci.yml
File metadata and controls
214 lines (182 loc) · 6.17 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
name: CI
on:
push:
branches: [main]
tags: ["v*"]
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
env:
IMAGE: ghcr.io/${{ github.repository }}
jobs:
build:
name: Build (${{ matrix.name }})
runs-on: ${{ matrix.runs_on }}
defaults:
run:
shell: nix develop --command bash -eo pipefail {0}
permissions:
id-token: write
contents: read
attestations: write
packages: write
strategy:
fail-fast: false
matrix:
include:
- name: linux-amd64
runs_on: ubuntu-24.04
platform: linux-amd64
- name: linux-arm64
runs_on: ubuntu-24.04-arm
platform: linux-arm64
- name: macos-arm64
runs_on: macos-26
platform: darwin-arm64
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Install Nix
uses: cachix/install-nix-action@v31
with:
extra_nix_config: |
accept-flake-config = true
- name: Cachix
uses: cachix/cachix-action@v16
with:
name: pdf-sign
authToken: ${{ secrets.CACHIX_AUTH_TOKEN }}
- name: Build (flake)
run: |
nix build .#pdf-sign --out-link result
- name: Test (flake checks)
run: |
nix flake check -L
- name: Collect artifact
run: |
mkdir -p dist
cp -L result/bin/pdf-sign "dist/pdf-sign-${{ runner.os }}-$(uname -m)"
- name: Generate artifact attestation
uses: actions/attest-build-provenance@v4
with:
subject-path: dist/*
- name: Upload artifact
uses: actions/upload-artifact@v7
with:
name: pdf-sign-${{ matrix.name }}
path: dist/*
# --- OCI image build and push (all platforms) ---
- name: Build streaming image
run: |
nix build .#image --out-link image
- name: Login to GHCR
if: github.event.pull_request.head.repo.fork != true
run: |
skopeo login ghcr.io \
--username "${{ github.actor }}" \
--password "${{ secrets.GITHUB_TOKEN }}" \
--compat-auth-file "$HOME/.docker/config.json"
- name: Push image to GHCR
id: push-image
if: github.event.pull_request.head.repo.fork != true
run: |
printf '{"default":[{"type":"reject"}],"transports":{"docker-archive":{"":[{"type":"insecureAcceptAnything"}]},"docker":{"ghcr.io/%s":[{"type":"insecureAcceptAnything"}]}}}\n' \
"${{ github.repository }}" > "$RUNNER_TEMP/skopeo-policy.json"
./image | gzip --fast | skopeo \
--policy "$RUNNER_TEMP/skopeo-policy.json" \
copy \
--digestfile "$RUNNER_TEMP/image-digest" \
docker-archive:/dev/stdin \
"docker://$IMAGE:sha-${GITHUB_SHA::7}-${{ matrix.platform }}"
echo "digest=$(cat "$RUNNER_TEMP/image-digest")" >> "$GITHUB_OUTPUT"
- name: Attest image
if: github.event.pull_request.head.repo.fork != true
uses: actions/attest-build-provenance@v4
with:
subject-name: ${{ env.IMAGE }}
subject-digest: ${{ steps.push-image.outputs.digest }}
push-to-registry: true
docker:
name: Docker Manifest
if: github.event.pull_request.head.repo.fork != true
needs: build
runs-on: ubuntu-24.04
defaults:
run:
shell: nix develop --command bash -eo pipefail {0}
permissions:
id-token: write
contents: read
packages: write
attestations: write
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Install Nix
uses: cachix/install-nix-action@v31
with:
extra_nix_config: |
accept-flake-config = true
- name: Cachix
uses: cachix/cachix-action@v16
with:
name: pdf-sign
authToken: ${{ secrets.CACHIX_AUTH_TOKEN }}
- name: Login to GHCR
run: |
skopeo login ghcr.io \
--username "${{ github.actor }}" \
--password "${{ secrets.GITHUB_TOKEN }}" \
--compat-auth-file "$HOME/.docker/config.json"
- name: Compute tags
id: tags
run: |
SHA_SHORT="${GITHUB_SHA::7}"
TAGS="$IMAGE:sha-$SHA_SHORT"
if [[ "$GITHUB_REF" == refs/heads/main ]]; then
TAGS="$TAGS,$IMAGE:latest"
fi
if [[ "$GITHUB_REF" == refs/tags/v* ]]; then
VERSION="${GITHUB_REF#refs/tags/}"
TAGS="$TAGS,$IMAGE:$VERSION"
TAGS="$TAGS,$IMAGE:${VERSION#v}"
MINOR="${VERSION%.*}"
TAGS="$TAGS,$IMAGE:${MINOR#v}"
TAGS="$TAGS,$IMAGE:latest"
fi
echo "tags=$TAGS" >> "$GITHUB_OUTPUT"
- name: Create multi-platform manifest
run: |
SHA_SHORT="${GITHUB_SHA::7}"
IFS=',' read -ra TAG_ARRAY <<< "${{ steps.tags.outputs.tags }}"
FIRST_TAG="${TAG_ARRAY[0]}"
EXTRA_TAGS=()
for tag in "${TAG_ARRAY[@]:1}"; do
EXTRA_TAGS+=(--tags "${tag##*:}")
done
manifest-tool push from-args \
--platforms linux/amd64,linux/arm64,darwin/arm64 \
--template "$IMAGE:sha-$SHA_SHORT-OS-ARCH" \
--target "$FIRST_TAG" \
"${EXTRA_TAGS[@]}"
- name: Get manifest digest
id: digest
run: |
SHA_SHORT="${GITHUB_SHA::7}"
DIGEST=$(skopeo inspect "docker://$IMAGE:sha-$SHA_SHORT" | jq -r '.Digest')
echo "digest=$DIGEST" >> "$GITHUB_OUTPUT"
- name: Attest manifest
uses: actions/attest-build-provenance@v4
with:
subject-name: ${{ env.IMAGE }}
subject-digest: ${{ steps.digest.outputs.digest }}
push-to-registry: true
- name: Verify attestations
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
sleep 5
IFS=',' read -ra TAG_ARRAY <<< "${{ steps.tags.outputs.tags }}"
for tag in "${TAG_ARRAY[@]}"; do
echo "Verifying $tag..."
gh attestation verify "oci://$tag" --repo "${{ github.repository }}"
done