Skip to content
This repository has been archived by the owner on Mar 25, 2023. It is now read-only.

Commit

Permalink
Get act debugging working with quirks
Browse files Browse the repository at this point in the history
- `.ci/debug/run_act.sh` to run in act
- `.ci/debug/run_act_break_before_install.sh` to run in act
   and enter an infinite loop before install, so you can attach
   to the container (couldn't figure out how to force act
   to run container in interactive mode)
- Bump node to `15.x` (deprecated, but same as cloud for now)
- Run `setup_debugging.sh` in ACT runs to fix quirks of 500MB
   container (instead of 20GB full container), e.g. missing `yarn`
- Still some jankiness - e.g., if running as a submodule, action
   will think that repository doesn't exist (since `.git` is a pointer
   to a relative path in the parent, rather than itself)
  • Loading branch information
milesrichardson committed Jul 7, 2021
1 parent 211afff commit bbbe582
Show file tree
Hide file tree
Showing 9 changed files with 148 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .ci/debug/install_utils.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

exec curl https://raw.githubusercontent.com/nektos/act/master/install.sh | sudo bash
26 changes: 26 additions & 0 deletions .ci/debug/libdebug.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash

infinite_sleep() {
echo "Sleeping in foreground..."
echo "Attach to container with:"
echo
echo "-"
echo ' docker exec -it $(docker ps -q --filter name=act-*) /bin/bash'
echo
echo "-"
echo
echo "Or, to kill this container:"
echo "-"
echo ' docker kill $(docker ps -q --filter name=act-*)'
echo "-"

echo "(Sleeping now... ctrl+c might not be enough to kill me)"

while :
do
sleep 10 &
wait $!
done

exit 2
}
5 changes: 5 additions & 0 deletions .ci/debug/payloads/commit-event.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"head_commit": {
"message": "Blah blah blah"
}
}
39 changes: 39 additions & 0 deletions .ci/debug/run_act.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env bash

DEBUG_DIR="$(cd -P -- "$(dirname -- "$0")" && pwd -P)"
REPO_DIR="$DEBUG_DIR/../.."
DEBUG_REL_DIR=".ci/debug/"

ACT_TARGET_ACTION="${1-build_and_deploy_preview}"
if test -n "$ACT_TARGET_ACTION" ; then
shift
fi

ACT_EVENT_PAYLOAD="${1-"${DEBUG_REL_DIR}"payloads/commit-event.json}"
if test -n "$ACT_EVENT_PAYLOAD" ; then
shift
fi

# note: remaining arguments will be passed to `act` in final `exec`

# need to use "no" so that act doesn't ask the user to set it
# BREAK_INTERACTIVE_BEFORE_INSTALL=${"$BREAK_INTERACTIVE_BEFORE_INSTALL"-"no"}

pushd "$REPO_DIR"
trap "popd" exit

echo "All config variables are OPTIONAL. Simply press enter to skip one."
echo "Current variables set:"
echo
echo -n " BREAK_INTERACTIVE_BEFORE_INSTALL=\"${BREAK_INTERACTIVE_BEFORE_INSTALL}\""
echo " # If non-empty, infinite sleep before yarn install"
echo
echo "---"
echo

# act docs: https://github.com/nektos/act
exec act \
-j "${ACT_TARGET_ACTION}" \
-e "$ACT_EVENT_PAYLOAD" \
-s BREAK_INTERACTIVE_BEFORE_INSTALL="$BREAK_INTERACTIVE_BEFORE_INSTALL" \
"$@"
7 changes: 7 additions & 0 deletions .ci/debug/run_act_break_before_install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

DEBUG_DIR="$(cd -P -- "$(dirname -- "$0")" && pwd -P)"

# Set flag to be checked by install.sh when it sources debug_install.sh
export BREAK_INTERACTIVE_BEFORE_INSTALL=yes
exec "$DEBUG_DIR"/run_act.sh "$@"
30 changes: 30 additions & 0 deletions .ci/debug/setup_debugging.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env bash

