-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun.sh
executable file
·118 lines (98 loc) · 2.99 KB
/
run.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/usr/bin/env bash
# this script is intended to be the entry point for running fontc_crater
# in a CI environment.
#
# This script should be copied into a new directory, and a a work scheduler
# (such as cron) should be setup to run it regularly (for instance, each night)
#
# this script is intentionally minimal and not intended to change much; all it
# should do is clone the fontc repo, and then call another script in that repo
# which will handle actually starting crater.
# the script we call in the fontc repo will use these variables to set
# arguments on fontc_crater
export FONTC_CRATER_RESULTS=$(realpath ./results)
export FONTC_CRATER_INPUT=$(realpath "gf-repos-2024-09-23.json")
GENERATED_HTML="$FONTC_CRATER_RESULTS/index.html"
LOCKFILE="$FONTC_CRATER_RESULTS/CRATER.lock"
FONTC_REPO=https://github.com/googlefonts/fontc.git
FONTC_DIR=./fontc
FONTC_REQUIREMENTS="$FONTC_DIR/resources/scripts/requirements.txt"
# relative to FONTC_DIR
SCRIPT_PATH=fontc_crater/resources/ci.sh
GITHUB_TOKEN=$(<"GITHUB_TOKEN")
cleanup() {
echo "cleaning up"
rm -rf $FONTC_DIR
rm $LOCKFILE
deactivate
# if we crashed after writing some files, stash them
git add .
git stash save "changes found at cleanup $(date '+%a %h %d %Y %H:%M')"
}
# acquire lock, or bail:
if [ -f $LOCKFILE ]; then
echo "$LOCKFILE exists (CI is already running, or failed and requires manual cleanup)"
exit 1
else
touch $LOCKFILE
fi
# make sure that the upstream repo is configured to authenticate with our token:
git remote set-url origin "https://$GITHUB_TOKEN:[email protected]/googlefonts/fontc_crater.git"
if [ $? -ne 0 ]; then
echo "failed to set upstream"
cleanup
exit 1
fi
# first make sure this repo is up to date, in case some config changes were pushed
git pull
if [ $? -ne 0 ]; then
echo "git pull failed, exiting"
cleanup
exit 1
fi
if [ -d venv ]; then
rm -rf venv
fi
echo "setting up venv"
python -m venv venv
if [ $? -ne 0 ]; then
echo could not setup venv, exiting
cleanup
exit 1
fi
source venv/bin/activate
echo "fetching fontc"
if git clone $FONTC_REPO $FONTC_DIR ; then
# install requirements:
echo "installing requirements"
pip install -r $FONTC_REQUIREMENTS
cd $FONTC_DIR
# run the actual script that starts CI:
chmod +x $SCRIPT_PATH
# pass our token through to the crater executable, it will use it to
# authenticate to private repos
( export GITHUB_TOKEN=$GITHUB_TOKEN; $SCRIPT_PATH )
if [ $? -ne 0 ]; then
echo script did not finish successfully, exiting
cleanup
exit 1
fi
cd ..
fi
# move index.html from results/ to repo root
mv $GENERATED_HTML index.html
## commit and push repo
# before we commit let's stash changes and pull
# in case there's been some maintanance change made upstream
# while we were running:
git add .
git stash save
git pull
git stash pop
git add .
git commit -m 'Automated commit'
if [ $? -eq 0 ]; then
git push
fi
# finally, cleanup if we got this far
cleanup