From 050ab310e1271542f115a8cb4330240b3c91e2d3 Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Tue, 23 Jul 2024 14:05:18 +0200 Subject: [PATCH] Allow GitHub Action to run on Windows (#456) --- .evergreen/download-mongodb.sh | 89 +++++++++++++++---------------- .evergreen/run-orchestration.sh | 4 +- .evergreen/start-orchestration.sh | 6 +-- .github/workflows/tests.yml | 8 ++- README.md | 6 ++- action.yml | 17 +++--- 6 files changed, 68 insertions(+), 62 deletions(-) diff --git a/.evergreen/download-mongodb.sh b/.evergreen/download-mongodb.sh index 982f2281..e4cd8094 100755 --- a/.evergreen/download-mongodb.sh +++ b/.evergreen/download-mongodb.sh @@ -541,61 +541,30 @@ get_mongodb_download_url_for () MONGODB_24="http://downloads.10gen.com/linux/mongodb-linux-x86_64-subscription-ubuntu1204${DEBUG}-${VERSION_24}.tgz" ;; windows32*) - EXTRACT="/cygdrive/c/Progra~2/7-Zip/7z.exe x" - EXTRACT_MONGOSH="/cygdrive/c/Progra~2/7-Zip/7z.exe x" - MONGODB_32="https://fastdl.mongodb.org/win32/mongodb-win32-i386${DEBUG}-${VERSION_32}.zip" - MONGODB_30="https://fastdl.mongodb.org/win32/mongodb-win32-i386${DEBUG}-${VERSION_30}.zip" - MONGODB_26="https://fastdl.mongodb.org/win32/mongodb-win32-i386${DEBUG}-${VERSION_26}.zip" - MONGODB_24="https://fastdl.mongodb.org/win32/mongodb-win32-i386${DEBUG}-${VERSION_24}.zip" + EXTRACT="/cygdrive/c/Progra~1/7-Zip/7z.exe x" + EXTRACT_MONGOSH="/cygdrive/c/Progra~1/7-Zip/7z.exe x" + set_url_win32 + ;; + cygwin*-i686) + EXTRACT="/cygdrive/c/Progra~1/7-Zip/7z.exe x" + EXTRACT_MONGOSH="/cygdrive/c/Progra~1/7-Zip/7z.exe x" + set_url_win32 ;; windows64*) - # same as cygwin*-86-64 EXTRACT="/cygdrive/c/Progra~2/7-Zip/7z.exe x" EXTRACT_MONGOSH="/cygdrive/c/Progra~2/7-Zip/7z.exe x" - MONGODB_LATEST="http://downloads.10gen.com/windows/mongodb-windows-x86_64-enterprise${DEBUG}-latest.zip" - MONGOSH="https://downloads.mongodb.com/compass/mongosh-${VERSION_MONGOSH}-win32-x64.zip" - MONGODB_RAPID="http://downloads.10gen.com/windows/mongodb-windows-x86_64-enterprise${DEBUG}-${VERSION_RAPID}.zip" - MONGODB_80="http://downloads.10gen.com/windows/mongodb-windows-x86_64-enterprise${DEBUG}-${VERSION_80}.zip" - MONGODB_70="http://downloads.10gen.com/windows/mongodb-windows-x86_64-enterprise${DEBUG}-${VERSION_70}.zip" - MONGODB_60="http://downloads.10gen.com/windows/mongodb-windows-x86_64-enterprise${DEBUG}-${VERSION_60}.zip" - MONGODB_50="http://downloads.10gen.com/windows/mongodb-windows-x86_64-enterprise${DEBUG}-${VERSION_50}.zip" - MONGODB_44="http://downloads.10gen.com/windows/mongodb-windows-x86_64-enterprise${DEBUG}-${VERSION_44}.zip" - MONGODB_42="http://downloads.10gen.com/win32/mongodb-win32-x86_64-enterprise-windows-64${DEBUG}-${VERSION_42}.zip" - MONGODB_40="http://downloads.10gen.com/win32/mongodb-win32-x86_64-enterprise-windows-64${DEBUG}-${VERSION_40}.zip" - MONGODB_36="http://downloads.10gen.com/win32/mongodb-win32-x86_64-enterprise-windows-64${DEBUG}-${VERSION_36}.zip" - MONGODB_34="http://downloads.10gen.com/win32/mongodb-win32-x86_64-enterprise-windows-64${DEBUG}-${VERSION_34}.zip" - MONGODB_32="http://downloads.10gen.com/win32/mongodb-win32-x86_64-enterprise-windows-64${DEBUG}-${VERSION_32}.zip" - MONGODB_30="http://downloads.10gen.com/win32/mongodb-win32-x86_64-enterprise-windows-64${DEBUG}-${VERSION_30}.zip" - MONGODB_26="http://downloads.10gen.com/win32/mongodb-win32-x86_64-enterprise-windows-64${DEBUG}-${VERSION_26}.zip" - MONGODB_24="https://fastdl.mongodb.org/win32/mongodb-win32-x86_64-2008plus${DEBUG}-${VERSION_24}.zip" + set_url_win64 ;; cygwin*-x86_64) EXTRACT="/cygdrive/c/Progra~2/7-Zip/7z.exe x" EXTRACT_MONGOSH="/cygdrive/c/Progra~2/7-Zip/7z.exe x" - MONGODB_LATEST="http://downloads.10gen.com/windows/mongodb-windows-x86_64-enterprise-latest.zip" - MONGOSH="https://downloads.mongodb.com/compass/mongosh-${VERSION_MONGOSH}-win32-x64.zip" - MONGODB_RAPID="http://downloads.10gen.com/windows/mongodb-windows-x86_64-enterprise${DEBUG}-${VERSION_RAPID}.zip" - MONGODB_80="http://downloads.10gen.com/windows/mongodb-windows-x86_64-enterprise${DEBUG}-${VERSION_80}.zip" - MONGODB_70="http://downloads.10gen.com/windows/mongodb-windows-x86_64-enterprise${DEBUG}-${VERSION_70}.zip" - MONGODB_60="http://downloads.10gen.com/windows/mongodb-windows-x86_64-enterprise${DEBUG}-${VERSION_60}.zip" - MONGODB_50="http://downloads.10gen.com/windows/mongodb-windows-x86_64-enterprise${DEBUG}-${VERSION_50}.zip" - MONGODB_44="http://downloads.10gen.com/windows/mongodb-windows-x86_64-enterprise${DEBUG}-${VERSION_44}.zip" - MONGODB_42="http://downloads.10gen.com/win32/mongodb-win32-x86_64-enterprise-windows-64${DEBUG}-${VERSION_42}.zip" - MONGODB_40="http://downloads.10gen.com/win32/mongodb-win32-x86_64-enterprise-windows-64${DEBUG}-${VERSION_40}.zip" - MONGODB_36="http://downloads.10gen.com/win32/mongodb-win32-x86_64-enterprise-windows-64${DEBUG}-${VERSION_36}.zip" - MONGODB_34="http://downloads.10gen.com/win32/mongodb-win32-x86_64-enterprise-windows-64${DEBUG}-${VERSION_34}.zip" - MONGODB_32="http://downloads.10gen.com/win32/mongodb-win32-x86_64-enterprise-windows-64${DEBUG}-${VERSION_32}.zip" - MONGODB_30="http://downloads.10gen.com/win32/mongodb-win32-x86_64-enterprise-windows-64${DEBUG}-${VERSION_30}.zip" - MONGODB_26="http://downloads.10gen.com/win32/mongodb-win32-x86_64-enterprise-windows-64${DEBUG}-${VERSION_26}.zip" - MONGODB_24="https://fastdl.mongodb.org/win32/mongodb-win32-x86_64-2008plus${DEBUG}-${VERSION_24}.zip" + set_url_win64 ;; - cygwin*-i686) - EXTRACT="/cygdrive/c/Progra~1/7-Zip/7z.exe x" - EXTRACT_MONGOSH="/cygdrive/c/Progra~1/7-Zip/7z.exe x" - MONGODB_32="https://fastdl.mongodb.org/win32/mongodb-win32-i386${DEBUG}-${VERSION_32}.zip" - MONGODB_30="https://fastdl.mongodb.org/win32/mongodb-win32-i386${DEBUG}-${VERSION_30}.zip" - MONGODB_26="https://fastdl.mongodb.org/win32/mongodb-win32-i386${DEBUG}-${VERSION_26}.zip" - MONGODB_24="https://fastdl.mongodb.org/win32/mongodb-win32-i386${DEBUG}-${VERSION_24}.zip" + # Windows on GitHub Actions + mingw64_nt-*-x86_64) + EXTRACT="7z.exe x" + EXTRACT_MONGOSH="7z.exe x" + set_url_win64 ;; esac @@ -689,6 +658,34 @@ get_mongodb_download_url_for () echo $MONGODB_DOWNLOAD_URL } +set_url_win64 () +{ + MONGOSH="https://downloads.mongodb.com/compass/mongosh-${VERSION_MONGOSH}-win32-x64.zip" + MONGODB_LATEST="http://downloads.10gen.com/windows/mongodb-windows-x86_64-enterprise${DEBUG}-latest.zip" + MONGODB_RAPID="http://downloads.10gen.com/windows/mongodb-windows-x86_64-enterprise${DEBUG}-${VERSION_RAPID}.zip" + MONGODB_80="http://downloads.10gen.com/windows/mongodb-windows-x86_64-enterprise${DEBUG}-${VERSION_80}.zip" + MONGODB_70="http://downloads.10gen.com/windows/mongodb-windows-x86_64-enterprise${DEBUG}-${VERSION_70}.zip" + MONGODB_60="http://downloads.10gen.com/windows/mongodb-windows-x86_64-enterprise${DEBUG}-${VERSION_60}.zip" + MONGODB_50="http://downloads.10gen.com/windows/mongodb-windows-x86_64-enterprise${DEBUG}-${VERSION_50}.zip" + MONGODB_44="http://downloads.10gen.com/windows/mongodb-windows-x86_64-enterprise${DEBUG}-${VERSION_44}.zip" + MONGODB_42="http://downloads.10gen.com/win32/mongodb-win32-x86_64-enterprise-windows-64${DEBUG}-${VERSION_42}.zip" + MONGODB_40="http://downloads.10gen.com/win32/mongodb-win32-x86_64-enterprise-windows-64${DEBUG}-${VERSION_40}.zip" + MONGODB_36="http://downloads.10gen.com/win32/mongodb-win32-x86_64-enterprise-windows-64${DEBUG}-${VERSION_36}.zip" + MONGODB_34="http://downloads.10gen.com/win32/mongodb-win32-x86_64-enterprise-windows-64${DEBUG}-${VERSION_34}.zip" + MONGODB_32="http://downloads.10gen.com/win32/mongodb-win32-x86_64-enterprise-windows-64${DEBUG}-${VERSION_32}.zip" + MONGODB_30="http://downloads.10gen.com/win32/mongodb-win32-x86_64-enterprise-windows-64${DEBUG}-${VERSION_30}.zip" + MONGODB_26="http://downloads.10gen.com/win32/mongodb-win32-x86_64-enterprise-windows-64${DEBUG}-${VERSION_26}.zip" + MONGODB_24="https://fastdl.mongodb.org/win32/mongodb-win32-x86_64-2008plus${DEBUG}-${VERSION_24}.zip" +} + +set_url_win32 () +{ + MONGODB_32="https://fastdl.mongodb.org/win32/mongodb-win32-i386${DEBUG}-${VERSION_32}.zip" + MONGODB_30="https://fastdl.mongodb.org/win32/mongodb-win32-i386${DEBUG}-${VERSION_30}.zip" + MONGODB_26="https://fastdl.mongodb.org/win32/mongodb-win32-i386${DEBUG}-${VERSION_26}.zip" + MONGODB_24="https://fastdl.mongodb.org/win32/mongodb-win32-i386${DEBUG}-${VERSION_24}.zip" +} + # curl_retry runs curl with up to three retries, retrying any error. curl_retry () { diff --git a/.evergreen/run-orchestration.sh b/.evergreen/run-orchestration.sh index 970f4a67..c6f25b0c 100755 --- a/.evergreen/run-orchestration.sh +++ b/.evergreen/run-orchestration.sh @@ -47,7 +47,7 @@ echo "Finding Python3 binary... done." # Set up the mongo orchestration config. mkdir -p $MONGO_ORCHESTRATION_HOME -echo "{ \"releases\": { \"default\": \"$MONGODB_BINARIES\" }}" > $MONGO_ORCHESTRATION_HOME/orchestration.config +printf '%s' $MONGODB_BINARIES | python -c 'import json,sys; print(json.dumps({"releases": {"default": sys.stdin.read() }}))' > $MONGO_ORCHESTRATION_HOME/orchestration.config # Copy client certificate because symlinks do not work on Windows. mkdir -p ${MONGO_ORCHESTRATION_HOME}/lib @@ -118,7 +118,7 @@ fi echo "ORCHESTRATION_FILE=$ORCHESTRATION_FILE" # Handle absolute path. -perl -p -i -e "s|ABSOLUTE_PATH_REPLACEMENT_TOKEN|${DRIVERS_TOOLS}|g" $ORCHESTRATION_FILE +perl -p -i -e "s|ABSOLUTE_PATH_REPLACEMENT_TOKEN|$(echo $DRIVERS_TOOLS | sed 's/\\/\\\\\\\\/g')|g" $ORCHESTRATION_FILE # If running on Docker, update the orchestration file to be docker-friendly. if [ -n "$DOCKER_RUNNING" ]; then diff --git a/.evergreen/start-orchestration.sh b/.evergreen/start-orchestration.sh index 3cdf5925..ff1809b2 100755 --- a/.evergreen/start-orchestration.sh +++ b/.evergreen/start-orchestration.sh @@ -48,7 +48,7 @@ cd - # Create default config file if it doesn't exist if [ ! -f $MONGO_ORCHESTRATION_HOME/orchestration.config ]; then - echo "{ \"releases\": { \"default\": \"$MONGODB_BINARIES\" }}" > $MONGO_ORCHESTRATION_HOME/orchestration.config + printf '%s' $MONGODB_BINARIES | python -c 'import json,sys; print(json.dumps({"releases": {"default": sys.stdin.read() }}))' > $MONGO_ORCHESTRATION_HOME/orchestration.config fi ORCHESTRATION_ARGUMENTS="-e default -f $MONGO_ORCHESTRATION_HOME/orchestration.config --socket-timeout-ms=60000 --bind=127.0.0.1 --enable-majority-read-concern" @@ -58,7 +58,7 @@ fi # Forcibly kill the process listening on port 8889, most likely a wild # mongo-orchestration left running from a previous task. -if [[ "${OSTYPE:?}" == cygwin ]]; then +if [[ "${OSTYPE:?}" == cygwin || "${OSTYPE:?}" == msys ]]; then OLD_MO_PID=$(netstat -ano | grep ':8889 .* LISTENING' | awk '{print $5}' | tr -d '[:space:]') if [ ! -z "$OLD_MO_PID" ]; then taskkill /F /T /PID "$OLD_MO_PID" || true @@ -74,7 +74,7 @@ elif [ -x "$(command -v ss)" ]; then kill -9 "$OLD_MO_PID" || true fi else - echo "Unable to identify the OS or find necessary utilities (lsof/ss) to kill the process." + echo "Unable to identify the OS (${OSTYPE:?}) or find necessary utilities (lsof/ss) to kill the process." exit 1 fi diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 98b6992b..e46e6c90 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -11,12 +11,15 @@ on: jobs: tests: name: "Tests" - runs-on: "ubuntu-20.04" + runs-on: ${{ matrix.os }} strategy: matrix: + os: + - "ubuntu-latest" + - "windows-latest" mongodb-version: - - "4.4" + - "7.0" topology: - "server" - "replica_set" @@ -35,6 +38,7 @@ jobs: fetch-depth: 2 - id: setup-mongodb + name: "Test GitHub Action" uses: ./ with: version: ${{ matrix.mongodb-version }} diff --git a/README.md b/README.md index 784d3856..30432141 100644 --- a/README.md +++ b/README.md @@ -66,8 +66,9 @@ The following inputs exist: These correspond to the respective environment variables that are passed to `run-orchestration.sh`. -After the cluster is started, its URI is exposed via the `cluster-uri` output. -This configuration snippet sets an environment variable with the cluster URI +After the cluster is started, its URI is exposed via the `cluster-uri` output. In addition, the action also exposes the +path to `crypt_shared` via the `crypt-shared-lib-path` output, unless the installation was not requested or failed. +This configuration snippet environment variables with the cluster URI and `crypt_shared` lib path returned from the `setup-mongodb` workflow step when running tests: ```yaml steps: @@ -76,6 +77,7 @@ returned from the `setup-mongodb` workflow step when running tests: run: "run-tests.sh" env: MONGODB_URI: ${{ steps.setup-mongodb.outputs.cluster-uri }} + CRYPT_SHARED_LIB_PATH: ${{ steps.setup-mongodb.outputs.crypt-shared-lib-path }} ``` ## Linters and Formatters diff --git a/action.yml b/action.yml index 280f3af8..40f284d2 100644 --- a/action.yml +++ b/action.yml @@ -28,7 +28,10 @@ inputs: outputs: cluster-uri: description: "URI of the cluster" - value: ${{ steps.get-cluster-uri.outputs.cluster-uri }} + value: ${{ steps.run-orchestration.outputs.cluster-uri }} + crypt-shared-lib-path: + description: "Path of the crypt_shared library" + value: ${{ steps.run-orchestration.outputs.crypt-shared-lib-path }} runs: using: "composite" steps: @@ -38,11 +41,15 @@ runs: shell: bash - id: "add-mongodb-binary-path" name: "Add PIP install folder to path" - run: echo "${{ github.action_path }}/mongodb/bin" >> $GITHUB_PATH + run: echo ${GITHUB_ACTION_PATH}/mongodb/bin >> $GITHUB_PATH shell: bash - id: "run-orchestration" name: "Download MongoDB" - run: ${{ github.action_path }}/.evergreen/run-orchestration.sh + run: | + ${GITHUB_ACTION_PATH}/.evergreen/run-orchestration.sh + [[ -f mo-expansion.sh ]] && source mo-expansion.sh + echo "cluster-uri=$(cat ${GITHUB_ACTION_PATH}/uri.txt)" >> $GITHUB_OUTPUT + echo "crypt-shared-lib-path=${CRYPT_SHARED_LIB_PATH}" >> $GITHUB_OUTPUT env: DRIVERS_TOOLS: ${{ github.action_path }} MONGODB_BINARIES: ${{ github.action_path }}/mongodb/bin @@ -57,7 +64,3 @@ runs: SKIP_LEGACY_SHELL: ${{ inputs.skip-legacy-shell }} INSTALL_LEGACY_SHELL: ${{ inputs.install-legacy-shell }} shell: bash - - id: "get-cluster-uri" - name: "Expose Cluster URI" - run: echo "cluster-uri=$(cat ${{ github.action_path }}/uri.txt)" >> $GITHUB_OUTPUT - shell: bash