ci: move test logic into a script

This commit is contained in:
Ivan Petkov 2022-10-20 20:46:45 -07:00
parent 9c16d69328
commit 9ed120ca50
No known key found for this signature in database
GPG Key ID: BB6F9EFC065832B6
3 changed files with 87 additions and 35 deletions

View File

@ -6,46 +6,41 @@ on:
branches:
- 'master'
- 'ci*' # Allow testing CI fixes without opening a PR
workflow_call:
permissions:
contents: read
jobs:
tests-pass:
name: all systems go
runs-on: ubuntu-latest
steps:
- run: exit 0
needs:
- tests
tests:
strategy:
# Allow other jobs to finish building and cache properly before bailing
fail-fast: false
matrix:
include:
- os: ubuntu-latest
- test_args: "--locked"
# Latest and greatest release of Nix
install_url: https://nixos.org/nix/install
- os: ubuntu-latest
- test_args: "--stable"
# The 22.05 branch ships with Nix 2.8.1
install_url: https://releases.nixos.org/nix/nix-2.8.1/install
nixpkgs-override: "--override-input nixpkgs github:NixOS/nixpkgs/release-22.05"
runs-on: ${{ matrix.os }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: cachix/install-nix-action@v17
- uses: cachix/install-nix-action@v18
with:
install_url: ${{ matrix.install_url }}
- uses: cachix/cachix-action@v10
- uses: cachix/cachix-action@v11
with:
name: crane
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
- name: flake checks
run: nix flake check --keep-going --print-build-logs ${{ matrix.nixpkgs-override }}
- name: extra tests
run: nix develop ${{ matrix.nixpkgs-override }} --command ./extra-tests/test.sh
- name: validate examples
run: |
for f in $(find examples -maxdepth 1 -mindepth 1 -type d); do
pushd "${f}"
echo "validating ${f}"
nix flake check --print-build-logs --override-input crane ../.. ${{ matrix.nixpkgs-override }}
nix run --override-input crane ../.. ${{ matrix.nixpkgs-override }}
popd
done
- name: run tests
run: ./ci/run-tests.sh ${{ matrix.test_args }}

View File

@ -3,26 +3,22 @@ name: Update flake dependencies
on:
workflow_dispatch: # for allowing manual triggers of the workflow
permissions:
contents: read
jobs:
test-with-updated-dependencies:
update-and-push-deps:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: cachix/install-nix-action@v17
- name: update flake.lock
run: nix flake update
- name: run test suite
uses: ./.github/workflows/test.yml
push-updates:
permissions:
contents: write
runs-on: ubuntu-latest
needs: test-with-updated-dependencies
steps:
- uses: actions/checkout@v3
- uses: cachix/install-nix-action@v18
with:
install_url: ${{ matrix.install_url }}
- uses: cachix/cachix-action@v11
with:
name: crane
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
- name: run tests
run: ./ci/run-tests.sh --locked
# Use the REST API to commit changes, so we get automatic commit signing
# https://gist.github.com/swinton/03e84635b45c78353b1f71e41007fc7c
- name: Commit changes

61
ci/run-tests.sh Executable file
View File

@ -0,0 +1,61 @@
#!/usr/bin/env bash
set -eu
NIXPKGS_STABLE="github:NixOS/nixpkgs/release-22.05"
main() {
cd $(dirname "$0")/..
# Run all tests by default
runStable="1"
runLocked="1"
while [ $# -gt 0 ]; do
case "$1" in
"--locked")
runLocked="1"
runStable=""
;;
"--stable")
runLocked=""
runStable="1"
;;
*)
echo "unrecognized option $1"
exit 1
;;
esac
done
if [ -n "${runLocked}" ]; then
runtests
fi
if [ -n "${runStable}" ]; then
runtests "--override-input nixpkgs ${NIXPKGS_STABLE}"
fi
}
runtests() {
overrideArgs=""
if [ $# -gt 0 ]; then
overrideArgs="$1"
fi
echo running flake checks
nix flake check --keep-going --print-build-logs ${overrideArgs}
echo running extra tests
nix develop ${overrideArgs} --command ./extra-tests/test.sh
for f in $(find examples -maxdepth 1 -mindepth 1 -type d); do
pushd "${f}"
echo "validating ${f}"
nix flake check --print-build-logs --keep-going --override-input crane ../.. $overrideArgs
nix run --override-input crane ../.. ${overrideArgs}
popd
done
}
main