Skip to content

Commit

Permalink
Use a lock file to prevent concurrent runs
Browse files Browse the repository at this point in the history
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
cmyr committed Sep 4, 2024
1 parent 158eb50 commit df9704f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ venv/
.DS_Store
fontc/
GITHUB_TOKEN
results/CRATER.lock

25 changes: 22 additions & 3 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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
Expand All @@ -76,3 +92,6 @@ git commit -m 'Automated commit'
if [ $? -eq 0 ]; then
git push
fi

# finally, cleanup if we got this far
cleanup

0 comments on commit df9704f

Please sign in to comment.