Skip to content

Commit

Permalink
Fix the GH Action build-and-test workflow.
Browse files Browse the repository at this point in the history
  • Loading branch information
realazthat committed May 13, 2024
1 parent 184a6e8 commit 2442a2f
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 19 deletions.
24 changes: 20 additions & 4 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,25 @@ jobs:
runs-on: ubuntu-20.04
strategy:
matrix:
node-version: [18.20.2, 20.12.1, 21.7.3, 22.0.0]
EXCALIDRAW_BRUTE_EXPORT_CLI_URL:
- http://localhost:59876,
- https://excalidraw.com,
node-version:
- 18.20.2
- 20.12.1
- 21.7.3
- 22.0.0
EXCALIDRAW_TAG:
- 0.15.0
- https://excalidraw.com
steps:
- name: Generate dynamic matrix hash
id: generate_hash
run: |
MATRIX_VARS=$(echo '${{ toJSON(matrix) }}')
MATRIX_HASH=$(echo -n "$MATRIX_VARS" | md5sum | awk '{print $1}')
echo "MATRIX_HASH=$MATRIX_HASH" >> $GITHUB_ENV
- name: Unique Matrix ID
run: |
GH_ACTION_UNIQUE_ID="${{ github.run_id }}-$MATRIX_HASH"
echo "GH_ACTION_UNIQUE_ID=$GH_ACTION_UNIQUE_ID" >> $GITHUB_ENV
- uses: actions/checkout@v4
- name: Set up Node
uses: actions/setup-node@v4
Expand All @@ -49,7 +63,9 @@ jobs:
# curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
- name: Run everything
run: |
npm install -g npm@latest
npm install
npx playwright install-deps
npx playwright install firefox
export EXCALIDRAW_INSTANCE_NAME=test-excalidraw-$GH_ACTION_UNIQUE_ID
bash scripts/pre.sh
17 changes: 13 additions & 4 deletions scripts/pre.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,21 @@ set -e -x -v -u -o pipefail
SCRIPT_DIR=$(realpath "$(dirname "${BASH_SOURCE[0]}")")
source "${SCRIPT_DIR}/utilities/common.sh"

IDEAL_EXCALIDRAW_TAG=$(cat .github/.excalidraw-tag)
IDEAL_NODE_VERSION="v20.12.1"
WANTED_NODE_VERSION=$(cat .nvmrc)

export PYTHON_VERSION_PATH="${PWD}/scripts/.python-version"
export TOML="${PWD}/scripts/pyproject.toml"
export EXCALIDRAW_BRUTE_EXPORT_CLI_URL=${EXCALIDRAW_BRUTE_EXPORT_CLI_URL-"http://localhost:59876"}
export EXCALIDRAW_TAG=${EXCALIDRAW_TAG-"${IDEAL_EXCALIDRAW_TAG}"}

# This variable will be 1 when we are the ideal version in the GH action matrix.
IDEAL="0"
WANTED_NODE_VERSION=$(cat .nvmrc)

if [[ "${WANTED_NODE_VERSION}" == "v20.12.1" && "${EXCALIDRAW_BRUTE_EXPORT_CLI_URL}" == "http://localhost:59876" ]]; then
if [[ "${WANTED_NODE_VERSION}" == "${IDEAL_NODE_VERSION}" && "${EXCALIDRAW_TAG}" == "${IDEAL_EXCALIDRAW_TAG}" ]]; then
IDEAL="1"
export EXCALIDRAW_PORT=59876
export EXCALIDRAW_INSTANCE_NAME="test-excalidraw"
fi

if [[ -z "${GITHUB_ACTIONS:-}" ]]; then
Expand All @@ -40,7 +45,11 @@ npm install

