From a8328146f2258b0c1d2e36a8493097aa7fa248fd Mon Sep 17 00:00:00 2001 From: Zach Taylor Date: Mon, 15 Apr 2019 12:40:35 -0500 Subject: [PATCH 1/3] Clean build directory so old artifacts don't get picked up --- hooks/checkout | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hooks/checkout b/hooks/checkout index cb43ab4..46a942b 100755 --- a/hooks/checkout +++ b/hooks/checkout @@ -2,4 +2,5 @@ set -euo pipefail -echo "--- Skipping checkout" +echo "--- Removing any files from previous builds" +rm -rf * From ce1070c2c234dc52484685a7bb4ed6bca3d78816 Mon Sep 17 00:00:00 2001 From: Zach Taylor Date: Fri, 26 Apr 2019 15:10:30 -0500 Subject: [PATCH 2/3] Better glob syntax according to shellcheck --- hooks/checkout | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hooks/checkout b/hooks/checkout index 46a942b..1d86fcc 100755 --- a/hooks/checkout +++ b/hooks/checkout @@ -3,4 +3,4 @@ set -euo pipefail echo "--- Removing any files from previous builds" -rm -rf * +rm -rf ./* From 1424d0d60c40304a127d3be22b09aaffd619bef1 Mon Sep 17 00:00:00 2001 From: Zach Taylor Date: Fri, 26 Apr 2019 15:15:51 -0500 Subject: [PATCH 3/3] Fix tests and add example --- hooks/checkout | 3 ++- tests/checkout.bats | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/hooks/checkout b/hooks/checkout index 1d86fcc..17af985 100755 --- a/hooks/checkout +++ b/hooks/checkout @@ -2,5 +2,6 @@ set -euo pipefail -echo "--- Removing any files from previous builds" +echo "--- Skipping checkout" +echo "Removing any old artifacts" rm -rf ./* diff --git a/tests/checkout.bats b/tests/checkout.bats index 0b3a946..4da27ac 100644 --- a/tests/checkout.bats +++ b/tests/checkout.bats @@ -23,6 +23,17 @@ post_checkout_hook="$PWD/hooks/post-checkout" assert_output --partial "Skipping checkout" } +@test "Removes old artifacts { + export BUILDKITE_BUILD_CHECKOUT_PATH=$tmp_dir + cd "$BUILDKITE_BUILD_CHECKOUT_PATH" + touch some_old_artifact + + run "$checkout_hook" + + assert_success + refute [ -f some_old_artifact ] +} + @test "Updates checkout directory when 'cd' is given" { export BUILDKITE_BUILD_CHECKOUT_PATH=$tmp_dir export BUILDKITE_PLUGIN_SKIP_CHECKOUT_CD="/var"