This repository has been archived by the owner on Feb 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfork.sh
executable file
·86 lines (72 loc) · 2.2 KB
/
fork.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
# fork.sh
# this script forks the framework at a given branch into a given existing (but empty) WildStang repo
# it then adds a tag to this repo
UPSTREAM="git@github.com:wildstang/robot_framework.git"
GITHUB="git@github.com:wildstang"
UPSTREAM_BRANCH="main"
fork=$1
branch=$2
# check parameters
if [ $# -lt 1 ]; then
echo "Fork repository name is required"
exit 1
elif [ $# -lt 2 ]; then
branch=$UPSTREAM_BRANCH
fi
# update to upstream
if [ $fork == "update" ]; then
git remote add upstream $UPSTREAM
git pull upstream $branch
git push
exit 0
fi
# clone and enter repo
git clone $UPSTREAM framework_fork
cd framework_fork
# add new remote and push
git remote add fork "${GITHUB}/${fork}"
git push fork $branch:$UPSTREAM_BRANCH
error=$?
if [ $error -eq 128 ]; then
echo ""
echo "Repo \"${GITHUB}/${fork}\" could not be found"
cd ..
rm -rf framework_fork
exit 2
elif [ $error -eq 1 ]; then
echo ""
echo "Branch \"${branch}\" could not be found"
cd ..
rm -rf framework_fork
exit 3
fi
# add tag to framework
git tag -a $fork -m "wildstang/${fork} forked from here"
git push origin $fork
# remove old repo and reclone
cd ..
rm -rf framework_fork
git clone "${GITHUB}/${fork}"
cd $fork
# update year
if [[ $fork =~ ^20[0-9]{2}_ ]]; then
year=$(echo $fork | cut -c1-4)
# make new year20XX package
cp -r src/main/java/org/wildstang/sample "src/main/java/org/wildstang/year${year}"
# rename package in all files
grep -rlF "wildstang.sample" "src/main/java/org/wildstang/year${year}" | xargs sed -i "s/wildstang.sample/wildstang.year${year}/g"
# update package name for gradle ROBOT_MAIN_CLASS
sed -i "s/sample/year${year}/" build.gradle
# don't overwrite up-to-date gradle versions
if ! grep -q "\"${year}." build.gradle; then
# update gradle version
sed -i "s/20[0-9]\{2\}\.[0-9]\.[0-9]/${year}.1.1/" build.gradle
fi
# update frcYear for gradle
sed -i "s/20[0-9]\{2\}/${year}/" settings.gradle
# update projectYear for wpilib
sed -i "s/20[0-9]\{2\}/${year}/" .wpilib/wpilib_preferences.json
echo ""
echo "Project years updated, check git changes to confirm then commit and push."
fi