Skip to content

Commit

Permalink
Merge pull request #693 from tj-actions/chore/clean-up-test
Browse files Browse the repository at this point in the history
fix: bug setting until and since inputs.
  • Loading branch information
jackton1 committed Oct 16, 2022
2 parents b3d763d + a558487 commit 210f4ed
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 37 deletions.
69 changes: 45 additions & 24 deletions .github/workflows/test.yml
Expand Up @@ -84,6 +84,51 @@ jobs:
shell:
bash

test-using-since-and-until:
name: Test changed-files using since and until
runs-on: ${{ matrix.platform }}
if: github.event_name == 'push'
strategy:
fail-fast: false
max-parallel: 4
matrix:
platform: [ubuntu-latest, ubuntu-22.04, windows-latest, macos-latest, macos-11, ubuntu-18.04, windows-2022]

steps:
- name: Checkout to branch
uses: actions/checkout@v3
with:
fetch-depth: 0

- run: |
git log -1 --format="%H" --date=local --until="2022-08-20" | grep -n 8d5c4478e28f7b7189cd93c195aa9d4f0992da90
- name: Run changed-files since 2022-08-19
id: changed-files-since
uses: ./
continue-on-error: true
with:
since: "2022-08-19"

- name: Show output
run: |
echo '${{ toJSON(steps.changed-files-since.outputs) }}'
shell:
bash

- name: Run changed-files until 2022-08-20
id: changed-files-until
uses: ./
continue-on-error: true
with:
until: "2022-08-20"

- name: Show output
run: |
echo '${{ toJSON(steps.changed-files-until.outputs) }}'
shell:
bash

test-similar-base-and-commit-sha:
name: Test changed-files similar base and commit sha
runs-on: ${{ matrix.platform }}
Expand Down Expand Up @@ -357,30 +402,6 @@ jobs:
exit 1
shell:
bash
- name: Run changed-files since 2022-08-19
id: changed-files-since
uses: ./
continue-on-error: true
with:
since: "2022-08-19"
target_branch_fetch_depth: "20000"
- name: Show output
run: |
echo '${{ toJSON(steps.changed-files-since.outputs) }}'
shell:
bash
- name: Run changed-files until 2022-08-20
id: changed-files-until
uses: ./
continue-on-error: true
with:
until: "2022-08-20"
target_branch_fetch_depth: "20000"
- name: Show output
run: |
echo '${{ toJSON(steps.changed-files-until.outputs) }}'
shell:
bash
- name: Run changed-files with forward slash separator
id: changed-files-forward-slash
uses: ./
Expand Down
28 changes: 15 additions & 13 deletions diff-sha.sh
Expand Up @@ -40,19 +40,20 @@ fi

echo "::debug::Getting HEAD SHA..."

if [[ -z $INPUT_SHA ]]; then
if [[ -n "$INPUT_UNTIL" ]]; then
CURRENT_SHA=$(git log -1 --format="%H" --date=local --until="$INPUT_UNTIL") && exit_status=$? || exit_status=$?
if [[ -n "$INPUT_UNTIL" ]]; then
echo "::debug::Getting HEAD SHA for '$INPUT_UNTIL'..."
CURRENT_SHA=$(git log -1 --format="%H" --date=local --until="$INPUT_UNTIL") && exit_status=$? || exit_status=$?

if [[ $exit_status -ne 0 ]]; then
echo "::error::Invalid until date: $INPUT_UNTIL"
exit 1
fi
else
CURRENT_SHA=$(git rev-list -n 1 "HEAD" 2>&1) && exit_status=$? || exit_status=$?
if [[ $exit_status -ne 0 ]]; then
echo "::error::Invalid until date: $INPUT_UNTIL"
exit 1
fi
else
CURRENT_SHA=$INPUT_SHA; exit_status=$?
if [[ -z $INPUT_SHA ]]; then
CURRENT_SHA=$(git rev-list -n 1 "HEAD" 2>&1) && exit_status=$? || exit_status=$?
else
CURRENT_SHA=$INPUT_SHA; exit_status=$?
fi
fi

echo "::debug::Verifying the current commit SHA: $CURRENT_SHA"
Expand All @@ -72,16 +73,17 @@ if [[ -z $GITHUB_BASE_REF ]]; then
CURRENT_BRANCH=$TARGET_BRANCH && exit_status=$? || exit_status=$?

if [[ -z $INPUT_BASE_SHA ]]; then
git fetch --no-tags -u --progress origin --depth="$INPUT_TARGET_BRANCH_FETCH_DEPTH" "${TARGET_BRANCH}":"${TARGET_BRANCH}" && exit_status=$? || exit_status=$?

if [[ -n "$INPUT_SINCE" ]]; then
PREVIOUS_SHA=$(git log --format="%H" --date=local --since="$INPUT_SINCE" --reverse | head -n 1)
echo "::debug::Getting base SHA for '$INPUT_SINCE'..."
PREVIOUS_SHA=$(git log --format="%H" --date=local --since="$INPUT_SINCE" | tail -1) && exit_status=$? || exit_status=$?

if [[ -z "$PREVIOUS_SHA" ]]; then
echo "::error::Unable to locate a previous commit for the specified date: $INPUT_SINCE"
exit 1
fi
else
git fetch --no-tags -u --progress origin --depth="$INPUT_TARGET_BRANCH_FETCH_DEPTH" "${TARGET_BRANCH}":"${TARGET_BRANCH}" && exit_status=$? || exit_status=$?

PREVIOUS_SHA=""

if [[ "$GITHUB_EVENT_FORCED" == "false" ]]; then
Expand Down

0 comments on commit 210f4ed

Please sign in to comment.