forked from Fediversity/Fediversity
61 lines
1.2 KiB
Bash
Executable file
61 lines
1.2 KiB
Bash
Executable file
#!/bin/sh
|
|
set -euC
|
|
|
|
cd "$(dirname "$0")" || exit 3
|
|
|
|
nix_eval () { nix eval --impure --raw --expr "with builtins; $1"; }
|
|
system=$(nix_eval "currentSystem")
|
|
checks=$(nix_eval "toJSON (attrNames (getFlake (toString ../..)).checks.$system)")
|
|
|
|
output=$(mktemp)
|
|
|
|
{
|
|
cat <<EOF
|
|
name: Nix flake checks
|
|
|
|
on:
|
|
pull_request:
|
|
types:
|
|
- opened
|
|
- synchronize
|
|
- reopened
|
|
push:
|
|
branches:
|
|
- main
|
|
|
|
jobs:
|
|
_checks:
|
|
needs: $checks
|
|
runs-on: native
|
|
steps:
|
|
- run: true
|
|
|
|
_complete:
|
|
runs-on: native
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
- run: nix-shell --run '.forgejo/workflows/nix-flake-check.sh check'
|
|
EOF
|
|
|
|
for check in $(echo "$checks" | jq -r .[]); do
|
|
cat <<EOF
|
|
|
|
$check:
|
|
runs-on: native
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
- run: nix build .#checks.$system.$check -vL
|
|
EOF
|
|
done
|
|
} >| "$output"
|
|
|
|
target=$(basename "$0" .sh).yaml
|
|
|
|
if [ $# -eq 1 ] && [ "$1" = "check" ]; then
|
|
if ! diff_output=$(diff --color=always "$target" "$output"); then
|
|
printf >&2 'Changes detected (\e[31m< current\e[0m | \e[32m> generated\e[0m):\n%s\n' "$diff_output"
|
|
exit 1
|
|
fi
|
|
else
|
|
mv "$output" "$target"
|
|
fi
|