Skip to content

CI Runner

CI Runner #4052

Workflow file for this run

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
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":.}]')
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
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 [[ "$(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
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
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