Repository navigation
Expand file tree
/
Copy pathaction.yml
More file actions
76 lines (66 loc) · 2.12 KB
/
Copy pathaction.yml
File metadata and controls
76 lines (66 loc) · 2.12 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
name: Git Commit and Push
description: Commit selected paths and push with rebase/retry handling.
inputs:
branch:
description: Branch to push to.
required: true
message:
description: Commit message.
required: true
paths:
description: Newline-separated list of paths to add.
required: true
outputs:
pushed:
description: Whether a commit was pushed.
value: ${{ steps.push.outputs.pushed }}
sha:
description: SHA of the pushed commit, when a commit was created.
value: ${{ steps.push.outputs.sha }}
runs:
using: composite
steps:
- name: Commit and push changes
id: push
shell: bash
env:
TARGET_BRANCH: ${{ inputs.branch }}
COMMIT_MESSAGE: ${{ inputs.message }}
PATHS: ${{ inputs.paths }}
run: |
set -euo pipefail
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# Rebase before staging so generated updates apply to the newest branch tip.
git pull --rebase --autostash origin "$TARGET_BRANCH"
while IFS= read -r path; do
[ -z "$path" ] && continue
if [ -e "$path" ]; then
git add "$path"
else
echo "::warning::Path not found, skipping: $path"
fi
done <<< "$PATHS"
if git diff --staged --quiet; then
echo "No changes to commit."
echo "pushed=false" >> "$GITHUB_OUTPUT"
exit 0
fi
git commit -m "$COMMIT_MESSAGE"
for attempt in 1 2 3; do
new_sha="$(git rev-parse HEAD)"
if git push origin "HEAD:${TARGET_BRANCH}"; then
echo "pushed=true" >> "$GITHUB_OUTPUT"
echo "sha=${new_sha}" >> "$GITHUB_OUTPUT"
exit 0
fi
echo "::warning::Push failed (attempt ${attempt}); rebasing and retrying."
git pull --rebase --autostash origin "$TARGET_BRANCH" || {
git rebase --abort || true
if [ "$attempt" -eq 3 ]; then
exit 1
fi
}
sleep $((attempt * 3))
done
exit 1