VERSION 0.8

FROM --pass-args ..+base

IMPORT .. AS tests

PROJECT earthly-technologies/core

WORKDIR /test

test-all:
    BUILD +test-group1
    BUILD +test-group2
    BUILD +test-group3

test-group1:
    BUILD +test-files
    BUILD +test-with-subdir
    BUILD +test-requires-project
    BUILD +test-wait
    BUILD +test-if-else
    BUILD +test-for-in
    BUILD +test-copy-glob
    BUILD +test-expand-args
    BUILD +test-build-args
    BUILD +test-pass-args

test-group2:
    BUILD +test-copy-target-args
    BUILD +test-arg-matrix
    BUILD +test-try-catch
    BUILD +test-push
    BUILD +test-no-cache
    BUILD +test-shell-out
    BUILD +test-copy-if-exists
    BUILD +test-remote-targets
    BUILD +test-from-dockerfile
    BUILD +test-import

test-group3:
    BUILD +test-copy-target-args-quoted
    BUILD +test-build-flag
    BUILD +test-flag-conflict
    BUILD +test-init-failure
    BUILD +test-arg-change
    BUILD +test-expand-let
    BUILD +test-copy-target-let
    BUILD +test-expand-set
    BUILD +test-copy-target-set
	BUILD +test-multi-platform-build-failure

test-files:
    RUN echo hello > my-file
    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=simple.earth --target=+mytarget --output_contains="I was run"
    RUN if ! grep "SSB3YXMgcnVuCg" earthly.output >/dev/null; then echo "base64 encoded RUN echo command is missing from output" && exit 1; fi

    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=simple.earth --target=+mytarget --output_does_not_contain="I was run"
    RUN if grep "SSB3YXMgcnVuCg" earthly.output >/dev/null; then echo "base64 encoded RUN echo command should not have been displayed" && exit 1; fi

    # change the input file, and validate it runs
    RUN echo world > my-file
    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=simple.earth --target=+mytarget --output_contains="I was run"
    RUN if ! grep "SSB3YXMgcnVuCg" earthly.output >/dev/null; then echo "base64 encoded RUN echo command is missing from output" && exit 1; fi

test-with-subdir:
    COPY subdir.earth Earthfile
    RUN mkdir subdir
    COPY subdir/test.earth subdir/Earthfile
    RUN echo abc > subdir/a-test-file
    DO --pass-args +RUN_EARTHLY_ARGS --target=+all --output_contains="0bee89b07a248e27c83fc3d5951213c1"
    DO --pass-args +RUN_EARTHLY_ARGS --target=+all --output_does_not_contain="0bee89b07a248e27c83fc3d5951213c1" --output_contains="Target .* has already been run. Skipping."

    RUN echo 123 > subdir/a-test-file
    DO --pass-args +RUN_EARTHLY_ARGS --target=+all --output_contains="ba1f2511fc30423bdbb183fe33f3dd0f"
    DO --pass-args +RUN_EARTHLY_ARGS --target=+all --output_does_not_contain="ba1f2511fc30423bdbb183fe33f3dd0f" --output_contains="Target .* has already been run. Skipping."

test-requires-project:
    RUN echo hello > my-file
    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=no-project.earth --target=+no-project --output_contains="I was run"

    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=no-project.earth --target=+no-project --extra_args="--org earthly-technologies --auto-skip-db-path=" --output_contains="I was run"

test-wait:
    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=wait.earth --target=+test --output_contains="not skipped"
    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=wait.earth --target=+test --output_contains="Target .* has already been run. Skipping."

test-if-else:
    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=if-else.earth --target=+test --output_contains="condition ok"
    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=if-else.earth --target=+test --output_contains="Target .* has already been run. Skipping."

    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=if-else.earth --target=+test-eval --output_contains="condition ok"
    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=if-else.earth --target=+test-eval --output_contains="Target .* has already been run. Skipping."

    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=if-else.earth --target=+test-eval-2 --output_contains="condition ok"
    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=if-else.earth --target=+test-eval-2 --output_contains="Target .* has already been run. Skipping."

test-for-in:
    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=for.earth --target=+test --output_contains="hello 3"
    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=for.earth --target=+test --output_contains="Target .* has already been run. Skipping."

    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=for.earth --target=+test-vars --output_contains="hello foo"
    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=for.earth --target=+test-vars --output_contains="Target .* has already been run. Skipping."

    RUN sed -i s/baz/boo/g Earthfile

    DO --pass-args +RUN_EARTHLY_ARGS --target=+test-vars --output_contains="hello foo"
    DO --pass-args +RUN_EARTHLY_ARGS --target=+test-vars --output_contains="Target .* has already been run. Skipping."