EXTRA=dev bash scripts/utilities/pin-extra-reqs.sh
npm run genversion
bash scripts/run-excalidraw.sh
source scripts/run-excalidraw.sh
if [[ -z "${EXCALIDRAW_BRUTE_EXPORT_CLI_URL}" ]]; then
echo -e "${RED}EXCALIDRAW_BRUTE_EXPORT_CLI_URL is not set${NC}"
exit 1
fi
bash scripts/run-all-examples.sh
bash scripts/format.sh
bash scripts/run-ood-smoke-test.sh
Expand Down
39 changes: 28 additions & 11 deletions scripts/run-excalidraw.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,56 @@
set -e -x -v -u -o pipefail

GREEN='\033[0;32m'
BLUE='\033[0;34m'
RED='\033[0;31m'
NC='\033[0m'

COMMIT=$(cat .github/.excalidraw-tag)
EXCALIDRAW_TAG=${EXCALIDRAW_TAG:-}
EXCALIDRAW_INSTANCE_NAME=${EXCALIDRAW_INSTANCE_NAME:-"test-excalidraw"}
EXCALIDRAW_PORT=${EXCALIDRAW_PORT:-}
IMAGE_NAME="test-excalidraw"
INSTANCE_NAME="test-excalidraw"
PORT=59876

if [[ -z "${EXCALIDRAW_TAG}" ]]; then
echo -e "${RED}EXCALIDRAW_TAG is not set, set it to an excalidraw github tag, or the string 'https://excalidraw.com'.${NC}"
exit 1
fi

if [[ "${EXCALIDRAW_TAG}" = "https://excalidraw.com" ]]; then
echo -e "${BLUE}No specified EXCALIDRAW_TAG, not starting excalidraw docker container${NC}"
export EXCALIDRAW_BRUTE_EXPORT_CLI_URL="https://excalidraw.com"
exit 0
fi

if [[ -z "${EXCALIDRAW_PORT}" ]]; then
EXCALIDRAW_PORT=$(python3 -c 'import socket; s=socket.socket(); s.bind(("",0)); print(s.getsockname()[1]); s.close()')
fi

TMP_DIR=$(mktemp -d)
function cleanup {
rm -rf "${TMP_DIR}" || true
}
trap cleanup EXIT

DOCKER_IMAGE_EXISTS=$(docker images -q "${IMAGE_NAME}:${COMMIT}" | wc -l)
DOCKER_IMAGE_EXISTS=$(docker images -q "${IMAGE_NAME}:${EXCALIDRAW_TAG}" | wc -l)
if [[ "${DOCKER_IMAGE_EXISTS}" -eq 0 ]]; then
cd "${TMP_DIR}"
git clone https://github.com/excalidraw/excalidraw.git
cd excalidraw
git checkout "${COMMIT}"
docker build -t "${IMAGE_NAME}:${COMMIT}" .
git checkout "${EXCALIDRAW_TAG}"
docker build -t "${IMAGE_NAME}:${EXCALIDRAW_TAG}" .
fi
docker rm -f "${INSTANCE_NAME}" || true
docker run -dit --name "${INSTANCE_NAME}" -p "${PORT}:80" "${IMAGE_NAME}:${COMMIT}"
docker rm -f "${EXCALIDRAW_INSTANCE_NAME}" || true
docker run -dit --name "${EXCALIDRAW_INSTANCE_NAME}" -p "${EXCALIDRAW_PORT}:80" "${IMAGE_NAME}:${EXCALIDRAW_TAG}"

EXCALIDRAW_URL="http://localhost:${PORT}"
export EXCALIDRAW_BRUTE_EXPORT_CLI_URL="http://localhost:${EXCALIDRAW_PORT}"

# Wait for the server to start
while true; do
if curl -s "${EXCALIDRAW_URL}" | grep -q "Excalidraw"; then
if curl -s "${EXCALIDRAW_BRUTE_EXPORT_CLI_URL}" | grep -q "Excalidraw"; then
break
fi
sleep 1
done


echo -e "${GREEN}Visit http://localhost:${PORT} to see Excalidraw${NC}"
echo -e "${GREEN}Visit ${EXCALIDRAW_BRUTE_EXPORT_CLI_URL} to see Excalidraw${NC}"

0 comments on commit 2442a2f

Please sign in to comment.