-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.sh
210 lines (174 loc) · 7.68 KB
/
main.sh
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#!/bin/bash
set -e
[[ $RUNNER_DEBUG != 1 ]] || set -x
[[ $RUNNER_DEBUG != 1 ]] || printenv
cd "$INPUT_PATH"
git status --verbose
add_pathspec=$(printenv INPUT_ADD-PATHSPEC || true)
[[ -n $add_pathspec ]] || add_pathspec=$(printenv INPUT_ADD-PATHSPECS || true)
[[ -n $add_pathspec ]] || add_pathspec=$(printenv INPUT_ADD-PATH || true)
[[ -n $add_pathspec ]] || add_pathspec=$(printenv INPUT_ADD-PATHS || true)
echo "add_pathspec=$add_pathspec"
add_pathspec_file=$(printenv INPUT_ADD-PATHSPEC-FILE || true)
[[ -n $add_pathspec_file ]] || add_pathspec_file=$(printenv INPUT_ADD-PATHSPECS-FILE || true)
[[ -n $add_pathspec_file ]] || add_pathspec_file=$(printenv INPUT_ADD-PATH-FILE || true)
[[ -n $add_pathspec_file ]] || add_pathspec_file=$(printenv INPUT_ADD-PATHS-FILE || true)
echo "add_pathspec_file=$add_pathspec_file"
add_force=$(printenv INPUT_ADD-FORCE || true)
if [[ $add_force == 1 || $add_force == true ]]; then
add_force_flag='--force'
fi
echo "add_force_flag=$add_force_flag"
if [[ -n $add_pathspec ]]; then
echo "using pathspec from input"
echo "$add_pathspec" | git add --pathspec-from-file=- $add_force_flag --verbose
elif [[ -n $add_pathspec_file ]]; then
echo "using pathspec from file"
git add --pathspec-from-file="$add_pathspec_file" $add_force_flag --verbose
else
echo "using --all"
git add --all $add_force_flag --verbose
fi
git status --verbose
if git diff --cached --exit-code --quiet; then
echo 'No changes detected'
echo "committed=false" >> $GITHUB_OUTPUT
else
commit_author_name=$(printenv INPUT_COMMIT-AUTHOR-NAME || true)
commit_author_email=$(printenv INPUT_COMMIT-AUTHOR-EMAIL || true)
echo "original commit_author_name=$commit_author_name"
echo "original commit_author_email=$commit_author_email"
# 'Name here <[email protected]>'
commit_author=$(printenv INPUT_COMMIT-AUTHOR || true)
echo "original commit_author=$commit_author"
if echo "$commit_author" | grep -qP '^\s*@?(github[-_])?actions?(\[bot\])?\s*$'; then
commit_author='github-actions[bot]'
commit_author='github-actions[bot]@users.noreply.github.com'
fi
if echo "$commit_author" | grep -qP '^\s*@?(me|author|self)\s*$'; then
commit_author=$GITHUB_ACTOR
commit_author="[email protected]"
fi
if [[ -n $commit_author ]]; then
commit_author_name=$(echo "$commit_author" | sed -r 's/^(.*) <.*>$/\1/')
commit_author_email=$(echo "$commit_author" | sed -r 's/^.* <(.*)>$/\1/')
fi
if [[ -z $commit_author_name ]]; then
commit_author_name=$(git config user.name) || true
fi
if [[ -z $commit_author_email ]]; then
commit_author_email=$(git config user.email) || true
fi
[[ -n $commit_author_name ]] || commit_author_name='github-actions[bot]'
[[ -n $commit_author_email ]] || commit_author_email='github-actions[bot]@users.noreply.github.com'
echo "processed commit_author_name=$commit_author_name"
echo "processed commit_author_email=$commit_author_email"
commit_committer_name=$(printenv INPUT_COMMIT-COMMITTER-NAME || true)
commit_committer_email=$(printenv INPUT_COMMIT-COMMITTER-EMAIL || true)
echo "original commit_committer_name=$commit_committer_name"
echo "original commit_committer_email=$commit_committer_email"
# 'Name here <emailhere@exampleorg>'
commit_committer=$(printenv INPUT_COMMIT-COMMITTER || true)
echo "original commit_committer=$commit_committer"
if echo "$commit_committer" | grep -qP '^\s*@?(github[-_])?actions?(\[bot\])?\s*$'; then
commit_committer_name='github-actions[bot]'
commit_committer_email='github-actions[bot]@users.noreply.github.com'
fi
if echo "$commit_committer" | grep -qP '^\s*@?(me|author|self)\s*$'; then
commit_committer_name=$GITHUB_ACTOR
commit_committer_email="[email protected]"
fi
if [[ -n $commit_committer ]]; then
commit_committer_name=$(echo "$commit_committer" | sed -r 's/^(.*) <.*>$/\1/')
commit_committer_email=$(echo "$commit_committer" | sed -r 's/^.* <(.*)>$/\1/')
fi
if [[ -z $commit_committer_name ]]; then
commit_committer_name=$(git config user.name) || true
fi
if [[ -z $commit_committer_email ]]; then
commit_committer_email=$(git config user.email) || true
fi
[[ -n $commit_committer_name ]] || commit_committer_name=$commit_author_name
[[ -n $commit_committer_email ]] || commit_committer_email=$commit_author_email
echo "processed commit_committer_name=$commit_committer_name"
echo "processed commit_committer_email=$commit_committer_email"
commit_message=$(printenv INPUT_COMMIT-MESSAGE || true)
echo "commit_message=$commit_message"
commit_message_file=$(printenv INPUT_COMMIT-MESSAGE-FILE || true)
echo "commit_message_file=$commit_message_file"
commit_date=$(printenv INPUT_COMMIT-DATE || true)
if [[ -n $commit_date ]]; then
commit_date_flag="--date=$commit_date"
fi
echo "commit_date_flag=$commit_date_flag"
export GIT_AUTHOR_NAME="$commit_author_name"
export GIT_AUTHOR_EMAIL="$commit_author_email"
export GIT_COMMITTER_NAME="$commit_committer_name"
export GIT_COMMITTER_EMAIL="$commit_committer_email"
if [[ -n $commit_message ]]; then
echo "committing with message"
git commit --message="$commit_message" --verbose $commit_date_flag
elif [[ -n $commit_message_file ]]; then
echo "committing with message file"
git commit --file="$commit_message_file" --verbose $commit_date_flag
else
echo "committing with default message"
git commit --message="Automated changes" --verbose $commit_date_flag
fi
unset GIT_AUTHOR_NAME
unset GIT_AUTHOR_EMAIL
unset GIT_COMMITTER_NAME
unset GIT_COMMITTER_EMAIL
echo "committed=true" >> $GITHUB_OUTPUT
echo "commit-sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
fi
git status --verbose
push_repository=$(printenv INPUT_PUSH-REPOSITORY || true)
[[ -n $push_repository ]] || push_repository=$(printenv INPUT_PUSH-REPO || true)
[[ -n $push_repository ]] || push_repository=$(printenv INPUT_PUSH-REMOTE || true)
[[ -n $push_repository ]] || push_repository=$(printenv INPUT_PUSH-TO || true)
[[ -n $push_repository ]] || push_repository=$(printenv INPUT_PUSH-TO-REPO || true)
[[ -n $push_repository ]] || push_repository=$(printenv INPUT_PUSH-TO-REPOSITORY || true)
[[ -n $push_repository ]] || push_repository=$(printenv INPUT_PUSH-TO-REMOTE || true)
[[ -n $push_repository ]] || push_repository=origin
echo "push_repository=$push_repository"
if git cherry -v origin | grep -qP '^\+'; then
push_refspec=$(printenv INPUT_PUSH-REFSPEC || true)
[[ -n $push_refspec ]] || push_refspec=$(printenv INPUT_PUSH-REF || true)
[[ -n $push_refspec ]] || push_refspec=$(printenv INPUT_PUSH-BRANCH || true)
[[ -n $push_refspec ]] || push_refspec=$(printenv INPUT_PUSH-TAG || true)
echo "original push_refspec=$push_refspec"
push_all=$(printenv INPUT_PUSH-ALL || true)
if [[ $push_all == 1 || $push_all == true ]]; then
push_refspec='all'
fi
if [[ $push_refspec == all ]]; then
push_refspec='--all'
fi
if [[ $push_refspec != '--all' ]]; then
if [[ -z $push_refspec ]]; then
push_refspec=$(git symbolic-ref HEAD)
fi
if [[ $push_refspec != HEAD:* ]]; then
push_refspec="HEAD:$push_refspec"
fi
fi
echo "processed push_refspec=$push_refspec"
push_force=$(printenv INPUT_PUSH-FORCE || true)
if [[ $push_force == 1 || $push_force == true ]]; then
push_force_flag='--force'
fi
echo "push_force_flag=$push_force_flag"
if [[ -n $push_refspec ]]; then
echo "pushing with refspec"
git push "$push_repository" "$push_refspec" $push_force_flag --verbose
else
echo "pushing with no refspec"
git push "$push_repository" $push_force_flag --verbose
fi
echo "pushed=true" >> $GITHUB_OUTPUT
else
echo 'No changes to push'
echo "pushed=false" >> $GITHUB_OUTPUT
fi
git status --verbose