Improve error handling (#263)
* Improve error handling Fixes: #255 * Update entrypoint.sh * Update entrypoint.sh * Update error checking * Update test.yml * Update test.yml * Update test.yml * Update entrypoint.sh * Update action.yml * Update entrypoint.sh * Update entrypoint.sh * Update entrypoint.sh * Update test.yml * Update entrypoint.sh * Update test.yml * Update test.yml * Update test.yml * Update entrypoint.sh * Update entrypoint.sh * Update entrypoint.sh * Update test.yml
This commit is contained in:
parent
0a8c804187
commit
3ef3d14e6d
63
.github/workflows/test.yml
vendored
63
.github/workflows/test.yml
vendored
@ -73,8 +73,8 @@ jobs:
|
|||||||
shell:
|
shell:
|
||||||
bash
|
bash
|
||||||
|
|
||||||
test-no-head-sha:
|
test-non-existent-base-sha:
|
||||||
name: Test changed-files missing head sha
|
name: Test changed-files non existent base sha
|
||||||
runs-on: ${{ matrix.platform }}
|
runs-on: ${{ matrix.platform }}
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
@ -85,10 +85,12 @@ jobs:
|
|||||||
- name: Checkout to branch
|
- name: Checkout to branch
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
- name: Run changed-files with defaults
|
- name: Run changed-files with non existent base sha
|
||||||
id: changed-files
|
id: changed-files
|
||||||
continue-on-error: true
|
|
||||||
uses: ./
|
uses: ./
|
||||||
|
continue-on-error: true
|
||||||
|
with:
|
||||||
|
base_sha: "4554456"
|
||||||
|
|
||||||
- name: Show output
|
- name: Show output
|
||||||
run: |
|
run: |
|
||||||
@ -96,6 +98,59 @@ jobs:
|
|||||||
shell:
|
shell:
|
||||||
bash
|
bash
|
||||||
|
|
||||||
|
- name: Run changed-files-specific with non existent base sha
|
||||||
|
id: changed-files-specific
|
||||||
|
uses: ./
|
||||||
|
continue-on-error: true
|
||||||
|
with:
|
||||||
|
files: action.yml
|
||||||
|
base_sha: "4554456"
|
||||||
|
|
||||||
|
- name: Show output
|
||||||
|
run: |
|
||||||
|
echo "${{ toJSON(steps.changed-files-specific.outputs) }}"
|
||||||
|
shell:
|
||||||
|
bash
|
||||||
|
|
||||||
|
test-non-existent-sha:
|
||||||
|
name: Test changed-files non existent sha
|
||||||
|
runs-on: ${{ matrix.platform }}
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
platform: [ubuntu-latest, windows-latest, macos-latest, macos-11, ubuntu-18.04, windows-2022, windows-2016]
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout to branch
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Run changed-files with non existent sha
|
||||||
|
id: changed-files
|
||||||
|
uses: ./
|
||||||
|
continue-on-error: true
|
||||||
|
with:
|
||||||
|
base_sha: "4554456"
|
||||||
|
|
||||||
|
- name: Show output
|
||||||
|
run: |
|
||||||
|
echo "${{ toJSON(steps.changed-files.outputs) }}"
|
||||||
|
shell:
|
||||||
|
bash
|
||||||
|
|
||||||
|
- name: Run changed-files-specific with non existent sha
|
||||||
|
id: changed-files-specific
|
||||||
|
uses: ./
|
||||||
|
continue-on-error: true
|
||||||
|
with:
|
||||||
|
files: action.yml
|
||||||
|
base_sha: "4554456"
|
||||||
|
|
||||||
|
- name: Show output
|
||||||
|
run: |
|
||||||
|
echo "${{ toJSON(steps.changed-files-specific.outputs) }}"
|
||||||
|
shell:
|
||||||
|
bash
|
||||||
|
|
||||||
test:
|
test:
|
||||||
name: Test changed-files
|
name: Test changed-files
|
||||||
runs-on: ${{ matrix.platform }}
|
runs-on: ${{ matrix.platform }}
|
||||||
|
@ -95,7 +95,7 @@ runs:
|
|||||||
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: |
|
- run: |
|
||||||
# "Set up the bash sha..."
|
# "Set base sha..."
|
||||||
if [[ -n "${{ inputs.base_sha }}" ]]; then
|
if [[ -n "${{ inputs.base_sha }}" ]]; then
|
||||||
echo "::set-output name=base_sha::${{ inputs.base_sha }}"
|
echo "::set-output name=base_sha::${{ inputs.base_sha }}"
|
||||||
elif [[ "${{ inputs.since_last_remote_commit }}" == "true" ]]; then
|
elif [[ "${{ inputs.since_last_remote_commit }}" == "true" ]]; then
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
set -e
|
set -eu
|
||||||
|
|
||||||
echo "::group::changed-files"
|
echo "::group::changed-files"
|
||||||
|
|
||||||
@ -37,8 +37,12 @@ else
|
|||||||
CURRENT_SHA=$INPUT_SHA && exit_status=$? || exit_status=$?
|
CURRENT_SHA=$INPUT_SHA && exit_status=$? || exit_status=$?
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
git rev-parse --quiet --verify "$CURRENT_SHA^{commit}" 1>/dev/null 2>&1 && exit_status=$? || exit_status=$?
|
||||||
|
|
||||||
|
|
||||||
if [[ $exit_status -ne 0 ]]; then
|
if [[ $exit_status -ne 0 ]]; then
|
||||||
echo "::warning::Unable to determine the current head sha"
|
echo "::warning::Unable to locate the current sha: $CURRENT_SHA"
|
||||||
|
echo "::warning::You seem to be missing 'fetch-depth: 0' or 'fetch-depth: 2'. See https://github.com/tj-actions/changed-files#usage"
|
||||||
git remote remove temp_changed_files
|
git remote remove temp_changed_files
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
@ -53,8 +57,10 @@ if [[ -z $GITHUB_BASE_REF ]]; then
|
|||||||
PREVIOUS_SHA=$INPUT_BASE_SHA && exit_status=$? || exit_status=$?
|
PREVIOUS_SHA=$INPUT_BASE_SHA && exit_status=$? || exit_status=$?
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
git rev-parse --quiet --verify "$PREVIOUS_SHA^{commit}" 1>/dev/null 2>&1 && exit_status=$? || exit_status=$?
|
||||||
|
|
||||||
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 locate the previous sha: $PREVIOUS_SHA"
|
||||||
echo "::warning::You seem to be missing 'fetch-depth: 0' or 'fetch-depth: 2'. See https://github.com/tj-actions/changed-files#usage"
|
echo "::warning::You seem to be missing 'fetch-depth: 0' or 'fetch-depth: 2'. See https://github.com/tj-actions/changed-files#usage"
|
||||||
git remote remove temp_changed_files
|
git remote remove temp_changed_files
|
||||||
exit 1
|
exit 1
|
||||||
@ -64,15 +70,17 @@ else
|
|||||||
CURRENT_BRANCH=$GITHUB_HEAD_REF
|
CURRENT_BRANCH=$GITHUB_HEAD_REF
|
||||||
|
|
||||||
if [[ -z $INPUT_BASE_SHA ]]; then
|
if [[ -z $INPUT_BASE_SHA ]]; then
|
||||||
git fetch --no-tags -u --progress --depth=1 temp_changed_files "${TARGET_BRANCH}":"${TARGET_BRANCH}"
|
git fetch --no-tags -u --progress --depth=1 temp_changed_files "${TARGET_BRANCH}":"${TARGET_BRANCH}" && exit_status=$? || exit_status=$?
|
||||||
PREVIOUS_SHA=$(git rev-parse "${TARGET_BRANCH}" 2>&1) && exit_status=$? || exit_status=$?
|
PREVIOUS_SHA=$(git rev-parse "${TARGET_BRANCH}" 2>&1) && exit_status=$? || exit_status=$?
|
||||||
else
|
else
|
||||||
git fetch --no-tags -u --progress --depth=1 temp_changed_files "$INPUT_BASE_SHA"
|
git fetch --no-tags -u --progress --depth=1 temp_changed_files "$INPUT_BASE_SHA" && exit_status=$? || exit_status=$?
|
||||||
PREVIOUS_SHA=$INPUT_BASE_SHA
|
PREVIOUS_SHA=$INPUT_BASE_SHA
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
git rev-parse --quiet --verify "$PREVIOUS_SHA^{commit}" 1>/dev/null 2>&1 && exit_status=$? || exit_status=$?
|
||||||
|
|
||||||
if [[ $exit_status -ne 0 ]]; then
|
if [[ $exit_status -ne 0 ]]; then
|
||||||
echo "::warning::Unable to determine the base ref sha for ${TARGET_BRANCH}"
|
echo "::warning::Unable to locate the previous sha: $PREVIOUS_SHA"
|
||||||
echo "::warning::You seem to be missing 'fetch-depth: 0' or 'fetch-depth: 2'. See https://github.com/tj-actions/changed-files#usage"
|
echo "::warning::You seem to be missing 'fetch-depth: 0' or 'fetch-depth: 2'. See https://github.com/tj-actions/changed-files#usage"
|
||||||
git remote remove temp_changed_files
|
git remote remove temp_changed_files
|
||||||
exit 1
|
exit 1
|
||||||
@ -81,8 +89,9 @@ fi
|
|||||||
|
|
||||||
echo "Retrieving changes between $PREVIOUS_SHA ($TARGET_BRANCH) → $CURRENT_SHA ($CURRENT_BRANCH)"
|
echo "Retrieving changes between $PREVIOUS_SHA ($TARGET_BRANCH) → $CURRENT_SHA ($CURRENT_BRANCH)"
|
||||||
|
|
||||||
|
echo "Getting diff..."
|
||||||
|
|
||||||
if [[ -z "${INPUT_FILES[*]}" ]]; then
|
if [[ -z "${INPUT_FILES[*]}" ]]; then
|
||||||
echo "Getting diff..."
|
|
||||||
ADDED=$(git diff --diff-filter=A --name-only "$PREVIOUS_SHA" "$CURRENT_SHA" | awk -v d="$INPUT_SEPARATOR" '{s=(NR==1?s:s d)$0}END{print s}')
|
ADDED=$(git diff --diff-filter=A --name-only "$PREVIOUS_SHA" "$CURRENT_SHA" | awk -v d="$INPUT_SEPARATOR" '{s=(NR==1?s:s d)$0}END{print s}')
|
||||||
COPIED=$(git diff --diff-filter=C --name-only "$PREVIOUS_SHA" "$CURRENT_SHA" | awk -v d="$INPUT_SEPARATOR" '{s=(NR==1?s:s d)$0}END{print s}')
|
COPIED=$(git diff --diff-filter=C --name-only "$PREVIOUS_SHA" "$CURRENT_SHA" | awk -v d="$INPUT_SEPARATOR" '{s=(NR==1?s:s d)$0}END{print s}')
|
||||||
DELETED=$(git diff --diff-filter=D --name-only "$PREVIOUS_SHA" "$CURRENT_SHA" | awk -v d="$INPUT_SEPARATOR" '{s=(NR==1?s:s d)$0}END{print s}')
|
DELETED=$(git diff --diff-filter=D --name-only "$PREVIOUS_SHA" "$CURRENT_SHA" | awk -v d="$INPUT_SEPARATOR" '{s=(NR==1?s:s d)$0}END{print s}')
|
||||||
@ -94,7 +103,6 @@ if [[ -z "${INPUT_FILES[*]}" ]]; then
|
|||||||
ALL_CHANGED_AND_MODIFIED=$(git diff --diff-filter="*ACDMRTUX" --name-only "$PREVIOUS_SHA" "$CURRENT_SHA" | awk -v d="$INPUT_SEPARATOR" '{s=(NR==1?s:s d)$0}END{print s}')
|
ALL_CHANGED_AND_MODIFIED=$(git diff --diff-filter="*ACDMRTUX" --name-only "$PREVIOUS_SHA" "$CURRENT_SHA" | awk -v d="$INPUT_SEPARATOR" '{s=(NR==1?s:s d)$0}END{print s}')
|
||||||
ALL_MODIFIED=$(git diff --diff-filter="ACMR" --name-only "$PREVIOUS_SHA" "$CURRENT_SHA" | awk -v d="$INPUT_SEPARATOR" '{s=(NR==1?s:s d)$0}END{print s}')
|
ALL_MODIFIED=$(git diff --diff-filter="ACMR" --name-only "$PREVIOUS_SHA" "$CURRENT_SHA" | awk -v d="$INPUT_SEPARATOR" '{s=(NR==1?s:s d)$0}END{print s}')
|
||||||
else
|
else
|
||||||
|
|
||||||
echo "Input files: ${INPUT_FILES[*]}"
|
echo "Input files: ${INPUT_FILES[*]}"
|
||||||
|
|
||||||
FILES=$(echo "${INPUT_FILES[*]}" | awk '{gsub(/ /,"\n"); print $0;}' | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}')
|
FILES=$(echo "${INPUT_FILES[*]}" | awk '{gsub(/ /,"\n"); print $0;}' | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user