test-copy-glob:
    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=copy-glob.earth --should_fail=true --target=+globstar --output_contains="globstar (\*\*) not supported"

    COPY --dir glob .

    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=copy-glob.earth --target=+dir --output_contains="glob/subdir/hello.txt"
    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=copy-glob.earth --target=+dir --output_contains="Target .* has already been run. Skipping."

    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=copy-glob.earth --target=+glob --output_contains="glob/subdir/hello.txt"
    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=copy-glob.earth --target=+glob --output_contains="Target .* has already been run. Skipping."

    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=copy-glob.earth --target=+glob-mid-path --output_contains="glob/subdir/hello.txt"
    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=copy-glob.earth --target=+glob-mid-path --output_contains="Target .* has already been run. Skipping."

    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=copy-glob.earth --target=+glob-dir --output_contains="glob/subdir/hello.txt"
    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=copy-glob.earth --target=+glob-dir --output_contains="Target .* has already been run. Skipping."

    RUN echo data > glob/subdir/new.txt
    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=copy-glob.earth --target=+glob-dir --output_contains="glob/subdir/new.txt"

test-expand-args:
    COPY glob/hello.txt .
    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=expand-args.earth --target=+basic --output_contains="COPY hello.txt"
    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=expand-args.earth --target=+basic --output_contains="Target .* has already been run. Skipping."

    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=expand-args.earth --target=+dynamic-build --output_contains="dynamic target ok"
    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=expand-args.earth --target=+dynamic-build --output_contains="Target .* has already been run. Skipping."

    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=expand-args.earth --target=+dynamic-arg --output_contains="hello bar"
    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=expand-args.earth --target=+dynamic-arg --output_contains="Target .* has already been run. Skipping."

test-build-args:
    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=expand-args.earth --target=+build-args --output_contains="hello 3 4"
    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=expand-args.earth --target=+build-args --output_contains="Target .* has already been run. Skipping."

    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=expand-args.earth --target=+build-args-2 --post_command="--foo=5 --bar=6" --output_contains="hello 5 6"
    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=expand-args.earth --target=+build-args-2 --post_command="--foo=5 --bar=6" --output_contains="Target .* has already been run. Skipping."
    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=expand-args.earth --target=+build-args-2 --post_command="--foo=5 --bar=7" --output_does_not_contain="Target .* has already been run. Skipping."

test-pass-args:
    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=expand-args.earth --target=+pass-args --post_command="--foo=3 --bar=4" --output_contains="hello 3 4"
    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=expand-args.earth --target=+pass-args --post_command="--foo=3 --bar=4" --output_contains="Target .* has already been run. Skipping."
    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=expand-args.earth --target=+pass-args --post_command="--foo=3 --bar=5" --output_does_not_contain="Target .* has already been run. Skipping."

test-copy-target-args:
    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=expand-args.earth --target=+copy-target-args --output_contains="+copy-target-args | hello"
    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=expand-args.earth --target=+copy-target-args --output_contains="Target .* has already been run. Skipping."

    RUN sed -i s/--foo=hello/--foo=changed/g Earthfile

    DO --pass-args +RUN_EARTHLY_ARGS --target=+copy-target-args --output_contains="+copy-target-args | changed"
    DO --pass-args +RUN_EARTHLY_ARGS --target=+copy-target-args --output_contains="Target .* has already been run. Skipping."

    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=expand-args.earth --target=+copy-target-dynamic --output_contains="+copy-target-dynamic | goodbye"
    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=expand-args.earth --target=+copy-target-dynamic --output_contains="Target .* has already been run. Skipping."

    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=expand-args.earth --target=+copy-target-dynamic-2 --output_contains="+copy-target-dynamic-2 | foobar"
    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=expand-args.earth --target=+copy-target-dynamic-2 --output_contains="Target .* has already been run. Skipping."

test-copy-target-args-quoted:
    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=expand-args.earth --target=+copy-target-args-quoted --output_contains="hello world"
    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=expand-args.earth --target=+copy-target-args-quoted --output_contains="Target .* has already been run. Skipping."

test-arg-matrix:
    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=matrix.earth --target=+arg-matrix --output_contains="Hello Bob. From Todd"
    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=matrix.earth --target=+arg-matrix --output_contains="Target .* has already been run. Skipping."

    RUN sed -i s/Bill/Sam/g Earthfile

    DO --pass-args +RUN_EARTHLY_ARGS --target=+arg-matrix --output_contains="Hello Sam. From Todd"
    DO --pass-args +RUN_EARTHLY_ARGS --target=+arg-matrix --output_contains="Target .* has already been run. Skipping."

