Skip to content

Commit

Permalink
Update build-pages.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
codefrau committed Mar 26, 2024
1 parent 19f8437 commit 953f58b
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions scripts/build-pages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ LINKS=()
FAILED=()
SUCCESS=()
TOP=$(git rev-parse --show-toplevel)
COMMIT=$(git log -1 --format='%H')
COMMIT_DATE=$(git log -1 --format='%cd' --date=format:'%Y-%m-%d %H:%M:%S')
for DIR in tutorials examples ; do
cd $TOP
mkdir _site/$DIR
Expand All @@ -23,22 +25,21 @@ for DIR in tutorials examples ; do
echo
echo "=== Building $APP ==="
cd $TOP/$APP
COMMIT=$(git log -1 --format='%ad %H' --date=format:'%Y-%m-%d %H:%M:%S')
echo "Commit: $COMMIT" > build.log
npm run build >> build.log 2>&1
BUILD_ERROR=$?
cat build.log
DATE=$(git ls-tree -r --name-only HEAD -- . | grep -v 'package.*json' | xargs -n 1 git log -1 --format='%ad' --date=format:'%Y-%m-%d' | sort | tail -1)
APP_DATE=$(git ls-tree -r --name-only HEAD -- . | grep -v 'package.*json' | xargs -n 1 git log -1 --format='%cd' --date=format:'%Y-%m-%d' | sort | tail -1)
if [ $BUILD_ERROR -eq 0 ] ; then
mv -v dist ../../_site/$APP
LINKS+=("<p>${DATE} <a href=\"${APP}/\"><b>${APP}</b></a> (<a href=\"${APP}/build.log\">log</a>)</p>")
LINKS+=("<p>${APP_DATE} <a href=\"${APP}/\"><b>${APP}</b></a> (<a href=\"${APP}/build.log\">log</a>)</p>")
SUCCESS+=($APP)
else
mkdir ../../_site/$APP
echo "<H1>Build failed</h1><pre>" > ../../_site/$APP/index.html
cat build.log >> ../../_site/$APP/index.html
echo "</pre>" >> ../../_site/$APP/index.html
LINKS+=("<p>${DATE} <b>${APP} BUILD FAILED</b> (<a href=\"${APP}/build.log\">log</a>)</p>")
LINKS+=("<p>${APP_DATE} <b>${APP} BUILD FAILED</b> (<a href=\"${APP}/build.log\">log</a>)</p>")
FAILED+=($APP)
fi
mv -v build.log ../../_site/$APP/
Expand All @@ -47,21 +48,28 @@ done

cd $TOP

LATEST_TAG=$(git describe --tags --abbrev=0)
COMMITS_SINCE=$(git rev-list --count ${LATEST_TAG}..HEAD)
VERSION="${LATEST_TAG}"
if [ $COMMITS_SINCE -gt 0 ] ; then
VERSION="${VERSION}+${COMMITS_SINCE}"
fi

echo
echo "=== Building index page ==="
cat > _site/index.html <<EOF
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Worldcore Builds</title>
<title>Worldcore Build ${VERSION}</title>
<style>
body { font-family: monospace; }
</style>
</head>
<body>
<h1>Worldcore Builds</h1>
<h2>${COMMIT}
<h1>Worldcore Build ${VERSION}</h1>
<h2>${COMMIT_DATE} <a href="https://github.com/croquet/worldcore/commits/${COMMIT}/">${COMMIT}</a>
(<a href="${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}">full log</a>,
<a href="$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/workflows/deploy-to-pages.yml">previous</a>)</h2>
${LINKS[@]}
Expand All @@ -87,14 +95,18 @@ if [ -n "$SLACK_HOOK_URL" ] ; then
NUM_FAILED=${#FAILED[@]}
NUM_TOTAL=$((${#SUCCESS[@]} + ${#FAILED[@]}))
if [ $NUM_FAILED -eq 0 ] ; then
JSON="{\"text\": \"😍 *Worldcore build succeeded for all apps* 😍\n${URL}\"}"
JSON="{\"text\": \"😍 *Worldcore build ${VERSION} succeeded for all apps* 😍\n${URL}\"}"
else
APPS=""
for APP in ${FAILED[@]} ; do
LOG="https://croquet.github.io/worldcore/${APP}/build.log"
APPS="${APPS}\nβ€’ <${LOG}|${APP}>"
APPS="${APPS}\n❌ <${LOG}|${APP}>"
done
for APP in ${SUCCESS[@]} ; do
RUN="https://croquet.github.io/worldcore/${APP}/"
APPS="${APPS}\nβœ… <${RUN}|${APP}>"
done
JSON="{\"text\": \"πŸ’© *Worldcore builds failed for ${NUM_FAILED}/${NUM_TOTAL} apps* πŸ’©\n${URL}\n${APPS}\"}"
JSON="{\"text\": \"πŸ‘·β€β™€οΈ *Worldcore app build ${VERSION} failed for ${NUM_FAILED}/${NUM_TOTAL} apps* πŸ‘·β€β™€οΈ\n${URL}\n${APPS}\"}"
fi
curl -sSX POST -H 'Content-type: application/json' --data "${JSON}" $SLACK_HOOK_URL
else
Expand Down

0 comments on commit 953f58b

Please sign in to comment.