diff --git a/actions/github/should-run/action.yml b/actions/github/should-run/action.yml index a891d34c3a..491c9779d3 100644 --- a/actions/github/should-run/action.yml +++ b/actions/github/should-run/action.yml @@ -10,9 +10,12 @@ inputs: default: ${{ github.base_ref }} checkout-repo: description: > - Boolean flag to control whether the action should check out the repo - default: true - type: boolean + Whether this action should perform its own full (fetch-depth: 0) checkout. + Defaults to "false"; the caller is expected to have already checked out + the repository with sufficient history for the diff. Set to "true" to have + this action perform its own checkout (this will clean the working tree and + remove any untracked files produced by earlier job steps). + default: "false" config: description: > YAML paths configuration. Can be a list of paths, or an object with keys like 'paths' and 'push'. @@ -38,7 +41,7 @@ runs: using: composite steps: - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 - if: inputs.checkout-repo + if: inputs.checkout-repo == 'true' with: fetch-depth: 0 - uses: envoyproxy/toolshed/actions/bson@7f2aff965c314c8a80a09a48f61552b1a3337af1 diff --git a/actions/github/should-run/tests/checkout-repo-false-preserves-tree.test.yml b/actions/github/should-run/tests/checkout-repo-false-preserves-tree.test.yml new file mode 100644 index 0000000000..8b11a59be2 --- /dev/null +++ b/actions/github/should-run/tests/checkout-repo-false-preserves-tree.test.yml @@ -0,0 +1,22 @@ +uses: ./actions/github/should-run +id: should-run +with: + checkout-repo: "false" + config: | + paths: + - some/path + +before: +- shell: bash + run: | + echo "marker-content" > .should-run-untracked-marker + +after: +- shell: bash + run: | + if [[ ! -f ".should-run-untracked-marker" ]]; then + echo "fail:Untracked marker file was removed — checkout ran despite checkout-repo: false" >> "$TEST_OUTPUT" + else + echo "success:Untracked marker file preserved — no checkout occurred with checkout-repo: false" >> "$TEST_OUTPUT" + fi + rm -f .should-run-untracked-marker diff --git a/actions/github/should-run/tests/default-does-not-checkout.test.yml b/actions/github/should-run/tests/default-does-not-checkout.test.yml new file mode 100644 index 0000000000..2a973b1ff0 --- /dev/null +++ b/actions/github/should-run/tests/default-does-not-checkout.test.yml @@ -0,0 +1,21 @@ +uses: ./actions/github/should-run +id: should-run +with: + config: | + paths: + - some/path + +before: +- shell: bash + run: | + echo "marker-content" > .should-run-default-marker + +after: +- shell: bash + run: | + if [[ ! -f ".should-run-default-marker" ]]; then + echo "fail:Untracked marker file was removed — checkout ran with default checkout-repo" >> "$TEST_OUTPUT" + else + echo "success:Untracked marker file preserved — default checkout-repo does not checkout" >> "$TEST_OUTPUT" + fi + rm -f .should-run-default-marker diff --git a/actions/github/should-run/tests/paths-match.test.yml b/actions/github/should-run/tests/paths-match.test.yml new file mode 100644 index 0000000000..5bf1e5b636 --- /dev/null +++ b/actions/github/should-run/tests/paths-match.test.yml @@ -0,0 +1,29 @@ +uses: ./actions/github/should-run +id: should-run +with: + checkout-repo: "false" + config: | + paths: + - tmp-should-run-test/** + +before: +- shell: bash + run: | + mkdir -p tmp-should-run-test + echo "test" > tmp-should-run-test/file.txt + git add tmp-should-run-test/file.txt + git -c user.name="Test" -c user.email="test@test.com" commit -m "tmp: add test file for should-run paths test" + +after: +- shell: bash + run: | + RUN_OUTPUT='${{ steps.should-run.outputs.run }}' + if [[ "$RUN_OUTPUT" != "true" ]]; then + echo "fail:Expected run=true for matching path, got '$RUN_OUTPUT'" >> "$TEST_OUTPUT" + else + echo "success:run=true for matching path tmp-should-run-test/**" >> "$TEST_OUTPUT" + fi + # Clean up the temporary commit and file + git reset HEAD~1 --soft + git restore --staged tmp-should-run-test/file.txt || true + rm -rf tmp-should-run-test