-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use a lock file to prevent concurrent runs
We want to make sure the same machine is only ever executing one run of the ci script at a time, so we will write a sentinal file when we start execution, and delete it when we're done.
- Loading branch information
Showing
2 changed files
with
23 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,5 @@ venv/ | |
.DS_Store | ||
fontc/ | ||
GITHUB_TOKEN | ||
results/CRATER.lock | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,25 +16,43 @@ export FONTC_CRATER_RESULTS=$(realpath ./results) | |
export FONTC_CRATER_INPUT=$(realpath "gf-repos-2024-08-12.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 | ||
} | ||
|
||
# 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 | ||
|
||
|
@@ -46,6 +64,7 @@ echo "setting up venv" | |
python -m venv venv | ||
if [ $? -ne 0 ]; then | ||
echo could not setup venv, exiting | ||
cleanup | ||
exit 1 | ||
fi | ||
|
||
|
@@ -63,9 +82,6 @@ if git clone $FONTC_REPO $FONTC_DIR ; then | |
( $SCRIPT_PATH ) | ||
cd .. | ||
fi | ||
echo "cleaning up" | ||
rm -rf $FONTC_DIR | ||
deactivate | ||
|
||
# move index.html from results/ to repo root | ||
mv $GENERATED_HTML index.html | ||
|
@@ -76,3 +92,6 @@ git commit -m 'Automated commit' | |
if [ $? -eq 0 ]; then | ||
git push | ||
fi | ||
|
||
# finally, cleanup if we got this far | ||
cleanup |