-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommit_and_push.sh
42 lines (35 loc) · 969 Bytes
/
commit_and_push.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
function commit_and_push() {
local commit_message=""
local amend=false
# Parse command line options
while getopts "m:" opt; do
case $opt in
m)
commit_message="$OPTARG"
;;
\?)
echo "Invalid option: -$OPTARG" >&2
return 1
;;
esac
done
# If -m flag is provided, amend the previous commit with the new message
if [ -n "$commit_message" ]; then
git commit --amend -m "$commit_message"
amend=true
else
git commit -m "WIP: Work in progress"
fi
# Push the changes
git push origin HEAD
# If amending, use gh cli to remove the last workflow run
if [ "$amend" = true ]; then
branch_name=$(git branch --show-current)
last_run=$(gh run list -R -B $branch_name | head -n 1 | awk '{print $1}')
if [ -n "$last_run" ]; then
gh run cancel $last_run
fi
fi
# Start a new workflow run
gh workflow run -f <your_workflow_file.yml> -B <your_branch_name>
}