From 53afe7a5b555e08df29ddc72d648ef951725b6be Mon Sep 17 00:00:00 2001 From: Krasimir Nikolov Date: Wed, 14 Jul 2021 23:57:17 +0300 Subject: [PATCH] Add custom source sha (#126) Co-authored-by: Tonye Jack --- .github/workflows/test.yml | 10 ++++++++++ README.md | 5 +++++ action.yml | 6 +++++- entrypoint.sh | 4 ++-- 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ede3f60e..3290a077 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -130,3 +130,13 @@ jobs: echo "${{ toJSON(steps.changed-files-specific-comma.outputs) }}" shell: bash + - name: Run changed-files with custom sha + id: changed-files-custom-sha + uses: ./ + with: + sha: ${{ github.event.pull_request.head.sha }} + - name: Show output + run: | + echo "${{ toJSON(steps.changed-files-custom-sha.outputs) }}" + shell: + bash diff --git a/README.md b/README.md index bdeeb595..e9f419aa 100644 --- a/README.md +++ b/README.md @@ -149,6 +149,11 @@ jobs: if: steps.changed-files-specific.outputs.any_changed == 'true' run: | echo "One or more files listed above has changed." + - name: Use a different commit SHA as the base + id: changed-files-comma + uses: tj-actions/changed-files@v8.4 + with: + sha: ${{ github.event.pull_request.head.sha }} ``` diff --git a/action.yml b/action.yml index 55c9b78b..60b84e17 100644 --- a/action.yml +++ b/action.yml @@ -14,6 +14,10 @@ inputs: description: 'Check for changes using only this list of files (Defaults to the entire repo)' required: false default: "" + sha: + description: 'Specify a different commit SHA to be used for comparing changes' + required: true + default: ${{ github.sha }} outputs: added_files: @@ -58,11 +62,11 @@ runs: id: changed-files shell: bash env: - GITHUB_SHA: ${{ github.sha }} GITHUB_BASE_REF: ${{ github.base_ref }} GITHUB_REPOSITORY: ${{ github.repository }} # 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_TOKEN: ${{ inputs.token }} INPUT_FILES: ${{ inputs.files }} INPUT_SEPARATOR: ${{ inputs.separator }} diff --git a/entrypoint.sh b/entrypoint.sh index c2872c4c..390eb7b3 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -8,10 +8,10 @@ git remote set-url origin "https://${INPUT_TOKEN}@github.com/${GITHUB_REPOSITORY echo "Getting HEAD info..." -if [[ -z $GITHUB_SHA ]]; then +if [[ -z $INPUT_SHA ]]; then CURR_SHA=$(git rev-parse HEAD 2>&1) && exit_status=$? || exit_status=$? else - CURR_SHA=$GITHUB_SHA + CURR_SHA=$INPUT_SHA fi if [[ $exit_status -ne 0 ]]; then