From b44ca153cef842a4801b73f6397987ee1eccf071 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Tue, 25 May 2021 00:08:26 -0400 Subject: [PATCH 1/6] Update test.yml --- .github/workflows/test.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5b639c4569c..c29e8c723f0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,6 +9,21 @@ on: - main jobs: + test-no-head-sha: + runs-on: ubuntu-latest + name: Test changed-files missing head sha + steps: + - name: Checkout to branch + uses: actions/checkout@v2 + + - name: Run changed-files with defaults + id: changed-files + uses: ./ + + - name: Show output + run: | + echo "${{ toJSON(steps.changed-files.outputs) }}" + test: runs-on: ubuntu-latest name: Test changed-files From 86d0ac0169fc01dc9ca5e8a2d8b69e640f9b57aa Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Tue, 25 May 2021 00:09:53 -0400 Subject: [PATCH 2/6] Update test.yml --- .github/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c29e8c723f0..642810616cf 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -4,6 +4,7 @@ on: push: branches: - main + - '**' pull_request: branches: - main From 3153fed2c9c48f46ff5369731d0b9a94213eaa6a Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Tue, 25 May 2021 00:11:56 -0400 Subject: [PATCH 3/6] Update entrypoint.sh --- entrypoint.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 161a3817ca8..e8e2b903bcb 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -7,11 +7,11 @@ git remote set-url origin "https://${INPUT_TOKEN}@github.com/${GITHUB_REPOSITORY echo "Getting head sha..." if [[ -z $GITHUB_BASE_REF ]]; then - HEAD_SHA=$(git rev-parse HEAD^1 || true) + HEAD_SHA=$(git rev-parse HEAD^1 2>/dev/null || true) else TARGET_BRANCH=${GITHUB_BASE_REF} git fetch --depth=1 origin "${TARGET_BRANCH}":"${TARGET_BRANCH}" - HEAD_SHA=$(git rev-parse "${TARGET_BRANCH}" || true) + HEAD_SHA=$(git rev-parse "${TARGET_BRANCH}" 2>/dev/null || true) fi if [[ -z $HEAD_SHA ]]; then From 35a86ed8e48a8f677e5bdcab4c6cdcf70383569b Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Tue, 25 May 2021 00:25:38 -0400 Subject: [PATCH 4/6] Update entrypoint.sh --- entrypoint.sh | 148 +++++++++++++++++++++++++------------------------- 1 file changed, 75 insertions(+), 73 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index e8e2b903bcb..f51f41b7f2e 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -7,90 +7,92 @@ git remote set-url origin "https://${INPUT_TOKEN}@github.com/${GITHUB_REPOSITORY echo "Getting head sha..." if [[ -z $GITHUB_BASE_REF ]]; then - HEAD_SHA=$(git rev-parse HEAD^1 2>/dev/null || true) + HEAD_SHA=$(git rev-parse HEAD^1 2>&1) && exit_status=$? || exit_status=$? else TARGET_BRANCH=${GITHUB_BASE_REF} git fetch --depth=1 origin "${TARGET_BRANCH}":"${TARGET_BRANCH}" - HEAD_SHA=$(git rev-parse "${TARGET_BRANCH}" 2>/dev/null || true) + HEAD_SHA=$(git rev-parse "${TARGET_BRANCH}" 2>&1) && exit_status=$? || exit_status=$? fi -if [[ -z $HEAD_SHA ]]; then +if [[ $exit_status -ne 0 ]]; then echo "::warning::Unable to determine the head sha: $HEAD_SHA." echo "::warning::You seem to be missing 'fetch-depth: 0' or 'fetch-depth: 2'" exit 1 +fi + +echo "Using head sha: $HEAD_SHA..." + +if [[ -z "$INPUT_FILES" ]]; then + echo "Getting diff..." + ADDED=$(git diff --diff-filter=A --name-only "$HEAD_SHA" | tr "\n" "$INPUT_SEPARATOR" | sed -E "s/($INPUT_SEPARATOR)$//") + COPIED=$(git diff --diff-filter=C --name-only "$HEAD_SHA" | tr "\n" "$INPUT_SEPARATOR" | sed -E "s/($INPUT_SEPARATOR)$//") + DELETED=$(git diff --diff-filter=D --name-only "$HEAD_SHA" | tr "\n" "$INPUT_SEPARATOR" | sed -E "s/($INPUT_SEPARATOR)$//") + MODIFIED=$(git diff --diff-filter=M --name-only "$HEAD_SHA" | tr "\n" "$INPUT_SEPARATOR" | sed -E "s/($INPUT_SEPARATOR)$//") + RENAMED=$(git diff --diff-filter=R --name-only "$HEAD_SHA" | tr "\n" "$INPUT_SEPARATOR" | sed -E "s/($INPUT_SEPARATOR)$//") + CHANGED=$(git diff --diff-filter=T --name-only "$HEAD_SHA" | tr "\n" "$INPUT_SEPARATOR" | sed -E "s/($INPUT_SEPARATOR)$//") + UNMERGED=$(git diff --diff-filter=U --name-only "$HEAD_SHA" | tr "\n" "$INPUT_SEPARATOR" | sed -E "s/($INPUT_SEPARATOR)$//") + UNKNOWN=$(git diff --diff-filter=X --name-only "$HEAD_SHA" | tr "\n" "$INPUT_SEPARATOR" | sed -E "s/($INPUT_SEPARATOR)$//") + ALL_CHANGED=$(git diff --diff-filter="*ACDMRTUX" --name-only "$HEAD_SHA" | tr "\n" "$INPUT_SEPARATOR" | sed -E "s/($INPUT_SEPARATOR)$//") + ALL_MODIFIED_FILES=$(git diff --diff-filter="ACM" --name-only "$HEAD_SHA" | tr "\n" "$INPUT_SEPARATOR" | sed -E "s/($INPUT_SEPARATOR)$//") else - echo "Using head sha: $HEAD_SHA..." - if [[ -z "$INPUT_FILES" ]]; then - echo "Getting diff..." - ADDED=$(git diff --diff-filter=A --name-only "$HEAD_SHA" | tr "\n" "$INPUT_SEPARATOR" | sed -E "s/($INPUT_SEPARATOR)$//") - COPIED=$(git diff --diff-filter=C --name-only "$HEAD_SHA" | tr "\n" "$INPUT_SEPARATOR" | sed -E "s/($INPUT_SEPARATOR)$//") - DELETED=$(git diff --diff-filter=D --name-only "$HEAD_SHA" | tr "\n" "$INPUT_SEPARATOR" | sed -E "s/($INPUT_SEPARATOR)$//") - MODIFIED=$(git diff --diff-filter=M --name-only "$HEAD_SHA" | tr "\n" "$INPUT_SEPARATOR" | sed -E "s/($INPUT_SEPARATOR)$//") - RENAMED=$(git diff --diff-filter=R --name-only "$HEAD_SHA" | tr "\n" "$INPUT_SEPARATOR" | sed -E "s/($INPUT_SEPARATOR)$//") - CHANGED=$(git diff --diff-filter=T --name-only "$HEAD_SHA" | tr "\n" "$INPUT_SEPARATOR" | sed -E "s/($INPUT_SEPARATOR)$//") - UNMERGED=$(git diff --diff-filter=U --name-only "$HEAD_SHA" | tr "\n" "$INPUT_SEPARATOR" | sed -E "s/($INPUT_SEPARATOR)$//") - UNKNOWN=$(git diff --diff-filter=X --name-only "$HEAD_SHA" | tr "\n" "$INPUT_SEPARATOR" | sed -E "s/($INPUT_SEPARATOR)$//") - ALL_CHANGED=$(git diff --diff-filter="*ACDMRTUX" --name-only "$HEAD_SHA" | tr "\n" "$INPUT_SEPARATOR" | sed -E "s/($INPUT_SEPARATOR)$//") - ALL_MODIFIED_FILES=$(git diff --diff-filter="ACM" --name-only "$HEAD_SHA" | tr "\n" "$INPUT_SEPARATOR" | sed -E "s/($INPUT_SEPARATOR)$//") - else - ADDED_ARRAY=() - COPIED_ARRAY=() - DELETED_ARRAY=() - MODIFIED_ARRAY=() - RENAMED_ARRAY=() - CHANGED_ARRAY=() - UNMERGED_ARRAY=() - UNKNOWN_ARRAY=() - ALL_CHANGED_ARRAY=() - ALL_MODIFIED_FILES_ARRAY=() - for path in ${INPUT_FILES} - do - echo "Checking for file changes: \"${path}\"..." - IFS=" " - # shellcheck disable=SC2207 - ADDED_ARRAY+=($(git diff --diff-filter=A --name-only "$HEAD_SHA" | grep -E "(${path})" | xargs || true)) - # shellcheck disable=SC2207 - COPIED_ARRAY+=($(git diff --diff-filter=C --name-only "$HEAD_SHA" | grep -E "(${path})" | xargs || true)) - # shellcheck disable=SC2207 - DELETED_ARRAY+=($(git diff --diff-filter=D --name-only "$HEAD_SHA" | grep -E "(${path})" | xargs || true)) - # shellcheck disable=SC2207 - MODIFIED_ARRAY+=($(git diff --diff-filter=M --name-only "$HEAD_SHA" | grep -E "(${path})" | xargs || true)) - # shellcheck disable=SC2207 - RENAMED_ARRAY+=($(git diff --diff-filter=R --name-only "$HEAD_SHA" | grep -E "(${path})" | xargs || true)) - # shellcheck disable=SC2207 - CHANGED_ARRAY+=($(git diff --diff-filter=T --name-only "$HEAD_SHA" | grep -E "(${path})" | xargs || true)) - # shellcheck disable=SC2207 - UNMERGED_ARRAY+=($(git diff --diff-filter=U --name-only "$HEAD_SHA" | grep -E "(${path})" | xargs || true)) - # shellcheck disable=SC2207 - UNKNOWN_ARRAY+=($(git diff --diff-filter=X --name-only "$HEAD_SHA" | grep -E "(${path})" | xargs || true)) - # shellcheck disable=SC2207 - ALL_CHANGED_ARRAY+=($(git diff --diff-filter="*ACDMRTUX" --name-only "$HEAD_SHA" | grep -E "(${path})" | xargs || true)) - # shellcheck disable=SC2207 - ALL_MODIFIED_FILES_ARRAY+=($(git diff --diff-filter="ACM" --name-only "$HEAD_SHA" | grep -E "(${path})" | xargs || true)) - done + ADDED_ARRAY=() + COPIED_ARRAY=() + DELETED_ARRAY=() + MODIFIED_ARRAY=() + RENAMED_ARRAY=() + CHANGED_ARRAY=() + UNMERGED_ARRAY=() + UNKNOWN_ARRAY=() + ALL_CHANGED_ARRAY=() + ALL_MODIFIED_FILES_ARRAY=() + for path in ${INPUT_FILES} + do + echo "Checking for file changes: \"${path}\"..." + IFS=" " + # shellcheck disable=SC2207 + ADDED_ARRAY+=($(git diff --diff-filter=A --name-only "$HEAD_SHA" | grep -E "(${path})" | xargs || true)) + # shellcheck disable=SC2207 + COPIED_ARRAY+=($(git diff --diff-filter=C --name-only "$HEAD_SHA" | grep -E "(${path})" | xargs || true)) + # shellcheck disable=SC2207 + DELETED_ARRAY+=($(git diff --diff-filter=D --name-only "$HEAD_SHA" | grep -E "(${path})" | xargs || true)) + # shellcheck disable=SC2207 + MODIFIED_ARRAY+=($(git diff --diff-filter=M --name-only "$HEAD_SHA" | grep -E "(${path})" | xargs || true)) + # shellcheck disable=SC2207 + RENAMED_ARRAY+=($(git diff --diff-filter=R --name-only "$HEAD_SHA" | grep -E "(${path})" | xargs || true)) + # shellcheck disable=SC2207 + CHANGED_ARRAY+=($(git diff --diff-filter=T --name-only "$HEAD_SHA" | grep -E "(${path})" | xargs || true)) + # shellcheck disable=SC2207 + UNMERGED_ARRAY+=($(git diff --diff-filter=U --name-only "$HEAD_SHA" | grep -E "(${path})" | xargs || true)) + # shellcheck disable=SC2207 + UNKNOWN_ARRAY+=($(git diff --diff-filter=X --name-only "$HEAD_SHA" | grep -E "(${path})" | xargs || true)) + # shellcheck disable=SC2207 + ALL_CHANGED_ARRAY+=($(git diff --diff-filter="*ACDMRTUX" --name-only "$HEAD_SHA" | grep -E "(${path})" | xargs || true)) + # shellcheck disable=SC2207 + ALL_MODIFIED_FILES_ARRAY+=($(git diff --diff-filter="ACM" --name-only "$HEAD_SHA" | grep -E "(${path})" | xargs || true)) + done - # shellcheck disable=SC2001 - ADDED=$(echo "${ADDED_ARRAY[*]}" | sed 's/ */'"$INPUT_SEPARATOR"'/g') - # shellcheck disable=SC2001 - COPIED=$(echo "${COPIED_ARRAY[*]}" | sed 's/ */'"$INPUT_SEPARATOR"'/g') - # shellcheck disable=SC2001 - DELETED=$(echo "${DELETED_ARRAY[*]}" | sed 's/ */'"$INPUT_SEPARATOR"'/g') - # shellcheck disable=SC2001 - MODIFIED=$(echo "${MODIFIED_ARRAY[*]}" | sed 's/ */'"$INPUT_SEPARATOR"'/g') - # shellcheck disable=SC2001 - RENAMED=$(echo "${RENAMED_ARRAY[*]}" | sed 's/ */'"$INPUT_SEPARATOR"'/g') - # shellcheck disable=SC2001 - CHANGED=$(echo "${CHANGED_ARRAY[*]}" | sed 's/ */'"$INPUT_SEPARATOR"'/g') - # shellcheck disable=SC2001 - UNMERGED=$(echo "${UNMERGED_ARRAY[*]}" | sed 's/ */'"$INPUT_SEPARATOR"'/g') - # shellcheck disable=SC2001 - UNKNOWN=$(echo "${UNKNOWN_ARRAY[*]}" | sed 's/ */'"$INPUT_SEPARATOR"'/g') - # shellcheck disable=SC2001 - ALL_CHANGED=$(echo "${ALL_CHANGED_ARRAY[*]}" | sed 's/ */'"$INPUT_SEPARATOR"'/g') - # shellcheck disable=SC2001 - ALL_MODIFIED_FILES=$(echo "${ALL_MODIFIED_FILES_ARRAY[*]}" | sed 's/ */'"$INPUT_SEPARATOR"'/g') - fi + # shellcheck disable=SC2001 + ADDED=$(echo "${ADDED_ARRAY[*]}" | sed 's/ */'"$INPUT_SEPARATOR"'/g') + # shellcheck disable=SC2001 + COPIED=$(echo "${COPIED_ARRAY[*]}" | sed 's/ */'"$INPUT_SEPARATOR"'/g') + # shellcheck disable=SC2001 + DELETED=$(echo "${DELETED_ARRAY[*]}" | sed 's/ */'"$INPUT_SEPARATOR"'/g') + # shellcheck disable=SC2001 + MODIFIED=$(echo "${MODIFIED_ARRAY[*]}" | sed 's/ */'"$INPUT_SEPARATOR"'/g') + # shellcheck disable=SC2001 + RENAMED=$(echo "${RENAMED_ARRAY[*]}" | sed 's/ */'"$INPUT_SEPARATOR"'/g') + # shellcheck disable=SC2001 + CHANGED=$(echo "${CHANGED_ARRAY[*]}" | sed 's/ */'"$INPUT_SEPARATOR"'/g') + # shellcheck disable=SC2001 + UNMERGED=$(echo "${UNMERGED_ARRAY[*]}" | sed 's/ */'"$INPUT_SEPARATOR"'/g') + # shellcheck disable=SC2001 + UNKNOWN=$(echo "${UNKNOWN_ARRAY[*]}" | sed 's/ */'"$INPUT_SEPARATOR"'/g') + # shellcheck disable=SC2001 + ALL_CHANGED=$(echo "${ALL_CHANGED_ARRAY[*]}" | sed 's/ */'"$INPUT_SEPARATOR"'/g') + # shellcheck disable=SC2001 + ALL_MODIFIED_FILES=$(echo "${ALL_MODIFIED_FILES_ARRAY[*]}" | sed 's/ */'"$INPUT_SEPARATOR"'/g') fi + echo "Added files: $ADDED" echo "Copied files: $COPIED" echo "Deleted files: $DELETED" From 337e5fdbaa5a5badc644c10e5bcaf5dd0aeec5a1 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Tue, 25 May 2021 00:27:28 -0400 Subject: [PATCH 5/6] Update test.yml --- .github/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 642810616cf..8b9c37d688b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -19,6 +19,7 @@ jobs: - name: Run changed-files with defaults id: changed-files + continue-on-error: true uses: ./ - name: Show output From 715a348cd90fc69c5d0ec1862836e2c56a9766f1 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Tue, 25 May 2021 00:28:06 -0400 Subject: [PATCH 6/6] Update entrypoint.sh --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index f51f41b7f2e..6789ecf6587 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -15,7 +15,7 @@ else fi if [[ $exit_status -ne 0 ]]; then - echo "::warning::Unable to determine the head sha: $HEAD_SHA." + echo "::warning::Unable to determine the head sha" echo "::warning::You seem to be missing 'fetch-depth: 0' or 'fetch-depth: 2'" exit 1 fi