-
Notifications
You must be signed in to change notification settings - Fork 2
237 lines (234 loc) · 9.72 KB
/
ci.yml
File metadata and controls
237 lines (234 loc) · 9.72 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
name: CI Runner
on:
workflow_dispatch:
inputs:
x86_64_count:
description: 'Number of x86_64 runners'
required: true
type: number
default: 0
aarch64_count:
description: 'Number of aarch64 runners'
required: true
type: number
default: 0
win_x86_64_count:
description: 'Number of x86_64 Windows runners'
required: true
type: number
default: 0
osx_count:
description: 'Number of OSX (aarch64) runners'
required: true
type: number
default: 0
riscv64_count:
description: 'Number of riscv64 (QEMU) runners'
required: true
type: number
default: 0
defaults:
run:
shell: bash
jobs:
matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.matrix.outputs.matrix }}
matrix_win: ${{ steps.matrix.outputs.matrix_win }}
matrix_osx: ${{ steps.matrix.outputs.matrix_osx }}
matrix_count: ${{ steps.matrix.outputs.matrix_count }}
matrix_win_count: ${{ steps.matrix.outputs.matrix_win_count }}
matrix_osx_count: ${{ steps.matrix.outputs.matrix_osx_count }}
runner_version: ${{ steps.runner.outputs.version }}
runner_version_major: ${{ steps.runner.outputs.version_major }}
steps:
- name: Calculate Matrix
id: matrix
run: |
X86=$(seq 1 "${{ github.event.inputs.x86_64_count }}" | jq -cs '[.[] | {"os":"ubuntu-latest", "runner_id":.}]')
ARM=$(seq 1 "${{ github.event.inputs.aarch64_count }}" | jq -cs '[.[] | {"os":"ubuntu-24.04-arm", "runner_id":.}]')
RISCV=$(seq 1 "${{ github.event.inputs.riscv64_count }}" | jq -cs '[.[] | {"os":"ubuntu-latest", "runner_id":., "riscv":true}]')
#echo "matrix=$(jq -cn --argjson a "$X86" --argjson b "$ARM" '{include: ($a + $b)}')" >> $GITHUB_OUTPUT
#echo "matrix_count=$(( ${{ github.event.inputs.x86_64_count }} + ${{ github.event.inputs.aarch64_count }} ))" >> $GITHUB_OUTPUT
echo "matrix=$(jq -cn --argjson a "$X86" --argjson b "$ARM" --argjson c "$RISCV" '{include: ($a + $b + $c)}')" >> $GITHUB_OUTPUT
echo "matrix_count=$(( \
${{ github.event.inputs.x86_64_count }} + \
${{ github.event.inputs.aarch64_count }} + \
${{ github.event.inputs.riscv64_count }} ))" >> $GITHUB_OUTPUT
WINX86=$(seq 1 "${{ github.event.inputs.win_x86_64_count }}" | jq -cs '[.[] | {"os":"windows-latest", "runner_id":.}]')
echo "matrix_win=$(jq -cn --argjson a "$WINX86" '{include: ($a)}')" >> $GITHUB_OUTPUT
echo "matrix_win_count=$(( ${{ github.event.inputs.win_x86_64_count }} ))" >> $GITHUB_OUTPUT
OSX=$(seq 1 "${{ github.event.inputs.osx_count }}" | jq -cs '[.[] | {"os":"macos-latest", "runner_id":.}]')
echo "matrix_osx=$(jq -cn --argjson a "$OSX" '{include: ($a)}')" >> $GITHUB_OUTPUT
echo "matrix_osx_count=$(( ${{ github.event.inputs.osx_count }} ))" >> $GITHUB_OUTPUT
- name: Get Runner Version
id: runner
run: |
VER="$(curl -s https://code.forgejo.org/api/v1/repos/forgejo/runner/releases/latest | jq .name -r | cut -c 2-)"
echo "version=$VER" >> $GITHUB_OUTPUT
echo "version_major=${VER/.*/}" >> $GITHUB_OUTPUT
ci:
needs: matrix
strategy:
fail-fast: false
matrix: ${{ fromJSON(needs.matrix.outputs.matrix) }}
runs-on: ${{ matrix.os }}
if: ${{ needs.matrix.outputs.matrix_count > 0 }}
steps:
- name: Free up disk space
shell: bash -c "nohup bash -e {0} >/tmp/cleanup.log &"
run: |
df -h
docker system prune -a -f
sudo rm -rf /opt/ghc /usr/local/.ghcup /usr/local/lib/android
df -h
- name: Checkout
uses: actions/checkout@v6
- name: Cache Runner
id: cache_runner
uses: actions/cache@v5
with:
key: fj-runner-${{ matrix.os }}-${{ needs.matrix.outputs.runner_version }}
path: runner
- name: Download Runner
if: ${{ steps.cache_runner.outputs.cache-hit != 'true' }}
run: |
if [[ "$(uname -m)" == "aarch64" ]]; then
RUNNERARCH="arm64"
else
RUNNERARCH="amd64"
fi
curl -Ls "https://code.forgejo.org/forgejo/runner/releases/download/v${{ needs.matrix.outputs.runner_version }}/forgejo-runner-${{ needs.matrix.outputs.runner_version }}-linux-${RUNNERARCH}.xz" | unxz > runner
chmod +x runner
- name: Register Runner
run: |
#if [[ "${{ matrix.riscv }}" == "true" ]]; then
if [[ "${{ matrix.riscv || false }}" == "true" ]]; then
printf '%s\n' '${{ secrets.RUNNER_REGISTRATION_X86_64 }}' > .runner
mv config_riscv64.yaml config.yaml
elif [[ "$(uname -m)" == "aarch64" ]]; then
printf '%s\n' '${{ secrets.RUNNER_REGISTRATION_AARCH64 }}' > .runner
mv config_aarch64.yaml config.yaml
else
printf '%s\n' '${{ secrets.RUNNER_REGISTRATION_X86_64 }}' > .runner
mv config_x86_64.yaml config.yaml
fi
- name: Restore Actions Cache
id: act_cache
uses: actions/cache/restore@v5
with:
key: act-ck-cache2-${{ matrix.os }}
path: /var/act
restore-keys: |
act-ck-cache2-${{ matrix.os }}-
- name: Set cache permissions
run: |
sudo mkdir -p /var/act /var/actcache
sudo chown -R $(id -u):$(id -g) /var/act /var/actcache
- name: Restore Docker Images
id: docker_cache_restore
uses: ./.github/actions/docker-cache-restore
with:
cache-key: docker-image-cache-${{ matrix.os }}
- name: Get Internal Env-Vars
uses: crazy-max/ghaction-github-runtime@v3
- name: Start Cacheproxy
if: ${{ !env.ACT }}
run: |
./cacheproxy/genconfig.sh
docker network create runnernet
docker run --rm --pull=always -d --network runnernet --name cacheproxy -v ./cacheproxy:/etc/caddy caddy:2
echo "ACTIONS_CACHE_URL_V2=http://cacheproxy:8080/" >> .env
echo "ACTIONS_CACHE_SERVICE_V2=1" >> .env
- name: Run Runner
if: ${{ !env.ACT }}
id: runner
run: |
RUNNER_RET=0
while [[ "$RUNNER_RET" == "0" ]]; do
./runner one-job -c config.yaml |& tee runner.log && RUNNER_RET=$? || RUNNER_RET=$?
if [[ "$RUNNER_RET" != "0" ]] && ! grep -q "Error: could not fetch task" runner.log; then
exit "$RUNNER_RET"
fi
done
exit 0
- name: Cache Docker Images
uses: ./.github/actions/docker-cache-save
with:
cache-key: docker-image-cache-${{ matrix.os }}
matched-key: ${{ steps.docker_cache_restore.outputs.cache-matched-key }}
- name: Calculate Cache Hash
id: cache_hash
run: |
echo "hash=$(find act -type f -print0 | sort -z | xargs -0 sha1sum | sha1sum | cut -d' ' -f1)" >> $GITHUB_OUTPUT
- name: Save Actions Cache
uses: actions/cache/save@v5
if: ${{ format('act-cache-{0}-{1}', matrix.os, steps.cache_hash.outputs.hash) != steps.act_cache.outputs.cache-matched-key }}
with:
key: act-ck-cache-${{ matrix.os }}-${{ steps.cache_hash.outputs.hash }}
path: act
- name: Cleanup result
run: cat /tmp/cleanup.log
- name: Result output
run: |
cat ./cacheproxy/Caddyfile
echo -------------------------
docker logs cacheproxy
winci:
needs: matrix
strategy:
fail-fast: false
matrix: ${{ fromJSON(needs.matrix.outputs.matrix_win) }}
runs-on: ${{ matrix.os }}
if: ${{ needs.matrix.outputs.matrix_win_count > 0 }}
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Cache Runner
id: cache_runner
uses: actions/cache@v5
with:
key: fj-runner-${{ matrix.os }}-${{ needs.matrix.outputs.runner_version }}
path: runner.exe
- uses: actions/setup-go@v6
if: ${{ steps.cache_runner.outputs.cache-hit != 'true' }}
with:
go-version: 'stable'
- name: Build Runner
if: ${{ steps.cache_runner.outputs.cache-hit != 'true' }}
run: |
git clone --depth=1 --branch="v${{ needs.matrix.outputs.runner_version }}" https://code.forgejo.org/forgejo/runner.git runner-build
cd runner-build
go build -v -buildmode=exe -tags 'netgo osusergo' -ldflags '-extldflags "-static" -s -w -X "code.forgejo.org/forgejo/runner/v${{ needs.matrix.outputs.runner_version_major }}/internal/pkg/ver.version=v${{ needs.matrix.outputs.runner_version }}"' -o ../runner.exe
cd ..
rm -rf runner-build
osxci:
needs: matrix
strategy:
fail-fast: false
matrix: ${{ fromJSON(needs.matrix.outputs.matrix_osx) }}
runs-on: ${{ matrix.os }}
if: ${{ needs.matrix.outputs.matrix_osx_count > 0 }}
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Cache Runner
id: cache_runner
uses: actions/cache@v5
with:
key: fj-runner-${{ matrix.os }}-${{ needs.matrix.outputs.runner_version }}
path: runner
- uses: actions/setup-go@v6
if: ${{ steps.cache_runner.outputs.cache-hit != 'true' }}
with:
go-version: 'stable'
- name: Build Runner
if: ${{ steps.cache_runner.outputs.cache-hit != 'true' }}
run: |
git clone --depth=1 --branch="v${{ needs.matrix.outputs.runner_version }}" https://code.forgejo.org/forgejo/runner.git runner-build
cd runner-build
make -j$(nproc) build
mv forgejo-runner ../runner
cd ..
rm -rf runner-build