Skip to content

Commit 09a98db

Browse files
authored
/src/scripts: manifest-update scripts (zephyrproject-rtos#15)
- Minor cleanup, tweaks to tag_main.sh. - Added the pr_comment.sh script * writes a comment to a PR with the rebase tag info * Works for both zephyr and zephyr-intel manifest update PRs Signed-off-by: Connor Graydon <[email protected]>
1 parent ccdd7c8 commit 09a98db

File tree

2 files changed

+162
-2
lines changed

2 files changed

+162
-2
lines changed

src/scripts/pr_comment.sh

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
#!/bin/bash
2+
3+
############################################################################
4+
#
5+
# Push a comment to a manifest rebase PR with the SHA and tag info.
6+
#
7+
# Usage: ./pr_comment <repo> <pr#> <tag>
8+
# Zephyr Example:
9+
#
10+
# ./pr_comment zephyr 123 zephyr-3.0.99-intel-20220524
11+
#
12+
# Zephyr-intel Example:
13+
#
14+
# ./pr_comment zephyr-intel 456 zephyr-3.0.99-intel-20220524
15+
#
16+
# The tag must already exist in the zephyr repo.
17+
#
18+
# If the PR exists, a comment is generated for the PR noting the SHA and
19+
# tag name for the main-intel revision we are "archiving."
20+
#
21+
# A comment is generated and then pushed to the PR.
22+
#
23+
# WARNING: THIS WILL GLEEFULLY PUSH THE COMMENT TO ANY VALID PR# YOU GIVE IT.
24+
# MAKE SURE YOU GIVE IT THE RIGHT ONE OR YOU WILL NEED TO GO CLEAN THAT UP.
25+
#
26+
############################################################################
27+
28+
export WORKDIR=/srv/build # or whatever your workdir is
29+
PR_REPO="$1"
30+
PR="$2"
31+
TAG="$3"
32+
ZEPHYR_REPO="[email protected]:intel-innersource/os.rtos.zephyr.zephyr.git"
33+
ZEPHYR_INTEL_REPO="[email protected]:intel-innersource/os.rtos.zephyr.zephyr-intel.git"
34+
BODY_FILE=$WORKDIR/body.txt
35+
36+
echo "You gave me:"
37+
echo "PR_REPO: $PR_DIR"
38+
echo "PR: $PR"
39+
echo "TAG: $TAG"
40+
echo
41+
42+
if [ "$PR_REPO" == "" ] || [ "$PR" == "" ] || [ "$TAG" == "" ]; then
43+
echo "Usage: ./pr_comment <repo> <pr#> <tag>"
44+
echo " ./pr_comment zephyr 123 zephyr-3.0.99-intel-20220524"
45+
echo "./pr_comment zephyr-intel 456 zephyr-3.0.99-intel-20220524"
46+
exit
47+
fi
48+
49+
function clone_repo()
50+
{
51+
# If repo exists hard reset everything and reuse it
52+
if [ -d $WORKDIR/$REPO_DIR ]; then
53+
echo "Found an existing $REPO_DIR repo. Reuse it? This will annihilate any unpushed changes."
54+
while true
55+
do
56+
read -r -p "REUSE IT? Y/N: " choice
57+
case "$choice" in
58+
n|N) echo "NOT reusing. Bye!"
59+
exit
60+
;;
61+
y|Y) echo "You said DO IT. Resetting repo."
62+
cd $REPO_DIR
63+
#git fetch origin --tags
64+
git checkout $BRANCH
65+
git reset --hard origin/$BRANCH
66+
git clean -d --force
67+
# We only care about the tags if we are reusing zephyr repo.
68+
# We never look at tags on zephyr-intel.
69+
if [ "$REPO_DIR" == "zephyr" ]; then
70+
git tag -l | xargs git tag -d && git fetch --tags
71+
fi
72+
break
73+
;;
74+
*) echo "Wut? Choose Y/n";;
75+
esac
76+
done
77+
fi
78+
79+
echo
80+
if [[ ! -d $WORKDIR/$REPO_DIR ]]; then
81+
echo "CLONE THE REPO"
82+
if ! git clone $REPO_URL $REPO_DIR; then
83+
echo "Failed to checkout $REPO_URL."
84+
exit
85+
else
86+
cd $REPO_DIR
87+
fi
88+
fi
89+
}
90+
91+
# Set up WORKDIR, if it doesn't already exist
92+
if [ ! -d $WORKDIR ]; then
93+
mkdir -p $WORKDIR
94+
chmod 777 $WORKDIR
95+
fi
96+
cd $WORKDIR
97+
98+
# First we clone Zephyr, cuz we have to find the tag info.
99+
REPO_DIR="zephyr"
100+
BRANCH="main-intel"
101+
REPO_URL=$ZEPHYR_REPO
102+
clone_repo
103+
104+
# Does the tag exist?
105+
if git rev-parse "$TAG" > /dev/null 2>&1; then
106+
FOUND="true"
107+
echo "FOUND TAG: $TAG"
108+
else
109+
echo "Can't find tag $TAG. Did you push it?"
110+
exit
111+
fi
112+
113+
# Uncomment this if you want to spew the tag details out to screen."
114+
#git --no-pager show $TAG
115+
#echo
116+
117+
# Get the SHA the tag points to.
118+
SHA=`git rev-list -n 1 $TAG`
119+
echo "SHA: $SHA"
120+
echo
121+
122+
echo "Zephyr repo main-intel $SHA has been tagged as $TAG" > $BODY_FILE
123+
124+
# If we are commenting on zephyr-intel PR, get that repo.
125+
if [ "$PR_REPO" == "zephyr-intel" ]; then
126+
cd $WORKDIR
127+
REPO_DIR="$PR_REPO"
128+
BRANCH="main"
129+
REPO_URL=$ZEPHYR_INTEL_REPO
130+
clone_repo
131+
fi
132+
133+
# Does our PR exist??
134+
# EXISTS DOESN'T GUARANTEE IT IS THE RIGHT ONE! Make sure you have the correct PR for the right repo!
135+
136+
if `gh pr view $PR > /dev/null 2>&1`; then
137+
echo "PR $PR exists";
138+
else
139+
echo "Can't find PR $PR. Go Fish"
140+
exit
141+
fi
142+
143+
# Write the comment to the PR
144+
echo "Writing the comment to PR $PR."
145+
146+
while true
147+
do
148+
read -r -p "PUSH THE PR COMMENT? Y/N: " choice
149+
case "$choice" in
150+
n|N) echo "NOT PUSHING THE COMMENT to $PR_REPO $PR. Bye!"
151+
exit
152+
;;
153+
y|Y) echo "PUSHING THE PR COMMENT to $PR_REPO $PR."
154+
gh pr comment $PR -F $BODY_FILE
155+
cat $BODY_FILE
156+
break
157+
;;
158+
*) echo "Wut? Choose Y/n";;
159+
esac
160+
done
161+
162+
rm $BODY_FILE

src/scripts/tag_main.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ if [ -d $WORKDIR/$REPO_DIR ]; then
3838
;;
3939
y|Y) echo "You said DO IT. Resetting repo."
4040
cd $REPO_DIR
41-
git fetch origin --tags
4241
git checkout $BRANCH
4342
git reset --hard origin/$BRANCH
4443
git clean -d --force
@@ -112,7 +111,6 @@ while true; do
112111
done
113112

114113
git tag -a -m "$TAG" $TAG
115-
#git push origin $TAG
116114
}
117115

118116
echo; echo

0 commit comments

Comments
 (0)