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:
parent
e11c6b4fe2
commit
71583c0a06
10
.github/workflows/test.yml
vendored
10
.github/workflows/test.yml
vendored
@ -388,6 +388,16 @@ jobs:
|
|||||||
branch: ${{ steps.branch-name.outputs.base_ref_branch }}
|
branch: ${{ steps.branch-name.outputs.base_ref_branch }}
|
||||||
workflow_id: 'test.yml'
|
workflow_id: 'test.yml'
|
||||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
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
|
- name: Run changed-files with a custom base sha
|
||||||
id: changed-files-custom-base-sha
|
id: changed-files-custom-base-sha
|
||||||
uses: ./
|
uses: ./
|
||||||
|
@ -111,6 +111,7 @@ jobs:
|
|||||||
| sha | `string` | `true` | `${{ github.sha }}` | Specify a different <br> commit SHA <br> used for <br> comparing changes |
|
| 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 |
|
| 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 |
|
| 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
|
## Example
|
||||||
|
|
||||||
|
14
action.yml
14
action.yml
@ -26,6 +26,10 @@ inputs:
|
|||||||
base_sha:
|
base_sha:
|
||||||
description: 'Specify a base commit SHA on used for comparing changes'
|
description: 'Specify a base commit SHA on used for comparing changes'
|
||||||
required: false
|
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:
|
path:
|
||||||
description: 'Specify a relative path under $GITHUB_WORKSPACE to locate the repository'
|
description: 'Specify a relative path under $GITHUB_WORKSPACE to locate the repository'
|
||||||
required: false
|
required: false
|
||||||
@ -90,6 +94,14 @@ runs:
|
|||||||
env:
|
env:
|
||||||
INPUT_FILES: ${{ inputs.files }}
|
INPUT_FILES: ${{ inputs.files }}
|
||||||
INPUT_FILES_FROM_SOURCE_FILE: ${{ inputs.files_from_source_file }}
|
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: |
|
- run: |
|
||||||
bash $GITHUB_ACTION_PATH/entrypoint.sh
|
bash $GITHUB_ACTION_PATH/entrypoint.sh
|
||||||
id: changed-files
|
id: changed-files
|
||||||
@ -101,7 +113,7 @@ runs:
|
|||||||
# INPUT_<VARIABLE_NAME> is not available in Composite run steps
|
# 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
|
# https://github.community/t/input-variable-name-is-not-available-in-composite-run-steps/127611
|
||||||
INPUT_SHA: ${{ inputs.sha }}
|
INPUT_SHA: ${{ inputs.sha }}
|
||||||
INPUT_BASE_SHA: ${{ inputs.base_sha }}
|
INPUT_BASE_SHA: ${{ steps.base-sha.outputs.base_sha }}
|
||||||
INPUT_TOKEN: ${{ inputs.token }}
|
INPUT_TOKEN: ${{ inputs.token }}
|
||||||
INPUT_FILES: ${{ steps.source-input-files.outputs.files }}
|
INPUT_FILES: ${{ steps.source-input-files.outputs.files }}
|
||||||
INPUT_SEPARATOR: ${{ inputs.separator }}
|
INPUT_SEPARATOR: ${{ inputs.separator }}
|
||||||
|
@ -44,13 +44,14 @@ if [[ $exit_status -ne 0 ]]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -z $GITHUB_BASE_REF ]]; then
|
if [[ -z $GITHUB_BASE_REF ]]; then
|
||||||
|
TARGET_BRANCH=${GITHUB_REF/refs\/heads\//}
|
||||||
|
CURRENT_BRANCH=$TARGET_BRANCH
|
||||||
|
|
||||||
if [[ -z $INPUT_BASE_SHA ]]; then
|
if [[ -z $INPUT_BASE_SHA ]]; then
|
||||||
PREVIOUS_SHA=$(git rev-parse HEAD^1 2>&1) && exit_status=$? || exit_status=$?
|
PREVIOUS_SHA=$(git rev-parse HEAD^1 2>&1) && exit_status=$? || exit_status=$?
|
||||||
else
|
else
|
||||||
PREVIOUS_SHA=$INPUT_BASE_SHA
|
PREVIOUS_SHA=$INPUT_BASE_SHA && exit_status=$? || exit_status=$?
|
||||||
fi
|
fi
|
||||||
TARGET_BRANCH=${GITHUB_REF/refs\/heads\//}
|
|
||||||
CURRENT_BRANCH=$TARGET_BRANCH
|
|
||||||
|
|
||||||
if [[ $exit_status -ne 0 ]]; then
|
if [[ $exit_status -ne 0 ]]; then
|
||||||
echo "::warning::Unable to determine the previous commit sha"
|
echo "::warning::Unable to determine the previous commit sha"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user