Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 90 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -450,4 +450,93 @@ jobs:
exit 1
fi

echo "Validation passed: changedFilesIfAvailable is $changedFilesIfAvailable."
echo "Validation passed: changedFilesIfAvailable is $changedFilesIfAvailable."

test-fail-if-no-changes: # make sure the action works on a clean machine without building
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Setup test branch
id: setup-test-branch
run: |
BRANCH_NAME="test_failure_no-changes-$(date +%s)"

git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'

git checkout -b $BRANCH_NAME
git push --set-upstream origin $BRANCH_NAME

# output status here to manually verify file changes
git status --porcelain=v2 --branch --untracked-files=no

echo "branch-name=$BRANCH_NAME" >> $GITHUB_OUTPUT
- uses: ./
id: test-action
continue-on-error: true
with:
token: ${{ github.token }}
commit-message: ${{ steps.setup-test-branch.outputs.branch-name }}
- name: Check output is failure
if: ${{ failure() }}
run: |
if [[ -z "${{ steps.test-action.outputs.commit-response }}" ]]; then
echo "Validation passed: commit-response is empty."
else
echo "Error: commit-response is expected to be empty but got not empty."
exit 1
fi
- name: Check output is success
if: ${{ success() }}
run: |
echo "Error: action status is expected to be failure but got success."
exit 1
- name: Delete test branch
if: ${{ always() }}
run: |
git push --force --delete origin ${{ steps.setup-test-branch.outputs.branch-name }}

test-success-if-no-changes: # make sure the action works on a clean machine without building
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Setup test branch
id: setup-test-branch
run: |
BRANCH_NAME="test_success_no-changes-$(date +%s)"

git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'

git checkout -b $BRANCH_NAME
git push --set-upstream origin $BRANCH_NAME

# output status here to manually verify file changes
git status --porcelain=v2 --branch --untracked-files=no

echo "branch-name=$BRANCH_NAME" >> $GITHUB_OUTPUT
- uses: ./
id: test-action
continue-on-error: true
with:
token: ${{ github.token }}
success-if-no-changes: true
commit-message: ${{ steps.setup-test-branch.outputs.branch-name }}
- name: Check output is failure
if: ${{ failure() }}
run: |
echo "Error: action status is expected to be success but got failure."
exit 1
- name: Check output is success
if: ${{ success() }}
run: |
if [[ -z "${{ steps.test-action.outputs.commit-response }}" ]]; then
echo "Validation passed: commit-response is empty."
else
echo "Error: commit-response is expected to be empty but got not empty."
exit 1
fi
- name: Delete test branch
if: ${{ always() }}
run: |
git push --force --delete origin ${{ steps.setup-test-branch.outputs.branch-name }}
14 changes: 13 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ inputs:
required: true
description: 'Whether to additionally stage all changed files in the repo prior to committing: true/false'
default: 'false'
success-if-no-changes:
required: true
description: 'Whether to return success if no changes are detected: true/false'
default: 'false'
token:
required: true
description: 'GitHub access token with permissions to write to repo'
Expand Down Expand Up @@ -119,7 +123,13 @@ runs:

if [[ "$additions" == "" && "$deletions" == "" ]]; then
echo "No changes to commit"
exit 1
echo "any_changed=false" >> $GITHUB_OUTPUT

if [[ "${{ inputs.success-if-no-changes }}" == "true" ]]; then
exit 0
else
exit 1
fi
fi

if [[ "$additions" == "" ]]; then
Expand All @@ -131,10 +141,12 @@ runs:
fi

# Set outputs for the next step
echo "any_changed=true" >> $GITHUB_OUTPUT
echo "additions=$additions" >> $GITHUB_OUTPUT
echo "deletions=$deletions" >> $GITHUB_OUTPUT

- name: Commit changes
if: ${{ steps.additions-and-deletions.outputs.any_changed == 'true' }}
shell: bash
id: commit-changes
run: |
Expand Down
Loading