-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yml
More file actions
120 lines (119 loc) · 3.76 KB
/
action.yml
File metadata and controls
120 lines (119 loc) · 3.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# Copyright (c) 2025 The University of Manchester
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
name: Push Changes to Git Branch
description: >
Detects if there are changes; if there are, commits them to a new branch.
author: Donal Fellows, Andrew Rowley, Douglas Lowe
branding:
color: gray-dark
icon: git-commit
inputs:
working-directory:
description: >
Which working directory to look at.
Defaults to the base directory.
default: ${{ github.workspace }}
branch-prefix:
description: >
Prefix of the branch name to use.
You should change this!
default: autocommit
token:
description: >
Access token used for writing the new branch to the repository.
default: ${{ github.token }}
commit-message:
description: >
The commit message to use.
default: >
Changes generated by workflow
commit-user-name:
description: >
The name of the user to ascribe the commit to.
default: GitHub Actions
commit-user-email:
description: >
The email address of the user to ascribe the commit to.
default: no-reply@github.com
exclude:
description: >
A pattern to describe what files to omit from the committed.
default: ""
outputs:
branch:
description: >
The name of the branch that may have been created.
value: ${{ steps.name.outputs.branch }}
changed:
description: >
Whether there were any changes committed.
value: ${{ steps.detect.outputs.changed == 1 && steps.push.outputs.pushed == 1 }}
runs:
using: composite
steps:
- name: make branch name
id: name
run: |
NOW=$(date +'%Y-%m-%d-%H-%M-%S')
echo "branch=$PREFIX-$GITHUB_HEAD_REF-$NOW" >> $GITHUB_OUTPUT
shell: bash
env:
PREFIX: ${{ inputs.branch-prefix }}
- name: detect changes
id: detect
working-directory: ${{ inputs.working-directory }}
run: |
set +e
git diff --quiet
CHANGED_FILES=$?
NEW_FILES=$(git ls-files . --exclude-standard --others | wc -l)
if [ $CHANGED_FILES -eq 1 ] || [ $NEW_FILES -ne 0 ]; then
echo "changed=1" >> $GITHUB_OUTPUT
else
echo "changed=0" >> $GITHUB_OUTPUT
fi
shell: bash
- name: configure git
if: steps.detect.outputs.changed == 1
run: |
git config --global user.email "$USER_EMAIL"
git config --global user.name "$USER_NAME"
shell: bash
env:
USER_NAME: ${{ inputs.commit-user-name }}
USER_EMAIL: ${{ inputs.commit-user-email }}
- name: push changes
if: steps.detect.outputs.changed == 1
id: push
working-directory: ${{ inputs.working-directory }}
run: |
git checkout -b "$NEW_BRANCH"
if [ -z "$EXCLUDE" ]; then
git add --all
else
git add --all -- "${EXCLUDE/#/:!}"
fi
if git diff --cached --exit-code >/dev/null; then
echo "pushed=0" >> $GITHUB_OUTPUT
else
git commit -m "$MESSAGE"
git push origin "$NEW_BRANCH"
echo "pushed=1" >> $GITHUB_OUTPUT
fi
shell: bash
env:
GH_TOKEN: ${{ inputs.token }}
NEW_BRANCH: ${{ steps.name.outputs.branch }}
MESSAGE: ${{ inputs.commit-message }}
EXCLUDE: ${{ inputs.exclude }}