Skip to content

Commit

Permalink
Notify slack about build failures
Browse files Browse the repository at this point in the history
  • Loading branch information
codefrau committed Mar 6, 2024
1 parent 0374474 commit d4be89c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
11 changes: 6 additions & 5 deletions .github/workflows/deploy-to-pages.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Workflow to build a GitHub Pages site for multiple branches simultaneously
# Workflow to build a GitHub Pages site for all examples and tutorials
# and deploy it to https://croquet.github.io/worldcore/

# NOTE: to make this work, in GitHub Settings under Pages – Build and Deployment
# change Source from "Deploy from a branch" to "GitHub Actions"!
# The actual work is done in scripts/build-pages.sh

# NOTE: to make this work, in GitHub Settings under Pages – Build and Deployment
# change Source from "Deploy from a branch" to "GitHub Actions"!
Expand All @@ -27,7 +27,8 @@ concurrency:

jobs:
deploy:
# only run on main repo
# only run on main repo and not forks
# (change this in your fork if you want it there)
if: github.repository == 'croquet/worldcore'
environment:
name: github-pages
Expand All @@ -39,7 +40,7 @@ jobs:
with:
fetch-depth: 0 # fetch full history

- name: Setup Pages
- name: Configure pages
uses: actions/configure-pages@v4

- name: Use Node.js 18
Expand Down
17 changes: 17 additions & 0 deletions scripts/build-pages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ npx lerna bootstrap || exit 1
rm -rf _site
mkdir _site
LINKS=()
FAILED=()
TOP=$(git rev-parse --show-toplevel)
for DIR in tutorials examples ; do
cd $TOP
Expand All @@ -36,6 +37,7 @@ for DIR in tutorials examples ; do
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>")
FAILED+=($APP)
fi
mv -v build.log ../../_site/$APP/
done
Expand Down Expand Up @@ -75,3 +77,18 @@ cat > _site/index.html <<EOF
</body>
</html>
EOF

NUM_FAILED=${#FAILED[@]}
if [ $NUM_FAILED -gt 0 ] ; then
if [ -n "$SLACK_HOOK_URL" ] ; then
echo
echo "=== Sending slack message ==="
URL="https://croquet.github.io/worldcore/"
APPS=$(printf -- "- %s\\\\n" "${FAILED[@]}")
JSON="{\"text\": \"🤖 *Worldcore build failed for ${NUM_FAILED} apps* 🤖\n${URL}\n${APPS}\""
echo curl -X POST -H 'Content-type: application/json' --data "${JSON}\"}" $SLACK_HOOK_URL
else
echo
echo "=== No SLACK_HOOK_URL set, not sending slack message ==="
fi
fi

0 comments on commit d4be89c

Please sign in to comment.