Skip to content

Commit

Permalink
Skip if nothing to commit
Browse files Browse the repository at this point in the history
  • Loading branch information
cYKatherine committed Oct 28, 2024
1 parent 6646bc7 commit c44a95d
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions actions/commit_pr_and_merge/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,16 @@ runs:
using: "composite"

steps:
- name: Check for changes
id: changes
run: |
if [[ -n $(git status --porcelain) ]]; then
echo "changes_exist=true" >> $GITHUB_OUTPUT
fi
- name: Commit to new branch
uses: EndBug/add-and-commit@v9
if: steps.changes.outputs.changes_exist == 'true'
id: create-branch-and-commit
with:
message: '[CI Pipeline] ${{ inputs.message }}'
Expand All @@ -40,6 +48,7 @@ runs:

- name: Create PR
uses: actions/github-script@v7
if: steps.changes.outputs.changes_exist == 'true'
id: create-pr
with:
script: |
Expand All @@ -56,6 +65,7 @@ runs:
- name: Merge PR
run: gh pr merge $PR_URL --delete-branch $MERGE_PR_STRATEGY
if: steps.changes.outputs.changes_exist == 'true'
shell: bash
env:
GITHUB_TOKEN: ${{ github.token }}
Expand All @@ -65,7 +75,7 @@ runs:
- name: Tag commit
uses: actions/github-script@v7
id: tag-commit
if: ${{ inputs.tag }}
if: ${{ inputs.tag }} && steps.changes.outputs.changes_exist == 'true'
with:
script: |
const pr = (await github.rest.pulls.get({
Expand All @@ -85,6 +95,7 @@ runs:
- name: Get commit SHA
uses: actions/github-script@v7
id: get-commit-sha
if: steps.changes.outputs.changes_exist == 'true'
with:
script: |
const pr = (await github.rest.pulls.get({
Expand All @@ -97,7 +108,7 @@ runs:
- name: Print outputs
uses: actions/github-script@v7
if: ${{ inputs.tag }}
if: ${{ inputs.tag }} && steps.changes.outputs.changes_exist == 'true'
with:
script: |
console.log('Result', '${{ steps.tag-commit.outcome }}');
Expand Down

0 comments on commit c44a95d

Please sign in to comment.