3
0
Fork 0
mirror of https://github.com/tj-actions/changed-files synced 2025-01-29 03:34:50 +00:00

Support retrieving changed files between the last remote commit and the current HEAD for push events (#236)

* Update entrypoint.sh

* Update entrypoint.sh

* Update entrypoint.sh

* Update entrypoint.sh

* Update entrypoint.sh

* Update entrypoint.sh

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Update entrypoint.sh

* Update entrypoint.sh

* Update entrypoint.sh

* Update entrypoint.sh

* Create new.yml

* Empty commit

* Empty commit 2

* Empty commit 3

* Updated the use the last remote commit

* Update entrypoint.sh

* Update README.md

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
This commit is contained in:
Tonye Jack 2021-10-30 15:55:58 -04:00 committed by GitHub
parent e11c6b4fe2
commit 71583c0a06
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 5 deletions

View file

@ -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: ./

View file

@ -111,6 +111,7 @@ jobs:
| sha | `string` | `true` | `${{ github.sha }}` | Specify a different <br> commit SHA <br> used for <br> comparing changes |
| files\_from\_source\_file | `string` | `false` | | Source file <br> used to populate <br> the files input |
| path | `string` | `false` | | Relative path under <br> `GITHUB_WORKSPACE` <br> to the repository |
| since_last_remote_commit | `string` | `false` | `false` | Use the last commit on the remote <br> branch as the `base_sha` for push event.<br> (Defaults to the previous commit). |
## Example

View file

@ -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_<VARIABLE_NAME> 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 }}

View file

@ -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"