diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index 28f61de9..a65078f7 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -129,7 +129,7 @@ jobs:
id: changed-files-specific-source-file
uses: ./
with:
- files-from-source-file: |
+ files_from_source_file: |
test/changed-files-list.txt
test/changed-files-list.txt
files: |
@@ -152,7 +152,7 @@ jobs:
id: changed-files-specific-comma-source-file
uses: ./
with:
- files-from-source-file: |
+ files_from_source_file: |
test/changed-files-list.txt
separator: ","
- name: Verify any_changed files comma separator
@@ -179,3 +179,22 @@ jobs:
echo "${{ toJSON(steps.changed-files-custom-sha.outputs) }}"
shell:
bash
+ - name: Get branch name
+ id: branch-name
+ uses: tj-actions/branch-names@v4.5
+ - uses: nrwl/last-successful-commit-action@v1
+ id: last_successful_commit
+ with:
+ branch: ${{ steps.branch-name.outputs.base_ref_branch }}
+ workflow_id: 'test.yml'
+ github_token: ${{ secrets.GITHUB_TOKEN }}
+ - name: Run changed-files with a custom base sha
+ id: changed-files-custom-base-sha
+ uses: ./
+ with:
+ base_sha: ${{ steps.last_successful_commit.outputs.commit_hash }}
+ - name: Show output
+ run: |
+ echo "${{ toJSON(steps.changed-files-custom-sha.outputs) }}"
+ shell:
+ bash
diff --git a/README.md b/README.md
index 410001d3..40c6a18e 100644
--- a/README.md
+++ b/README.md
@@ -98,8 +98,9 @@ jobs:
| token | `string` | `false` | `${{ github.token }}` | [GITHUB_TOKEN](https://docs.github.com/en/free-pro-team@latest/actions/reference/authentication-in-a-workflow#using-the-github_token-in-a-workflow)
or a repo scoped
[Personal Access Token](https://docs.github.com/en/free-pro-team@latest/github/authenticating-to-github/creating-a-personal-access-token) |
| separator | `string` | `true` | `' '` | Output string separator |
| files | `string` OR `string[]` | `false` | | Check for changes
using only these
list of file(s)
(Defaults to the
entire repo) |
+| base_sha | `string` | `false` | | Specify a different
base commit SHA used
for comparing changes |
| sha | `string` | `true` | `${{ github.sha }}` | Specify a different
commit SHA used
for comparing changes |
-| files-from-source-file | `string` | `false` | | Source file used populate
the files input. |
+| files_from_source_file | `string` | `false` | | Source file used populate
the files input. |
## Example
@@ -156,14 +157,14 @@ jobs:
id: changed-files-specific-source-file
uses: ./
with:
- files-from-source-file: |
+ files_from_source_file: |
test/changed-files-list.txt
- name: Use a source file or list of file(s) to populate to files input and optionally specify more files.
id: changed-files-specific-source-file-and-specify-files
uses: ./
with:
- files-from-source-file: |
+ files_from_source_file: |
test/changed-files-list.txt
files: |
.github/workflows/rebase.yml
diff --git a/action.yml b/action.yml
index f19591d6..e9d3c199 100644
--- a/action.yml
+++ b/action.yml
@@ -10,7 +10,7 @@ inputs:
description: 'Split character for array output'
required: true
default: " "
- files-from-source-file:
+ files_from_source_file:
description: 'Source file to populate the files input'
required: false
default: ""
@@ -19,9 +19,12 @@ inputs:
required: false
default: ""
sha:
- description: 'Specify a different commit SHA used for comparing changes'
+ description: 'Specify a current commit SHA used for comparing changes'
required: true
default: ${{ github.sha }}
+ base_sha:
+ description: 'Specify a base commit SHA on used for comparing changes'
+ required: false
outputs:
added_files:
@@ -76,7 +79,7 @@ runs:
shell: bash
env:
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: |
bash $GITHUB_ACTION_PATH/entrypoint.sh
id: changed-files
@@ -87,6 +90,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_TOKEN: ${{ inputs.token }}
INPUT_FILES: ${{ join(format('{0} {1}', inputs.files, steps.source-input-files.outputs.files), ' ') }}
INPUT_SEPARATOR: ${{ inputs.separator }}
diff --git a/entrypoint.sh b/entrypoint.sh
index 57759ee8..db26ceed 100755
--- a/entrypoint.sh
+++ b/entrypoint.sh
@@ -9,9 +9,9 @@ git remote set-url origin "https://${INPUT_TOKEN}@github.com/${GITHUB_REPOSITORY
echo "Getting HEAD info..."
if [[ -z $INPUT_SHA ]]; then
- CURR_SHA=$(git rev-parse HEAD 2>&1) && exit_status=$? || exit_status=$?
+ CURRENT_SHA=$(git rev-parse HEAD 2>&1) && exit_status=$? || exit_status=$?
else
- CURR_SHA=$INPUT_SHA
+ CURRENT_SHA=$INPUT_SHA
fi
if [[ $exit_status -ne 0 ]]; then
@@ -20,7 +20,11 @@ if [[ $exit_status -ne 0 ]]; then
fi
if [[ -z $GITHUB_BASE_REF ]]; then
- PREV_SHA=$(git rev-parse HEAD^1 2>&1) && exit_status=$? || exit_status=$?
+ 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
+ fi
TARGET_BRANCH=${GITHUB_REF/refs\/heads\//}
CURRENT_BRANCH=$TARGET_BRANCH
@@ -30,10 +34,14 @@ if [[ -z $GITHUB_BASE_REF ]]; then
exit 1
fi
else
- TARGET_BRANCH=${GITHUB_BASE_REF}
+ TARGET_BRANCH=$GITHUB_BASE_REF
CURRENT_BRANCH=$GITHUB_HEAD_REF
- git fetch --depth=1 origin "${TARGET_BRANCH}":"${TARGET_BRANCH}"
- PREV_SHA=$(git rev-parse "${TARGET_BRANCH}" 2>&1) && exit_status=$? || exit_status=$?
+ git fetch origin "${TARGET_BRANCH}":"${TARGET_BRANCH}"
+ if [[ -z $INPUT_BASE_SHA ]]; then
+ PREVIOUS_SHA=$(git rev-parse "${TARGET_BRANCH}" 2>&1) && exit_status=$? || exit_status=$?
+ else
+ PREVIOUS_SHA=$INPUT_BASE_SHA
+ fi
if [[ $exit_status -ne 0 ]]; then
echo "::warning::Unable to determine the base ref sha for ${TARGET_BRANCH}"
@@ -41,22 +49,22 @@ else
fi
fi
-echo "Retrieving changes between $PREV_SHA ($TARGET_BRANCH) → $CURR_SHA ($CURRENT_BRANCH)"
+echo "Retrieving changes between $PREVIOUS_SHA ($TARGET_BRANCH) → $CURRENT_SHA ($CURRENT_BRANCH)"
UNIQUE_FILES=$(echo "$INPUT_FILES" | tr ' ' '\n' | sort -u | xargs)
if [[ -z "$UNIQUE_FILES" ]]; then
echo "Getting diff..."
- ADDED=$(git diff --diff-filter=A --name-only "$PREV_SHA" "$CURR_SHA" | tr "\n" "$INPUT_SEPARATOR" | sed -E "s/($INPUT_SEPARATOR)$//")
- COPIED=$(git diff --diff-filter=C --name-only "$PREV_SHA" "$CURR_SHA" | tr "\n" "$INPUT_SEPARATOR" | sed -E "s/($INPUT_SEPARATOR)$//")
- DELETED=$(git diff --diff-filter=D --name-only "$PREV_SHA" "$CURR_SHA" | tr "\n" "$INPUT_SEPARATOR" | sed -E "s/($INPUT_SEPARATOR)$//")
- MODIFIED=$(git diff --diff-filter=M --name-only "$PREV_SHA" "$CURR_SHA" | tr "\n" "$INPUT_SEPARATOR" | sed -E "s/($INPUT_SEPARATOR)$//")
- RENAMED=$(git diff --diff-filter=R --name-only "$PREV_SHA" "$CURR_SHA" | tr "\n" "$INPUT_SEPARATOR" | sed -E "s/($INPUT_SEPARATOR)$//")
- TYPE_CHANGED=$(git diff --diff-filter=T --name-only "$PREV_SHA" "$CURR_SHA" | tr "\n" "$INPUT_SEPARATOR" | sed -E "s/($INPUT_SEPARATOR)$//")
- UNMERGED=$(git diff --diff-filter=U --name-only "$PREV_SHA" "$CURR_SHA" | tr "\n" "$INPUT_SEPARATOR" | sed -E "s/($INPUT_SEPARATOR)$//")
- UNKNOWN=$(git diff --diff-filter=X --name-only "$PREV_SHA" "$CURR_SHA" | tr "\n" "$INPUT_SEPARATOR" | sed -E "s/($INPUT_SEPARATOR)$//")
- ALL_CHANGED=$(git diff --diff-filter="*ACDMRTUX" --name-only "$PREV_SHA" "$CURR_SHA" | tr "\n" "$INPUT_SEPARATOR" | sed -E "s/($INPUT_SEPARATOR)$//")
- ALL_MODIFIED_FILES=$(git diff --diff-filter="ACM" --name-only "$PREV_SHA" "$CURR_SHA" | tr "\n" "$INPUT_SEPARATOR" | sed -E "s/($INPUT_SEPARATOR)$//")
+ ADDED=$(git diff --diff-filter=A --name-only "$PREVIOUS_SHA" "$CURRENT_SHA" | tr "\n" "$INPUT_SEPARATOR" | sed -E "s/($INPUT_SEPARATOR)$//")
+ COPIED=$(git diff --diff-filter=C --name-only "$PREVIOUS_SHA" "$CURRENT_SHA" | tr "\n" "$INPUT_SEPARATOR" | sed -E "s/($INPUT_SEPARATOR)$//")
+ DELETED=$(git diff --diff-filter=D --name-only "$PREVIOUS_SHA" "$CURRENT_SHA" | tr "\n" "$INPUT_SEPARATOR" | sed -E "s/($INPUT_SEPARATOR)$//")
+ MODIFIED=$(git diff --diff-filter=M --name-only "$PREVIOUS_SHA" "$CURRENT_SHA" | tr "\n" "$INPUT_SEPARATOR" | sed -E "s/($INPUT_SEPARATOR)$//")
+ RENAMED=$(git diff --diff-filter=R --name-only "$PREVIOUS_SHA" "$CURRENT_SHA" | tr "\n" "$INPUT_SEPARATOR" | sed -E "s/($INPUT_SEPARATOR)$//")
+ TYPE_CHANGED=$(git diff --diff-filter=T --name-only "$PREVIOUS_SHA" "$CURRENT_SHA" | tr "\n" "$INPUT_SEPARATOR" | sed -E "s/($INPUT_SEPARATOR)$//")
+ UNMERGED=$(git diff --diff-filter=U --name-only "$PREVIOUS_SHA" "$CURRENT_SHA" | tr "\n" "$INPUT_SEPARATOR" | sed -E "s/($INPUT_SEPARATOR)$//")
+ UNKNOWN=$(git diff --diff-filter=X --name-only "$PREVIOUS_SHA" "$CURRENT_SHA" | tr "\n" "$INPUT_SEPARATOR" | sed -E "s/($INPUT_SEPARATOR)$//")
+ ALL_CHANGED=$(git diff --diff-filter="*ACDMRTUX" --name-only "$PREVIOUS_SHA" "$CURRENT_SHA" | tr "\n" "$INPUT_SEPARATOR" | sed -E "s/($INPUT_SEPARATOR)$//")
+ ALL_MODIFIED_FILES=$(git diff --diff-filter="ACM" --name-only "$PREVIOUS_SHA" "$CURRENT_SHA" | tr "\n" "$INPUT_SEPARATOR" | sed -E "s/($INPUT_SEPARATOR)$//")
else
ADDED_ARRAY=()
COPIED_ARRAY=()
@@ -74,25 +82,25 @@ else
echo "Checking for file changes: \"${path}\"..."
IFS=" "
# shellcheck disable=SC2207
- ADDED_ARRAY+=($(git diff --diff-filter=A --name-only "$PREV_SHA" "$CURR_SHA" | grep -E "(${path})" | xargs || true))
+ ADDED_ARRAY+=($(git diff --diff-filter=A --name-only "$PREVIOUS_SHA" "$CURRENT_SHA" | grep -E "(${path})" | xargs || true))
# shellcheck disable=SC2207
- COPIED_ARRAY+=($(git diff --diff-filter=C --name-only "$PREV_SHA" "$CURR_SHA" | grep -E "(${path})" | xargs || true))
+ COPIED_ARRAY+=($(git diff --diff-filter=C --name-only "$PREVIOUS_SHA" "$CURRENT_SHA" | grep -E "(${path})" | xargs || true))
# shellcheck disable=SC2207
- DELETED_ARRAY+=($(git diff --diff-filter=D --name-only "$PREV_SHA" "$CURR_SHA" | grep -E "(${path})" | xargs || true))
+ DELETED_ARRAY+=($(git diff --diff-filter=D --name-only "$PREVIOUS_SHA" "$CURRENT_SHA" | grep -E "(${path})" | xargs || true))
# shellcheck disable=SC2207
- MODIFIED_ARRAY+=($(git diff --diff-filter=M --name-only "$PREV_SHA" "$CURR_SHA" | grep -E "(${path})" | xargs || true))
+ MODIFIED_ARRAY+=($(git diff --diff-filter=M --name-only "$PREVIOUS_SHA" "$CURRENT_SHA" | grep -E "(${path})" | xargs || true))
# shellcheck disable=SC2207
- RENAMED_ARRAY+=($(git diff --diff-filter=R --name-only "$PREV_SHA" "$CURR_SHA" | grep -E "(${path})" | xargs || true))
+ RENAMED_ARRAY+=($(git diff --diff-filter=R --name-only "$PREVIOUS_SHA" "$CURRENT_SHA" | grep -E "(${path})" | xargs || true))
# shellcheck disable=SC2207
- TYPE_CHANGED_ARRAY+=($(git diff --diff-filter=T --name-only "$PREV_SHA" "$CURR_SHA" | grep -E "(${path})" | xargs || true))
+ TYPE_CHANGED_ARRAY+=($(git diff --diff-filter=T --name-only "$PREVIOUS_SHA" "$CURRENT_SHA" | grep -E "(${path})" | xargs || true))
# shellcheck disable=SC2207
- UNMERGED_ARRAY+=($(git diff --diff-filter=U --name-only "$PREV_SHA" "$CURR_SHA" | grep -E "(${path})" | xargs || true))
+ UNMERGED_ARRAY+=($(git diff --diff-filter=U --name-only "$PREVIOUS_SHA" "$CURRENT_SHA" | grep -E "(${path})" | xargs || true))
# shellcheck disable=SC2207
- UNKNOWN_ARRAY+=($(git diff --diff-filter=X --name-only "$PREV_SHA" "$CURR_SHA" | grep -E "(${path})" | xargs || true))
+ UNKNOWN_ARRAY+=($(git diff --diff-filter=X --name-only "$PREVIOUS_SHA" "$CURRENT_SHA" | grep -E "(${path})" | xargs || true))
# shellcheck disable=SC2207
- ALL_CHANGED_ARRAY+=($(git diff --diff-filter="*ACDMRTUX" --name-only "$PREV_SHA" "$CURR_SHA" | grep -E "(${path})" | xargs || true))
+ ALL_CHANGED_ARRAY+=($(git diff --diff-filter="*ACDMRTUX" --name-only "$PREVIOUS_SHA" "$CURRENT_SHA" | grep -E "(${path})" | xargs || true))
# shellcheck disable=SC2207
- ALL_MODIFIED_FILES_ARRAY+=($(git diff --diff-filter="ACM" --name-only "$PREV_SHA" "$CURR_SHA" | grep -E "(${path})" | xargs || true))
+ ALL_MODIFIED_FILES_ARRAY+=($(git diff --diff-filter="ACM" --name-only "$PREVIOUS_SHA" "$CURRENT_SHA" | grep -E "(${path})" | xargs || true))
done
# shellcheck disable=SC2001