diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index eace0cf4..bf84bd93 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -314,7 +314,7 @@ jobs: - name: Verify any_changed from source files if: | ( - !contains(steps.changed-files-specific-source-file.outputs.all_modified_files, 'action.yml') && + !contains(steps.changed-files-specific-source-file.outputs.all_modified_files, 'action.yml') && !contains(steps.changed-files-specific-source-file.outputs.all_modified_files, '.github/workflows/test.yml') && !contains(steps.changed-files-specific-source-file.outputs.all_modified_files, '.github/workflows/rebase.yml') ) @@ -388,6 +388,16 @@ jobs: branch: ${{ steps.branch-name.outputs.base_ref_branch }} workflow_id: 'test.yml' github_token: ${{ secrets.GITHUB_TOKEN }} + - name: Run changed-files with since_last_remote_commit set to true + id: changed-files-since-last-remote-commit + uses: ./ + with: + since_last_remote_commit: 'true' + - name: Show output + run: | + echo '${{ toJSON(steps.changed-files-since-last-remote-commit.outputs) }}' + shell: + bash - name: Run changed-files with a custom base sha id: changed-files-custom-base-sha uses: ./ diff --git a/README.md b/README.md index 6cf1b645..fd6c3c8d 100644 --- a/README.md +++ b/README.md @@ -111,6 +111,7 @@ jobs: | sha | `string` | `true` | `${{ github.sha }}` | Specify a different
commit SHA
used for
comparing changes | | files\_from\_source\_file | `string` | `false` | | Source file
used to populate
the files input | | path | `string` | `false` | | Relative path under
`GITHUB_WORKSPACE`
to the repository | +| since_last_remote_commit | `string` | `false` | `false` | Use the last commit on the remote
branch as the `base_sha` for push event.
(Defaults to the previous commit). | ## Example diff --git a/action.yml b/action.yml index c16bbfc6..f69167b5 100644 --- a/action.yml +++ b/action.yml @@ -26,6 +26,10 @@ inputs: base_sha: description: 'Specify a base commit SHA on used for comparing changes' required: false + since_last_remote_commit: + description: 'Use the last commit on the remote branch as the base_sha for push event.' + required: false + default: 'false' path: description: 'Specify a relative path under $GITHUB_WORKSPACE to locate the repository' required: false @@ -90,6 +94,14 @@ runs: env: INPUT_FILES: ${{ inputs.files }} INPUT_FILES_FROM_SOURCE_FILE: ${{ inputs.files_from_source_file }} + - run: | + if [[ -n "${{ inputs.base_sha }}" ]]; then + echo "::set-output name=base_sha::${{ inputs.base_sha }}" + elif [[ "${{ github.event_name }}" == "push" && -z "${{ inputs.base_sha }}" && "${{ inputs.since_last_remote_commit }}" == "true" ]]; then + echo "::set-output name=base_sha::${{ github.event.before }}" + fi + id: base-sha + shell: bash - run: | bash $GITHUB_ACTION_PATH/entrypoint.sh id: changed-files @@ -101,7 +113,7 @@ runs: # INPUT_ is not available in Composite run steps # https://github.community/t/input-variable-name-is-not-available-in-composite-run-steps/127611 INPUT_SHA: ${{ inputs.sha }} - INPUT_BASE_SHA: ${{ inputs.base_sha }} + INPUT_BASE_SHA: ${{ steps.base-sha.outputs.base_sha }} INPUT_TOKEN: ${{ inputs.token }} INPUT_FILES: ${{ steps.source-input-files.outputs.files }} INPUT_SEPARATOR: ${{ inputs.separator }} diff --git a/entrypoint.sh b/entrypoint.sh index 60fbc71d..fe254ee3 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -44,13 +44,14 @@ if [[ $exit_status -ne 0 ]]; then fi if [[ -z $GITHUB_BASE_REF ]]; then + TARGET_BRANCH=${GITHUB_REF/refs\/heads\//} + CURRENT_BRANCH=$TARGET_BRANCH + if [[ -z $INPUT_BASE_SHA ]]; then PREVIOUS_SHA=$(git rev-parse HEAD^1 2>&1) && exit_status=$? || exit_status=$? else - PREVIOUS_SHA=$INPUT_BASE_SHA + PREVIOUS_SHA=$INPUT_BASE_SHA && exit_status=$? || exit_status=$? fi - TARGET_BRANCH=${GITHUB_REF/refs\/heads\//} - CURRENT_BRANCH=$TARGET_BRANCH if [[ $exit_status -ne 0 ]]; then echo "::warning::Unable to determine the previous commit sha"