Skip to content

CI Runner

CI Runner #6189

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 }}
steps:
- 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
- name: Checkout
uses: actions/checkout@v6
- name: Setup Runner
uses: ./.github/actions/setup-runner
with:
runner-version: ${{ steps.runner.outputs.version }}
- name: Register ephemeral runners
id: eph_reg
run: |
REG_WIN64=()
for i in $(seq 1 "${{ github.event.inputs.win_x86_64_count }}"); do
rm -f .runner
./runner register --no-interactive --instance "https://code.ffmpeg.org/" --ephemeral --name "gh-eph-win64" --labels "gh-win64" --token "${{ secrets.RUNNER_REGISTRATION_TOKEN }}"
REG_WIN64+=( "$(base64 -w0 .runner)" )
done
printf -v REG_LIST_WIN64 '"%s",' "${REG_WIN64[@]}"
echo "eph_reg_win64=[${REG_LIST_WIN64%,}]" >> $GITHUB_OUTPUT
REG_OSX=()
for i in $(seq 1 "${{ github.event.inputs.osx_count }}"); do
rm -f .runner
./runner register --no-interactive --instance "https://code.ffmpeg.org/" --ephemeral --name "gh-eph-osx" --labels "gh-osx" --token "${{ secrets.RUNNER_REGISTRATION_TOKEN }}"
REG_OSX+=( "$(base64 -w0 .runner)" )
done
printf -v REG_LIST_OSX '"%s",' "${REG_OSX[@]}"
echo "eph_reg_osx=[${REG_LIST_OSX%,}]" >> $GITHUB_OUTPUT
- 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=$(jq -cn --argjson c '${{ github.event.inputs.win_x86_64_count }}' --argjson r '${{ steps.eph_reg.outputs.eph_reg_win64 }}' '[range(1; $c+1) as $i | {"os":"windows-latest", "runner_id":$i, "reg_file":$r[$i-1]}]')
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=$(jq -cn --argjson c '${{ github.event.inputs.osx_count }}' --argjson r '${{ steps.eph_reg.outputs.eph_reg_osx }}' '[range(1; $c+1) as $i | {"os":"macos-latest", "runner_id":$i, "reg_file":$r[$i-1]}]')
echo "matrix_osx=$(jq -cn --argjson a "$OSX" '{include: ($a)}')" >> $GITHUB_OUTPUT
echo "matrix_osx_count=${{ github.event.inputs.osx_count }}" >> $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: Setup Runner
uses: ./.github/actions/setup-runner
with:
runner-version: ${{ needs.matrix.outputs.runner_version }}
- 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@v4
- 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 && RUNNER_RET=$? || RUNNER_RET=$?
if [[ "$RUNNER_RET" == "2" ]] then
# No Jobs left
exit 0
elif [[ "$RUNNER_RET" != "0" ]] 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
name: winci (${{ matrix.runner_id }})
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: Setup Runner
uses: ./.github/actions/setup-runner
with:
runner-version: ${{ needs.matrix.outputs.runner_version }}
- name: Register Runner
run: echo '${{ matrix.reg_file }}' | base64 -d > .runner
- name: Get Internal Env-Vars
uses: crazy-max/ghaction-github-runtime@v4
- name: Setup Caddy
uses: ./.github/actions/setup-caddy
- name: Start Cacheproxy
run: |
./cacheproxy/genconfig.sh
./caddy.exe start --config ./cacheproxy/Caddyfile
echo "ACTIONS_CACHE_URL_V2=http://localhost:8080/" >> .env
echo "ACTIONS_CACHE_SERVICE_V2=1" >> .env
- name: Run Runner
run: ./runner.exe one-job -c config_win64.yaml
- name: Stop Caddy
if: always()
run: ./caddy.exe stop || true
osxci:
needs: matrix
name: osxci (${{ matrix.runner_id }})
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: Setup Runner
uses: ./.github/actions/setup-runner
with:
runner-version: ${{ needs.matrix.outputs.runner_version }}
- name: Register Runner
run: echo '${{ matrix.reg_file }}' | base64 -d > .runner
- name: Get Internal Env-Vars
uses: crazy-max/ghaction-github-runtime@v4
- name: Setup Caddy
uses: ./.github/actions/setup-caddy
- name: Start Cacheproxy
run: |
./cacheproxy/genconfig.sh
./caddy start --config ./cacheproxy/Caddyfile
echo "ACTIONS_CACHE_URL_V2=http://localhost:8080/" >> .env
echo "ACTIONS_CACHE_SERVICE_V2=1" >> .env
- name: Run Runner
run: ./runner one-job -c config_osx.yaml
- name: Stop Caddy
if: always()
run: ./caddy stop || true