Skip to content

Build and populate cache #329

Build and populate cache

Build and populate cache #329

Workflow file for this run

name: "Build and populate cache"
on:
workflow_dispatch: # allows manual triggering
pull_request:
push:
branches:
- main
- master
schedule:
# rebuild everyday at 3:30
# TIP: Choose a random time here so not all repositories are build at once:
# https://www.random.org/clock-times/?num=1&earliest=01%3A00&latest=08%3A00&interval=5&format=html&rnd=new
- cron: '30 3 * * *'
jobs:
define-matrix:
name: Define job matrix
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.matrix.outputs.matrix }}
steps:
- name: Define matrix
id: matrix
run: |
jq -nrf /dev/stdin << 'EOF' > "$GITHUB_OUTPUT"
"Rhys-T" as $nurRepo |
"rhys-t" as $cachixName |
[
"Lnx x64/ubuntu-latest",
"Lnx A64/ubuntu-latest+qemu-aarch64-linux",
"Mac x64/macos-13",
"Mac A64/macos-latest",
empty] as $runners |
[
"nixpkgs-unstable",
"nixos-unstable",
"nixos-24.05",
"nixos-24.11",
empty] as $nixpkgss |
[
"base",
"mame",
"hbmame",
"qemu-screamer",
empty] as $subsets |
{include: [
$runners[] as $runner |
$nixpkgss[] as $nixpkgs |
($runner | split("/")) as [$displayRunner, $runner] |
select(($runner | startswith("ubuntu")) or ($nixpkgs | startswith("nixpkgs"))) |
($runner | split("+qemu-")) as [$runner, $qemuSystem] |
(if $qemuSystem then {
"aarch64-linux": "arm64",
}[$qemuSystem] else null end) as $qemuSystemForAction |
# (if $qemuSystem then $subsets[] else "all" end) as $subset |
$subsets[] as $subset |
select(($runner | startswith("macos")) or ($subset != "mame")) |
($nixpkgs |
gsub("^nixpkgs-"; "NP-") |
gsub("^nixos-"; "NO-") |
gsub("-unstable$"; "-U") |
.) as $displayNixpkgs |
{$displayRunner, $runner, $qemuSystem, $qemuSystemForAction, $displayNixpkgs, $nixpkgs, $subset, $nurRepo, $cachixName}
]} |
@json "matrix=\(.)"
EOF
tests:
needs: define-matrix
strategy:
matrix: ${{ fromJson(needs.define-matrix.outputs.matrix) }}
fail-fast: false
name: ${{ matrix.displayRunner }} ${{ matrix.displayNixpkgs }} ${{ matrix.subset }}
runs-on: ${{ matrix.runner }}
outputs:
nurRepo: ${{ steps.build.outputs.nurRepo }}
steps:
- name: Output nurRepo for final job
run: echo 'nurRepo=${{ matrix.nurRepo }}' >> "$GITHUB_OUTPUT"
- name: Checkout repository
uses: actions/checkout@v4
- name: Install qemu-user-static
if: ${{ matrix.qemuSystem != null }}
uses: docker/setup-qemu-action@v3
with:
platforms: ${{ matrix.qemuSystemForAction }}
- name: Install nix
uses: cachix/install-nix-action@v30
with:
nix_path: "nixpkgs=https://github.com/NixOS/nixpkgs/archive/refs/heads/${{ matrix.nixpkgs }}.tar.gz"
extra_nix_config: |
experimental-features = nix-command flakes
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
${{ matrix.qemuSystem && format('extra-platforms = {0}', matrix.qemuSystem)}}
- name: Show nixpkgs version
run: nix-instantiate --eval -E '(import <nixpkgs> {}).lib.version'
- name: Setup cachix
uses: cachix/cachix-action@v15
# Don't replace <YOUR_CACHIX_NAME> here!
if: ${{ matrix.cachixName != '<YOUR_CACHIX_NAME>' }}
with:
name: ${{ matrix.cachixName }}
signingKey: '${{ secrets.CACHIX_SIGNING_KEY }}'
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
- name: Check evaluation
run: |
nix-env -f . -qa \* --meta --xml \
--allowed-uris https://static.rust-lang.org \
--option restrict-eval true \
--option allow-import-from-derivation true \
--drv-path --show-trace \
-I nixpkgs=$(nix-instantiate --find-file nixpkgs) \
-I $PWD
- name: Build nix packages
id: build
run: nix shell -f '<nixpkgs>' nix-build-uncached -c nix-build-uncached ci.nix -build-flags '-L --keep-going' ${{ matrix.qemuSystem && format('--argstr platform {0}', matrix.qemuSystem) }} --argstr subsetName ${{ matrix.subset }} -A cacheOutputs
- name: Upload build logs
if: '!cancelled()'
uses: actions/upload-artifact@v4
with:
name: Rhys-T-nur-packages-build-logs-${{ matrix.runner }}${{ matrix.qemuSystem && format('+qemu-{0}', matrix.qemuSystem) }}-${{ matrix.nixpkgs }}-${{ matrix.subset }}
path: |
/nix/var/log
!/nix/var/log/nix/drvs/*/*user-environment*
if-no-files-found: ignore
trigger-update:
name: Trigger NUR update
runs-on: ubuntu-latest
needs: tests
steps:
- name: Trigger NUR update
# Don't replace <YOUR_REPO_NAME> here!
if: ${{ needs.tests.outputs.nurRepo != '<YOUR_REPO_NAME>' }}
run: curl -XPOST "https://nur-update.nix-community.org/update?repo=${{ needs.tests.outputs.nurRepo }}"