end-to-end/actions/example-force-rebuild/run.sh
Earl Warren d29439c5f7
fix: actions: refactor force-rebuild tests to use a remote action (#991)
The local actions are always rebuilt with a random tag and cannot be used to verify the force_rebuild setting is working.

Reviewed-on: https://code.forgejo.org/forgejo/end-to-end/pulls/991
Reviewed-by: Michael Kriese <michael.kriese@gmx.de>
Co-authored-by: Earl Warren <contact@earl-warren.org>
Co-committed-by: Earl Warren <contact@earl-warren.org>
2025-09-01 17:14:24 +00:00

69 lines
1.6 KiB
Bash
Executable file

TMPDIR=$(mktemp -d)
trap "rm -fr $TMPDIR" EXIT
function setup_with_rebuild() {
FORGEJO_RUNNER_CONFIG=$EXAMPLE_DIR/runner-config-with-rebuild.yml forgejo-runner.sh reload
}
function setup_without_rebuild() {
FORGEJO_RUNNER_CONFIG=$EXAMPLE_DIR/runner-config-without-rebuild.yml forgejo-runner.sh reload
}
function run() {
local dir="$1"
local expected="$2"
local repo=root/example-$example
forgejo-test-helper.sh push_workflow $dir $url root example-$example setup-forgejo $token
sha=$(forgejo-test-helper.sh branch_tip $url $repo main)
forgejo-test-helper.sh wait_$expected $url $repo $sha
}
function get_remote_image() {
docker image ls --format='{{ .Repository }}' | grep '^runner-remote-docker-action'
}
function remove_remote_images() {
docker image ls --format='{{ .Repository }}' | grep '^runner-remote-docker-action' | while read image; do
docker rmi $image
done
}
function was_built() {
grep --quiet 'docker build -t runner-remote-docker-action' $FORGEJO_RUNNER_LOGS
}
function main() {
local dir=$TMPDIR/repository
cp -a $EXAMPLE_DIR $dir
remove_remote_images
:
: Run one
:
setup_without_rebuild
run $dir success
local image="$(get_remote_image)"
test "$image"
was_built
:
: Run two: verify the image was not rebuilt
:
setup_without_rebuild # resets the logs
run $dir success
test "$image" = "$(get_remote_image)"
! was_built
:
: Run two: verify the image was rebuilt and
: the image name stayed the same
:
setup_with_rebuild
run $dir success
test "$image" = "$(get_remote_image)"
was_built
}
main