Skip to content

Commit

Permalink
ci: use self-hosted runner for aarch64 builds
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerschtli committed Mar 6, 2024
1 parent 458366e commit 70be2ab
Showing 1 changed file with 15 additions and 97 deletions.
112 changes: 15 additions & 97 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ on:

jobs:
nix:
runs-on: ubuntu-latest
runs-on: "${{ matrix.system == 'aarch64' && 'self-hosted' || 'ubuntu-latest' }}"

strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -80,121 +81,38 @@ jobs:
- name: Free Disk Space (Ubuntu)
uses: jlumbroso/free-disk-space@main
continue-on-error: true
if: matrix.system == 'x86_64'
with:
tool-cache: true

- name: Install nix
uses: cachix/install-nix-action@v25
if: matrix.system == 'x86_64'
with:
extra_nix_config: |
keep-going = true
- name: Setup cachix
- name: Setup cachix (gerschtli)
uses: cachix/cachix-action@v14
with:
name: gerschtli
authToken: ${{ secrets.CACHIX_AUTH_TOKEN }}

- name: Build command (aarch64)
if: matrix.system == 'aarch64'
# FIXME: use upstream once --tty is removed
#uses: uraimo/run-on-arch-action@v2
uses: Gerschtli/run-on-arch-action@tty
- name: Setup cachix (nix-on-droid)
uses: cachix/cachix-action@v14
with:
arch: aarch64
distro: alpine_latest
githubToken: ${{ github.token }}
dockerRunArgs: --volume /nix:/nix
install: |
apk --no-cache add curl git xz
adduser --disabled-password ci
env: |
_system: ${{ matrix.system }}-linux
CACHIX_ACTIVATE_TOKEN: ${{ secrets.CACHIX_ACTIVATE_TOKEN || 'no-value' }}
CACHIX_AUTH_TOKEN: ${{ secrets.CACHIX_AUTH_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
mkdir -p /home/ci/.config/nix
cat <<EOF > /home/ci/.config/nix/nix.conf
experimental-features = nix-command flakes
keep-going = true
show-trace = true
access-tokens = github.com=$GITHUB_TOKEN
EOF
chown --recursive ci:ci /nix /home/ci
chgrp --recursive ci "$(pwd)"
chmod -R g+w "$(pwd)"
echo "::group::Install nix"
curl \
--silent \
--show-error \
--output /tmp/install \
--retry 5 \
--retry-all-errors \
--fail \
--location \
"https://nixos.org/nix/install"
su ci -c "sh /tmp/install --no-channel-add --no-daemon"
rm /tmp/install
function run() {
su ci -c ". /home/ci/.nix-profile/etc/profile.d/nix.sh; $*"
}
# FIXME: setting build-hook is needed because default hook `nix __build-remote` is not available
function build_hook() {
local nix_path="$(run which nix)"
echo "${nix_path/bin\/nix/libexec/nix/build-remote}"
}
run echo "build-hook = $(build_hook)" >> /home/ci/.config/nix/nix.conf
name: nix-on-droid
useDaemon: false

echo "::group::Setup cachix"
run nix-env --quiet -j8 -iA cachix -f https://cachix.org/api/v1/install
run cachix --version
run cachix use gerschtli
run cachix use nix-on-droid
echo "::group::Build command"
run git config --global --add safe.directory "$(pwd)"
run nix ${{ matrix.nix-command }}
${{ github.ref == 'refs/heads/master' && inputs.branch == '' && matrix.deploy-agent &&
format(
'
echo "::group::Build spec"
spec="$(run nix build --print-out-paths ".#cachix-deploy-spec-{0}")"
echo "::group::Upload spec"
run cachix push gerschtli "$spec"
echo "::group::Activate deployment"
run cachix deploy activate --agent "{0}" {1} "$spec"
',
matrix.deploy-agent,
matrix.deploy-args
)
|| 'echo "::group::Skip spec deploy"'
}}
- name: Build command (x86_64)
if: matrix.system == 'x86_64'
- name: Build command
env:
_system: ${{ matrix.system }}-linux
run: nix ${{ matrix.nix-command }}
run: |
nix ${{ matrix.nix-command }}
rm result || :
- name: Deploy cachix-agent spec (x86_64)
if: matrix.system == 'x86_64' && github.ref == 'refs/heads/master' && inputs.branch == '' && matrix.deploy-agent
- name: Deploy cachix-agent spec
if: github.ref == 'refs/heads/master' && inputs.branch == '' && matrix.deploy-agent
env:
CACHIX_ACTIVATE_TOKEN: ${{ secrets.CACHIX_ACTIVATE_TOKEN }}
run: |
Expand Down

0 comments on commit 70be2ab

Please sign in to comment.