# The GitHub workflow should conditionally call this script when running in ACT

if ! test -n "$ACT" ; then
echo "Fatal Error: Cannot call debug_preinstall.sh when not running inside ACT"
exit 1
fi

# `yarn` should be installed in GitHub actions, but when we're debugging
# with `act`, the 500MB container doesn't include `yarn`, so install it
if ! which yarn ; then
echo "------"
echo "Yarn not found (running in act?) - install it..."
echo "Node version: $(node --version)"
echo "------"

set -e
apt-get update -qq
apt-get install -yy curl gnupg2
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list

# Also, for some reason we nede to reinstall Node for this to work
curl -sL https://deb.nodesource.com/setup_15.x | bash -
apt-get install -yy nodejs
apt-get install --no-install-recommends yarn
set +e
fi

13 changes: 12 additions & 1 deletion .ci/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
CI_DIR="$(cd -P -- "$(dirname -- "$0")" && pwd -P)"
SPLITGRAPH_DIR="$CI_DIR/.."

if test ! -z "$YARN_CACHE_FOLDER" ; then
if test -n "$ACT" ; then
. "$CI_DIR"/debug/libdebug.sh
fi

# yarn cache is per branch by default. Clear it with commit pragma [clear cache]
if test ! -z "$YARN_CACHE_FOLDER" ; then
if git log --format=%B HEAD -n1 | grep -q '[clear cache]' ; then
>&2 echo "Clear cache ${YARN_CACHE_FOLDER}..."
test -d "$YARN_CACHE_FOLDER" && rm -r "$YARN_CACHE_FOLDER"
Expand All @@ -14,6 +18,13 @@ if test ! -z "$YARN_CACHE_FOLDER" ; then
echo "Yarn cache ($YARN_CACHE_FOLDER): $(ls -l "$YARN_CACHE_FOLDER" | wc -l)"
fi

# For debugging: Sleep in foreground so user can attach to container
# (I couldn't find how to force act to run the container in interactive mode)
if test -n "$BREAK_INTERACTIVE_BEFORE_INSTALL" ; then
echo "BREAK_INTERACTIVE_ON_INSTALL is set (not empty)"
infinite_sleep
fi

# We need to set the special lockfile name here, because if we use yarn.lock,
# then when running in the parent monorepo, yarn will think its in its own root
export WORKSPACE_LOCKFILE=yarn-public-workspace.lock
Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/build_and_deploy_preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ jobs:
- name: Use Node.js
uses: actions/setup-node@v1
with:
node-version: 13.x
node-version: 15.x
- name: Setup ACT debugging container
if: ${{ env.ACT }}
run: ./.ci/debug/setup_debugging.sh
- run: ./setup.sh
- uses: actions/cache@v1
with:
Expand All @@ -21,6 +24,9 @@ jobs:
- run: ./.ci/install.sh
env:
YARN_CACHE_FOLDER: /home/runner/yarn-cache

# For debugging only, but must be defined here or `act` ignores it
BREAK_INTERACTIVE_BEFORE_INSTALL: ${{ secrets.BREAK_INTERACTIVE_BEFORE_INSTALL }}
- run: ./.ci/build.sh
env:
DOCSEARCH_PUBLIC_CLIENT_API_KEY: ${{ secrets.DOCSEARCH_PUBLIC_CLIENT_API_KEY }}
Expand Down
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,22 @@

- `yarn dev`
- Run this script to start dev of the docs, after running `yarn install`

## debugging CI

```bash

# Start `act`
.ci/debug/run_act.sh

# "Break" before running bulk of install step (see `install.sh`)
.ci/debug/run_act_break_before_install.sh

# The "break" is just an infinite loop of `sleep 10`
# To get an interactive shell, need to `docker exec` into that container

docker exec -it $(docker ps -q --filter name=act-*) /bin/bash

# If you need to kill the container
docker kill $(docker ps -q --filter name=act-*)
```

0 comments on commit bbbe582

Please sign in to comment.