From fcb8f965d1426e57dceb2335421e79034a191077 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Tue, 16 Jan 2024 23:29:50 -0700 Subject: [PATCH 1/5] feat: add support for running action within a subdirectory --- entrypoint.sh | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index 1d6748b..b0efb74 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -8,9 +8,20 @@ INPUT_SEPARATOR="${INPUT_SEPARATOR//\\n/%0A}" INPUT_SEPARATOR="${INPUT_SEPARATOR//\\r/%0D}" echo "::group::verify-changed-files" - echo "::debug::Separator: $INPUT_SEPARATOR" +if [[ -n $INPUT_PATH ]]; then + REPO_DIR="$GITHUB_WORKSPACE/$INPUT_PATH" + + echo "Resolving repository path: $REPO_DIR" + if [[ ! -d "$REPO_DIR" ]]; then + echo "::error::Invalid repository path: $REPO_DIR" + echo "::endgroup::" + exit 1 + fi + cd "$REPO_DIR" +fi + GIT_STATUS_EXTRA_ARGS="-u --porcelain" if [[ "$INPUT_MATCH_GITIGNORE_FILES" == "true" ]]; then From 7c6dd7a421ab039a2f385f8d07ad9c09b95479f7 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Tue, 16 Jan 2024 23:34:17 -0700 Subject: [PATCH 2/5] Update action.yml --- action.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/action.yml b/action.yml index 06307f1..8150eec 100644 --- a/action.yml +++ b/action.yml @@ -29,6 +29,10 @@ inputs: description: "Apply sanitization to output filenames before being set as output." required: false default: "true" + path: + description: "Relative path under GITHUB_WORKSPACE to the repository" + required: false + default: '.' outputs: files_changed: @@ -67,6 +71,7 @@ runs: INPUT_FAIL_IF_CHANGED: ${{ inputs.fail-if-changed }} INPUT_FAIL_MSG: ${{ inputs.fail-message }} INPUT_SAFE_OUTPUT: ${{ inputs.safe_output }} + INPUT_PATH: ${{ inputs.path }} branding: icon: file-text From f57fc8b15b7395080475030cf45ec3b79af4fb0f Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Tue, 16 Jan 2024 23:40:59 -0700 Subject: [PATCH 3/5] Update test.yml --- .github/workflows/test.yml | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index cee3c36..b917d19 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -26,13 +26,17 @@ jobs: fail-fast: false matrix: platform: [ubuntu-latest, windows-latest, macos-latest, macos-11, windows-2022] + path: ['.', 'dir1'] steps: - name: Checkout uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 + with: + path: ${{ matrix.path }} - name: Test files has no changes - uses: ./ + uses: ${{ matrix.path }} id: changed_files_not_expected with: + path: ${{ matrix.path }} files: | test/*.txt test/*.sql @@ -44,9 +48,10 @@ jobs: echo "Changed files (Not expected): ${{ steps.changed_files_not_expected.outputs.changed_files }}" exit 1 - name: Test dont fail if not changed - uses: ./ + uses: ${{ matrix.path }} id: changed_files_not_expected_fail with: + path: ${{ matrix.path }} fail-if-changed: true files: | test/*.txt @@ -61,9 +66,10 @@ jobs: printf '%s\n' "323442" "424" >> "test/\$(whoami).txt" shell: bash - name: Test test/new*.txt file has changes - uses: ./ + uses: ${{ matrix.path }} id: changed_files_expected with: + path: ${{ matrix.path }} separator: '\n' files: | test/*.txt @@ -80,10 +86,11 @@ jobs: echo "No Changes found: (Not expected)" exit 1 - name: Test fail if changed - uses: ./ + uses: ${{ matrix.path }} id: changed_files_expected_fail continue-on-error: true with: + path: ${{ matrix.path }} fail-if-changed: true files: | test/*.txt @@ -94,9 +101,10 @@ jobs: run: | echo "New changes" > unstaged.txt - name: Test unstaged file has changes - uses: ./ + uses: ${{ matrix.path }} id: changed_unstaged_files_expected with: + path: ${{ matrix.path }} files: | unstaged.txt - name: Display unstaged changed files @@ -109,9 +117,10 @@ jobs: echo "No Changes found: (Not expected)" exit 1 - name: Test unstaged file changes are ignored - uses: ./ + uses: ${{ matrix.path }} id: changed_unstaged_files_not_expected with: + path: ${{ matrix.path }} files: | !test/new.txt !test/new1.txt @@ -124,9 +133,10 @@ jobs: echo "Changes found: (Not expected)" exit 1 - name: Test unstaged file has changes - uses: ./ + uses: ${{ matrix.path }} id: changed_unstaged2_files_expected with: + path: ${{ matrix.path }} files: | !test/new.txt !test/new1.txt @@ -144,8 +154,10 @@ jobs: rm test/new.txt - name: Test deletion of test/new.txt - uses: ./ + uses: ${{ matrix.path }} id: deleted_file_test + with: + path: ${{ matrix.path }} - name: Show output run: | From 70368a5831a7f92b75e4fc27460a05144196520e Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Thu, 18 Jan 2024 19:23:11 -0700 Subject: [PATCH 4/5] Update test.yml --- .github/workflows/test.yml | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b917d19..cee3c36 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -26,17 +26,13 @@ jobs: fail-fast: false matrix: platform: [ubuntu-latest, windows-latest, macos-latest, macos-11, windows-2022] - path: ['.', 'dir1'] steps: - name: Checkout uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 - with: - path: ${{ matrix.path }} - name: Test files has no changes - uses: ${{ matrix.path }} + uses: ./ id: changed_files_not_expected with: - path: ${{ matrix.path }} files: | test/*.txt test/*.sql @@ -48,10 +44,9 @@ jobs: echo "Changed files (Not expected): ${{ steps.changed_files_not_expected.outputs.changed_files }}" exit 1 - name: Test dont fail if not changed - uses: ${{ matrix.path }} + uses: ./ id: changed_files_not_expected_fail with: - path: ${{ matrix.path }} fail-if-changed: true files: | test/*.txt @@ -66,10 +61,9 @@ jobs: printf '%s\n' "323442" "424" >> "test/\$(whoami).txt" shell: bash - name: Test test/new*.txt file has changes - uses: ${{ matrix.path }} + uses: ./ id: changed_files_expected with: - path: ${{ matrix.path }} separator: '\n' files: | test/*.txt @@ -86,11 +80,10 @@ jobs: echo "No Changes found: (Not expected)" exit 1 - name: Test fail if changed - uses: ${{ matrix.path }} + uses: ./ id: changed_files_expected_fail continue-on-error: true with: - path: ${{ matrix.path }} fail-if-changed: true files: | test/*.txt @@ -101,10 +94,9 @@ jobs: run: | echo "New changes" > unstaged.txt - name: Test unstaged file has changes - uses: ${{ matrix.path }} + uses: ./ id: changed_unstaged_files_expected with: - path: ${{ matrix.path }} files: | unstaged.txt - name: Display unstaged changed files @@ -117,10 +109,9 @@ jobs: echo "No Changes found: (Not expected)" exit 1 - name: Test unstaged file changes are ignored - uses: ${{ matrix.path }} + uses: ./ id: changed_unstaged_files_not_expected with: - path: ${{ matrix.path }} files: | !test/new.txt !test/new1.txt @@ -133,10 +124,9 @@ jobs: echo "Changes found: (Not expected)" exit 1 - name: Test unstaged file has changes - uses: ${{ matrix.path }} + uses: ./ id: changed_unstaged2_files_expected with: - path: ${{ matrix.path }} files: | !test/new.txt !test/new1.txt @@ -154,10 +144,8 @@ jobs: rm test/new.txt - name: Test deletion of test/new.txt - uses: ${{ matrix.path }} + uses: ./ id: deleted_file_test - with: - path: ${{ matrix.path }} - name: Show output run: | From 14705816441fdb6f2c1a5fe7bae88817b5d3c7ac Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Thu, 18 Jan 2024 19:29:53 -0700 Subject: [PATCH 5/5] Update test.yml --- .github/workflows/test.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index cee3c36..50618ac 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -65,11 +65,10 @@ jobs: id: changed_files_expected with: separator: '\n' + path: test files: | - test/*.txt - test/*.sql - test/**/*.txt - test/**/*.sql + *.{txt,sql} + **/*.{txt,sql} - name: Display changed files if: steps.changed_files_expected.outputs.files_changed == 'true' run: |