From 2442a2fa9cb67d29d1435ecb038f537c6e712888 Mon Sep 17 00:00:00 2001 From: Azriel Fasten Date: Sun, 12 May 2024 21:35:46 -0400 Subject: [PATCH] Fix the GH Action build-and-test workflow. --- .github/workflows/build-and-test.yml | 24 ++++++++++++++--- scripts/pre.sh | 17 +++++++++--- scripts/run-excalidraw.sh | 39 ++++++++++++++++++++-------- 3 files changed, 61 insertions(+), 19 deletions(-) diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index a6e8703..27c2188 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -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 @@ -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 diff --git a/scripts/pre.sh b/scripts/pre.sh index d6162e1..660c6af 100755 --- a/scripts/pre.sh +++ b/scripts/pre.sh @@ -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 @@ -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 diff --git a/scripts/run-excalidraw.sh b/scripts/run-excalidraw.sh index 0237aa4..595cae4 100755 --- a/scripts/run-excalidraw.sh +++ b/scripts/run-excalidraw.sh @@ -3,12 +3,29 @@ 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 { @@ -16,26 +33,26 @@ function cleanup { } 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}"