test-expand-let:
    COPY glob/hello.txt .
    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=expand-let.earth --target=+basic --output_contains="COPY hello.txt"
    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=expand-let.earth --target=+basic --output_contains="Target .* has already been run. Skipping."

    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=expand-let.earth --target=+dynamic-build --output_contains="dynamic target ok"
    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=expand-let.earth --target=+dynamic-build --output_contains="Target .* has already been run. Skipping."

    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=expand-let.earth --target=+dynamic-arg --output_contains="hello bar"
    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=expand-let.earth --target=+dynamic-arg --output_contains="Target .* has already been run. Skipping."

test-copy-target-let:
    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=expand-let.earth --target=+copy-target-dynamic --output_contains="+copy-target-dynamic | goodbye"
    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=expand-let.earth --target=+copy-target-dynamic --output_contains="Target .* has already been run. Skipping."

    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=expand-let.earth --target=+copy-target-dynamic-2 --output_contains="+copy-target-dynamic-2 | foobar"
    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=expand-let.earth --target=+copy-target-dynamic-2 --output_contains="Target .* has already been run. Skipping."

test-expand-set:
    COPY glob/hello.txt .
    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=expand-set.earth --target=+basic --output_contains="COPY hello.txt"
    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=expand-set.earth --target=+basic --output_contains="Target .* has already been run. Skipping."

    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=expand-set.earth --target=+dynamic-build --output_contains="dynamic target ok"
    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=expand-set.earth --target=+dynamic-build --output_contains="Target .* has already been run. Skipping."

    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=expand-set.earth --target=+dynamic-arg --output_contains="hello bar"
    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=expand-set.earth --target=+dynamic-arg --output_contains="Target .* has already been run. Skipping."

test-copy-target-set:
    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=expand-set.earth --target=+copy-target-dynamic --output_contains="+copy-target-dynamic | goodbye"
    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=expand-set.earth --target=+copy-target-dynamic --output_contains="Target .* has already been run. Skipping."

    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=expand-set.earth --target=+copy-target-dynamic-2 --output_contains="+copy-target-dynamic-2 | foobar"
    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=expand-set.earth --target=+copy-target-dynamic-2 --output_contains="Target .* has already been run. Skipping."

test-try-catch:
    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=try-catch.earth --target=+basic --output_contains="Artifact +basic/hello.txt output as hello.txt"
    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=try-catch.earth --target=+basic --output_contains="Target .* has already been run. Skipping."

test-no-cache:
    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=simple.earth --target=+no-cache --should_fail=true --extra_args="--no-cache" --output_contains="no-cache cannot be used"
    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=simple.earth --target=+no-cache --should_fail=true --extra_args="--no-cache" --output_does_not_contain="Target .* has already been run. Skipping."

test-push:
    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=simple.earth --target=+simple --extra_args="--push" --output_contains="hello"
    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=simple.earth --target=+simple --extra_args="--push" --output_contains="Target .* has already been run. Skipping."

test-shell-out:
    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=shell-out.earth --target=+shell-out
    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=shell-out.earth --target=+shell-out --output_contains="Target .* has already been run. Skipping."

    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=shell-out.earth --target=+shell-out-target --should_fail=true --output_contains="dynamic target"
    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=shell-out.earth --target=+shell-out-target-2 --should_fail=true --output_contains="dynamic target"

    RUN echo "foo" > my-file

    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=shell-out.earth --target=+shell-out-copy --should_fail=true --output_contains="dynamic COPY source"

test-copy-if-exists:
    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=simple.earth --target=+copy-if-exists
    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=simple.earth --target=+copy-if-exists --output_contains="Target .* has already been run. Skipping."

    RUN echo "foo" > my-file

    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=simple.earth --target=+copy-if-exists --output_does_not_contain="Target .* has already been run. Skipping."

test-remote-targets:
    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=remote-target.earth --target=+valid-copy
    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=remote-target.earth --target=+valid-copy --output_contains="Target .* has already been run. Skipping."

    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=remote-target.earth --target=+valid-copy-sha
    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=remote-target.earth --target=+valid-copy-sha --output_contains="Target .* has already been run. Skipping."

    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=remote-target.earth --target=+valid-from
    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=remote-target.earth --target=+valid-from --output_contains="Target .* has already been run. Skipping."

    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=remote-target.earth --target=+valid-from-sha
    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=remote-target.earth --target=+valid-from-sha --output_contains="Target .* has already been run. Skipping."

    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=remote-target.earth --target=+invalid-copy-branch --should_fail=true --output_contains="complete Git SHA or an explicit tag"

    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=remote-target.earth --target=+valid-build
    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=remote-target.earth --target=+valid-build --output_contains="Target .* has already been run. Skipping."

    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=remote-target.earth --target=+invalid-build --should_fail=true --output_contains="complete Git SHA or an explicit tag"

