-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpatch.sh
executable file
·86 lines (78 loc) · 2.15 KB
/
patch.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
#!/bin/bash
#set -o xtrace
BRANCH_NAME=
PR_TITLE=
PR_BODY=
JBANG_SCRIPT=
FILTER_REPOS=.
# This script is used to patch all Quarkiverse repositories
while getopts "b:t:m:j:f:" OPT; do
case "$OPT" in
"b") BRANCH_NAME=$OPTARG ;;
"t") PR_TITLE=$OPTARG ;;
"m") PR_BODY=$OPTARG ;;
"j") JBANG_SCRIPT=$OPTARG ;;
"f") FILTER_REPOS=$OPTARG ;;
"?") exit -1 ;;
esac
done
# Check that all parameters are set
if [ -z "$BRANCH_NAME" ]; then
echo "Branch name is not set"
exit -1
fi
if [ -z "$PR_TITLE" ]; then
echo "Pull-request title is not set"
exit -1
fi
if [ -z "$PR_BODY" ]; then
echo "Pull-request body is not set"
exit -1
fi
if [ -z "$JBANG_SCRIPT" ]; then
echo "JBang script is not set"
exit -1
fi
apply_patch() {
# Invoke the JBang script
jbang run $JBANG_SCRIPT $1
}
CURRENT_DIR=$(pwd)
# Create temporary directory
WORK_DIR=$(mktemp -d 2>/dev/null || mktemp -d -t 'mytmpdir')
echo "Working in temp directory $WORK_DIR"
cd $WORK_DIR
# Iterate through all Quarkiverse repositories and apply the patch
gh repo list quarkiverse --jq '.[].nameWithOwner' --topic quarkus-extension --json nameWithOwner --no-archived -L 1000 | sort | grep $FILTER_REPOS | while read repo; do
cd $WORK_DIR
echo -e "\n-> Processing $repo"
# Clone the repository
gh repo clone $repo -- -q
# Change directory
cd $(basename $repo)
# Skip if the branch already exists
if [[ -z $(git ls-remote --heads origin $BRANCH_NAME) ]]; then
# Checkout the branch
git switch -c $BRANCH_NAME
# Invoke the patch function
apply_patch $repo
# Check if there are changes in the git repository
if [[ -n $(git status -s) ]]; then
# Invoke formatter
mvn clean process-sources
# Commit the changes
git add . && git commit -m "$PR_TITLE"
# Push the changes
git push origin $BRANCH_NAME
# Create the pull-request
gh pr create --title "$PR_TITLE" --body "$PR_BODY" | tee -a $CURRENT_DIR/pull-requests.txt
else
echo "No changes in $repo"
fi
else
echo "No changes in $repo, branch $BRANCH_NAME already exists"
fi
done
# Remove temporary directory
echo "Cleaning up temp directory $WORK_DIR"
rm -rf $WORK_DIR