diff --git a/.github/workflows/image.yml b/.github/workflows/image.yml index 5a99cb6..faa2292 100644 --- a/.github/workflows/image.yml +++ b/.github/workflows/image.yml @@ -33,18 +33,8 @@ jobs: timeout-minutes: 10 steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - # The VM set-up's parts are fragments of one script (vm/kali.sh defines `$keep`): each - # composition the launcher makes must parse, with the player's account between the toolset - # and the desktop. - - name: The VM set-up parses - run: | - set -euo pipefail - for parts in "vm/kali.sh vm/toolset.sh" "vm/kali.sh vm/toolset.sh vm/desktop.sh" "vm/kali.sh vm/desktop.sh"; do - # shellcheck disable=SC2086 - { cat $parts; } | sh -n - done - - name: shellcheck - run: shellcheck player-account.sh smoke-test.sh + # The VM set-up's compositions parse, and shellcheck (check.sh, as a contributor runs it). + - run: ./check.sh scripts smoke: strategy: @@ -61,11 +51,9 @@ jobs: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 # The image is large (~14 GB unpacked): Docker keeps its data on the runner's scratch disk. - uses: ./.github/actions/scratch-disk-docker - # No registry, no secrets: a plain local build, so pull requests from forks run it too. - - name: Build - run: docker build --pull -t attack-box:smoke . - - name: Smoke test - run: ./smoke-test.sh attack-box:smoke + # No registry, no secrets: a plain local build and its smoke test (check.sh), so pull + # requests from forks run it too. + - run: ./check.sh image build: needs: [scripts, smoke] diff --git a/README.md b/README.md index 444d8aa..42cc47d 100644 --- a/README.md +++ b/README.md @@ -32,11 +32,12 @@ The launcher assembles one `sh` script from these parts, in this order: ## Building and testing ```sh -docker build --pull -t attack-box:local . -./smoke-test.sh attack-box:local +./check.sh # the scripts: the VM set-up's compositions parse, shellcheck +./check.sh image # the image built locally and smoke-tested +./check.sh all # both ``` -The workflow builds and smoke-tests every pull request on amd64 and arm64; a push to `main`, the +The workflow runs the same command: it checks the scripts, and builds and smoke-tests every pull request on amd64 and arm64; a push to `main`, the weekly run or a manual run publishes, only once both pass, then pulls the published digest and smoke-tests it again before pinning it in the launcher. diff --git a/check.sh b/check.sh new file mode 100755 index 0000000..4707b98 --- /dev/null +++ b/check.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env bash +# The attack box's check, the command CI runs (.github/workflows/image.yml) and a contributor runs: +# +# ./check.sh the scripts: the VM set-up's compositions parse, shellcheck passes +# ./check.sh image the image built locally (no registry, no secrets) and smoke-tested +# ./check.sh all both +# +# The VM set-up's parts are fragments of one script (vm/kali.sh defines `$keep`): each composition +# the launcher makes must parse, with the player's account between the toolset and the desktop. +set -euo pipefail +cd "$(dirname "$0")" + +scripts() { + local parts + for parts in "vm/kali.sh vm/toolset.sh" "vm/kali.sh vm/toolset.sh vm/desktop.sh" "vm/kali.sh vm/desktop.sh"; do + # shellcheck disable=SC2086 # the list is the files, split on purpose + if ! cat $parts | sh -n; then echo "check: the VM set-up doesn't parse as $parts" >&2; return 1; fi + done + shellcheck check.sh player-account.sh smoke-test.sh + echo "check: scripts ok" +} + +image() { + docker build --pull -t attack-box:smoke . + ./smoke-test.sh attack-box:smoke + echo "check: image ok" +} + +case "${1:-scripts}" in + scripts) scripts ;; + image) image ;; + all) scripts && image ;; + *) echo "usage: ./check.sh [scripts|image|all]" >&2; exit 2 ;; +esac