Skip to content

Commit

Permalink
Allow GitHub Action to run on Windows (#456)
Browse files Browse the repository at this point in the history
  • Loading branch information
alcaeus authored Jul 23, 2024
1 parent 395efce commit 050ab31
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 62 deletions.
89 changes: 43 additions & 46 deletions .evergreen/download-mongodb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 ()
{
Expand Down
4 changes: 2 additions & 2 deletions .evergreen/run-orchestration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions .evergreen/start-orchestration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand All @@ -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

Expand Down
8 changes: 6 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -35,6 +38,7 @@ jobs:
fetch-depth: 2

- id: setup-mongodb
name: "Test GitHub Action"
uses: ./
with:
version: ${{ matrix.mongodb-version }}
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
17 changes: 10 additions & 7 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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

0 comments on commit 050ab31

Please sign in to comment.