Repository navigation
264 lines (232 loc) · 8.22 KB
/
Copy pathrelease.yml
File metadata and controls
264 lines (232 loc) · 8.22 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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
name: Release Build and Publish
permissions:
contents: write
pull-requests: read
packages: write
on:
push:
tags:
- "v*"
pull_request:
paths:
- "**/*.rs"
- "**/Cargo.toml"
- "Cargo.lock"
- "flake.nix"
workflow_dispatch:
inputs:
release_name:
description: "Name of release (optional)"
required: false
default: ""
create_release:
description: "Create a GitHub release? (true/false)"
required: false
default: "false"
create_binaries:
description: "Create a Binaries? (true/false)"
required: false
default: "false"
create_images:
description: "Create a Docker Images? (true/false)"
required: false
default: "false"
jobs:
setup:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.set-version.outputs.version }}
steps:
- name: Extract version
id: set-version
run: |
if [ -n "${{ github.event.inputs.release_name }}" ]; then
VERSION="${{ github.event.inputs.release_name }}"
elif [[ "${GITHUB_REF}" == refs/tags/v* ]]; then
VERSION="${GITHUB_REF#refs/tags/v}"
elif [[ "${GITHUB_REF}" == refs/tags/* ]]; then
VERSION="${GITHUB_REF#refs/tags/}"
else
VERSION="${GITHUB_REF_NAME}"
fi
echo "VERSION=$VERSION"
echo "version=$VERSION" >> $GITHUB_OUTPUT
generate-matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.generate-matrix.outputs.matrix }}
arch_list: ${{ steps.generate-arch-list.outputs.arch_list }}
steps:
- uses: actions/checkout@v4
- name: Install Nix
uses: cachix/install-nix-action@v30
with:
nix_path: nixpkgs=channel:nixos-unstable
github_access_token: ${{ secrets.GITHUB_TOKEN }}
extra_nix_config: |
experimental-features = nix-command flakes
- name: Setup Attic cache
uses: ryanccn/attic-action@v0
with:
endpoint: https://cache.rustlang-es.org/
cache: main
token: ${{ secrets.ATTIC_TOKEN }}
- name: Generate matrix
id: generate-matrix
run: |
MATRIX=$(nix run .#matrix --quiet)
echo "Generated Matrix:"
echo "$MATRIX"
echo "matrix=$MATRIX" >> $GITHUB_OUTPUT
- name: Generate Arch List
id: generate-arch-list
run: |
ARCH_LIST=$(nix run .#archs --quiet)
echo "Generated Archs:"
echo "$ARCH_LIST"
echo "arch_list=$ARCH_LIST" >> $GITHUB_OUTPUT
build:
runs-on: ubuntu-latest
needs: [setup, generate-matrix]
env:
VERSION: ${{ needs.setup.outputs.version }}
if: ${{ github.event.inputs.create_binaries == 'true' || (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')) }}
strategy:
fail-fast: false
matrix:
include: ${{ fromJson(needs.generate-matrix.outputs.matrix) }}
steps:
- uses: actions/checkout@v4
- name: Install Nix
uses: cachix/install-nix-action@v30
with:
nix_path: nixpkgs=channel:nixos-unstable
github_access_token: ${{ secrets.GITHUB_TOKEN }}
extra_nix_config: |
experimental-features = nix-command flakes
- name: Setup Attic cache
uses: ryanccn/attic-action@v0
with:
endpoint: https://cache.rustlang-es.org/
cache: main
token: ${{ secrets.ATTIC_TOKEN }}
- name: Set up artifact name
run: |
echo "ARTIFACT_NAME=grhooks_${{ env.VERSION }}_${{ matrix.os }}_${{ matrix.arch }}.${{ matrix.format }}" >> $GITHUB_ENV
- name: Build package
run: |
echo "Building ${{ matrix.package }} for ${{ matrix.arch }}-${{ matrix.os }}..."
nix bundle --bundler "${{ matrix.bundler }}" ".#${{ matrix.package }}" --out-link result
mkdir -p dist
cp result/*${{ matrix.format }} dist/${{ env.ARTIFACT_NAME }}
- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: ${{ env.ARTIFACT_NAME }}
path: dist/*
create-release:
runs-on: ubuntu-latest
needs: [setup, build]
if: ${{ github.event.inputs.create_release == 'true' || (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')) }}
steps:
- uses: actions/checkout@v4
- name: Generate changelog
uses: orhun/git-cliff-action@v4
id: git-cliff
with:
config: cliff.toml
args: --latest
env:
OUTPUT: CHANGES.md
GITHUB_REPO: ${{ github.repository }}
- name: Get release name
id: release_name
run: |
if [ -n "${{ github.event.inputs.release_name }}" ]; then
echo "RELEASE_NAME=${{ github.event.inputs.release_name }}" >> $GITHUB_OUTPUT
else
echo "RELEASE_NAME=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
fi
- name: Download Artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
merge-multiple: true
- name: Create Release
uses: softprops/action-gh-release@v2
with:
make_latest: true
prerelease: ${{ steps.release_name.outputs.release_name != '' && contains(steps.release_name.outputs.release_name, 'a') }}
tag_name: ${{ needs.setup.outputs.version }}
name: ${{ needs.setup.outputs.version }}
body: ${{ steps.git-cliff.outputs.content }}
files: |
artifacts/*
CHANGES.md
docker-build:
runs-on: ubuntu-latest
needs: [setup, generate-matrix]
env:
VERSION: ${{ needs.setup.outputs.version }}
if: ${{ github.event.inputs.create_images == 'true' || (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')) }}
strategy:
fail-fast: false
matrix:
include: ${{ fromJson(needs.generate-matrix.outputs.arch_list) }}
steps:
- uses: actions/checkout@v4
- name: Set Repository Lowercase
run: echo "REPOSITORY=${GITHUB_REPOSITORY,,}" >> $GITHUB_ENV
- name: Install Nix
uses: cachix/install-nix-action@v30
with:
nix_path: nixpkgs=channel:nixos-unstable
github_access_token: ${{ secrets.GITHUB_TOKEN }}
extra_nix_config: |
experimental-features = nix-command flakes
- name: Setup Attic cache
uses: ryanccn/attic-action@v0
with:
endpoint: https://cache.rustlang-es.org/
cache: main
token: ${{ secrets.ATTIC_TOKEN }}
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build individual images with Nix
run: |
nix build .#image-${{ matrix.arch }}
docker load < ./result
docker tag grhooks:${{ env.VERSION }} ghcr.io/${{ env.REPOSITORY }}:${{ env.VERSION }}-${{ matrix.arch }}
- name: Push image
run: |
docker push ghcr.io/${{ env.REPOSITORY }}:${{ env.VERSION }}-${{ matrix.arch }}
docker-publish:
runs-on: ubuntu-latest
needs: [setup, generate-matrix, docker-build]
env:
VERSION: ${{ needs.setup.outputs.version }}
ARCHS: ${{ needs.generate-matrix.outputs.arch_list }}
steps:
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set Repository Lowercase
run: echo "REPOSITORY=${GITHUB_REPOSITORY,,}" >> $GITHUB_ENV
- name: Create and push manifest
run: |
IMAGE=ghcr.io/${{ env.REPOSITORY }}:${{ env.VERSION }}
echo "Creating manifest for architectures: $ARCHS"
manifest_args=""
for arch in $(echo "$ARCHS" | jq -r '.[].arch'); do
manifest_args="$manifest_args --amend ghcr.io/${{ env.REPOSITORY }}:${{ env.VERSION }}-$arch"
done
echo "Running docker manifest create $IMAGE $manifest_args"
eval docker manifest create $IMAGE $manifest_args
docker manifest push $IMAGE