test-from-dockerfile:
    RUN mkdir /dist
    COPY Dockerfile /dist
    RUN echo "foo" > /dist/my-file

    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=from-dockerfile.earth --target=+local
    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=from-dockerfile.earth --target=+local --output_contains="Target .* has already been run. Skipping."

    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=from-dockerfile.earth --target=+local-target
    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=from-dockerfile.earth --target=+local-target --output_contains="Target .* has already been run. Skipping."

    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=from-dockerfile.earth --target=+remote
    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=from-dockerfile.earth --target=+remote --output_contains="Target .* has already been run. Skipping."

test-import:
    COPY --dir imported .

    RUN echo "hello" > imported/my-file

    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=import.earth --target=+basic
    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=import.earth --target=+basic --output_contains="Target .* has already been run. Skipping."

    RUN echo "bye-bye" > imported/my-file

    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=import.earth --target=+basic --output_does_not_contain="Target .* has already been run. Skipping."

    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=import.earth --target=+remote
    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=import.earth --target=+remote --output_contains="Target .* has already been run. Skipping."

    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=import.earth --target=+global
    DO --pass-args +RUN_EARTHLY_ARGS --earthfile=import.earth --target=+global --output_contains="Target .* has already been run. Skipping."

test-build-flag:
    DO --pass-args tests+RUN_EARTHLY --extra_args="--auto-skip-db-path=test.db" --earthfile=build-flag.earth --target=+basic
    RUN cat earthly.output | acbgrep 'hello from a'
    RUN cat earthly.output | acbgrep 'hello from b'

    DO --pass-args tests+RUN_EARTHLY --extra_args="--auto-skip-db-path=test.db" --earthfile=build-flag.earth --target=+basic
    RUN cat earthly.output | acbgrep 'hello from a'
    RUN cat earthly.output | acbgrep -v 'hello from b'
    RUN cat earthly.output | acbgrep 'Target +b .* has already been run'

    DO --pass-args tests+RUN_EARTHLY --extra_args="--auto-skip-db-path=test.db" --earthfile=build-flag.earth --target=+remote
    RUN cat earthly.output | acbgrep 'Hello World'
    RUN cat earthly.output | acbgrep 'hello from b'

    DO --pass-args tests+RUN_EARTHLY --extra_args="--auto-skip-db-path=test.db" --earthfile=build-flag.earth --target=+remote
    RUN cat earthly.output | acbgrep -v 'Hello World'
    RUN cat earthly.output | acbgrep 'Target github.com/earthly/test-remote:6accddaba346aeda062ab47bae62e65dcdcc513f+basic .* has already been run'
    RUN cat earthly.output | acbgrep 'hello from b'

test-multi-platform-build-failure:
    COPY build-multiplatform-failure.earth Earthfile
    DO --pass-args tests+RUN_EARTHLY --extra_args="--auto-skip-db-path=test.db" --target=+test --should_fail=true
    # test that the first run didn't write to hash entry to test.db; running a second time should also fail
    DO --pass-args tests+RUN_EARTHLY --extra_args="--auto-skip-db-path=test.db" --target=+test --should_fail=true

test-flag-conflict:
    DO --pass-args tests+RUN_EARTHLY --extra_args="--auto-skip-db-path=test.db --auto-skip --no-auto-skip" \
                                     --earthfile=build-flag.earth --target=+basic --should_fail=true \
                                     --output_contains="\-\-no-auto-skip cannot be used with \-\-auto-skip"

test-init-failure:
    DO --pass-args tests+RUN_EARTHLY --extra_args="--auto-skip-db-path=/tmp --auto-skip" \
                                     --earthfile=build-flag.earth --target=+basic \
                                     --output_contains="Failed to initialize auto-skip database"

test-arg-change:
    # These 2 distinct versions are pinned to ensure a version argument change
    # triggers auto-skip cache-busting.
    ARG V1="3.18.6"
    ARG V2="3.19.1"
    RUN acbtest "$V1" != "$V2" # Ensure that the values are kept distinct.
    COPY arg-change.earth Earthfile
    RUN sed -i "s/<VERSION>/$V1/g" Earthfile
    DO --pass-args tests+RUN_EARTHLY --extra_args="--auto-skip-db-path=test.db" --target=+expand-args-from --output_contains="VERSION_ID=$V1"
    RUN sed -i "s/$V1/$V2/g" Earthfile
    DO --pass-args tests+RUN_EARTHLY --extra_args="--auto-skip-db-path=test.db" --target=+expand-args-from --output_contains="VERSION_ID=$V2"

RUN_EARTHLY_ARGS:
    FUNCTION
    ARG extra_args
    DO --pass-args tests+RUN_EARTHLY \
        --extra_args="--auto-skip --auto-skip-db-path=test.db $extra_args"
