Skip to content

Commit 93130f3

Browse files
authored
Merge pull request #102 from UoMResearchIT/omit-workflows-from-commits
Trying to allow excluding a path
2 parents e189e38 + 482804f commit 93130f3

File tree

3 files changed

+28
-12
lines changed

3 files changed

+28
-12
lines changed

.github/workflows/apply-reuse.yml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ on:
3939
outputs:
4040
check-failed:
4141
description: "Whether the check applied by this workflow 'failed'."
42-
value: ${{ jobs.add-headers.outputs.made-change == 1 }}
42+
value: ${{ jobs.add-headers.outputs.made-change }}
4343
branch-created:
4444
description: "If a branch was created, the name of that branch."
45-
value: ${{ jobs.add-headers.outputs.made-change == 1 && jobs.add-headers.outputs.branch || '' }}
45+
value: ${{ jobs.add-headers.outputs.made-change && jobs.add-headers.outputs.branch || '' }}
4646
branches-deleted:
4747
description: "If some branches were delete, what branches were they."
4848
value: ${{ jobs.add-headers.outputs.deleted }}
@@ -86,27 +86,28 @@ jobs:
8686
working-directory: ${{ inputs.work-dir }}
8787
branch-prefix: add-license-headers-to
8888
commit-message: Add License and Copyright Headers
89+
exclude: .github/workflows/*
8990

9091
annotate:
9192
runs-on: ubuntu-latest
9293
concurrency: prune:bot-comments
9394
needs: add-headers
9495
steps:
9596
- name: Commit comment
96-
if: needs.add-headers.outputs.made-change == 1
97+
if: needs.add-headers.outputs.made-change
9798
uses: peter-evans/commit-comment@v4
9899
with:
99100
body: >
100101
Copyright updates at [.../compare/${{ inputs.branch }}...${{ needs.add-headers.outputs.branch }}](${{ github.server_url }}/${{ github.repository }}/compare/${{ inputs.branch }}...${{ needs.add-headers.outputs.branch }}?expand=1), please review and merge.
101102
102103
- name: Hide old PR comments
103-
if: needs.add-headers.outputs.made-change == 0
104+
if: ${{ !needs.add-headers.outputs.made-change }}
104105
uses: kanga333/comment-hider@v0.4.0
105106
with:
106107
github_token: ${{ secrets.GITHUB_TOKEN }}
107108

108109
- name: PR comment
109-
if: needs.add-headers.outputs.made-change == 1
110+
if: needs.add-headers.outputs.made-change
110111
uses: mshick/add-pr-comment@v2
111112
with:
112113
refresh-message-position: true
@@ -115,7 +116,7 @@ jobs:
115116
There are copyright updates on the (temporary) [${{ needs.add-headers.outputs.branch }} branch](${{ github.server_url }}/${{ github.repository }}/compare/${{ inputs.branch }}...${{ needs.add-headers.outputs.branch }}?expand=1). Please review and merge, or add further commits (this branch will be deleted).
116117
117118
- name: Fail marker
118-
if: needs.add-headers.outputs.made-change == 1
119+
if: needs.add-headers.outputs.made-change
119120
uses: actions/github-script@v8
120121
with:
121122
script: |

git-push-changes-to-branch/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ Example:
6363
* `branch`
6464

6565
The name of the branch that may have been created.
66-
NB: The branch is only created if the `changed` output is `1`.
66+
NB: The branch is only created if the `changed` output is `true`.
6767

6868
* `changed`
6969

70-
Whether there were any changes committed. (`1` if yes, `0` if no.)
70+
Whether there were any changes committed. (`true` if yes, `false` if no.)
7171

7272
## Permissions
7373
Required permission:

git-push-changes-to-branch/action.yml

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ inputs:
4747
description: >
4848
The email address of the user to ascribe the commit to.
4949
default: no-reply@github.com
50+
exclude:
51+
description: >
52+
A pattern to describe what files to omit from the committed.
53+
default: ""
5054
outputs:
5155
branch:
5256
description: >
@@ -55,7 +59,7 @@ outputs:
5559
changed:
5660
description: >
5761
Whether there were any changes committed.
58-
value: ${{ steps.detect.outputs.changed }}
62+
value: ${{ steps.detect.outputs.changed == 1 && steps.push.outputs.pushed == 1 }}
5963
runs:
6064
using: composite
6165
steps:
@@ -92,14 +96,25 @@ runs:
9296
USER_EMAIL: ${{ inputs.commit-user-email }}
9397
- name: push changes
9498
if: steps.detect.outputs.changed == 1
99+
id: push
95100
working-directory: ${{ inputs.working-directory }}
96101
run: |
97102
git checkout -b "$NEW_BRANCH"
98-
git add -A
99-
git commit -a -m "$MESSAGE"
100-
git push origin "$NEW_BRANCH"
103+
if [ -z "$EXCLUDE" ]; then
104+
git add -A
105+
else
106+
git add --all -- "${EXCLUDE/#/:!}"
107+
fi
108+
if git diff --cached --exit-code >/dev/null; then
109+
echo "pushed=0" >> $GITHUB_OUTPUT
110+
else
111+
git commit -a -m "$MESSAGE"
112+
git push origin "$NEW_BRANCH"
113+
echo "pushed=1" >> $GITHUB_OUTPUT
114+
fi
101115
shell: bash
102116
env:
103117
GH_TOKEN: ${{ inputs.token }}
104118
NEW_BRANCH: ${{ steps.name.outputs.branch }}
105119
MESSAGE: ${{ inputs.commit-message }}
120+
EXCLUDE: ${{ inputs.exclude }}

0 commit comments

Comments
 (0)