-
Notifications
You must be signed in to change notification settings - Fork 84
feat: add a download script to facilitate easy use in CI MONGOSH-2687 #2532
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
4df5b98
c1ec95a
588c5e2
50bddd8
e8d4af8
8a9f8cc
9fad15d
73fe093
3e1404b
ff93c05
c47eb09
5dcb55e
8f1242a
9290f20
170aea3
c7ed465
52c0d62
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| name: "Test download_latest script" | ||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
| pull_request: | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| smoke-tests: | ||
| name: "OS: ${{ matrix.runner }}, node@${{ matrix.node }}" | ||
| strategy: | ||
| matrix: | ||
| runner: [ubuntu, macos] | ||
| node: [24.x] | ||
| fail-fast: false | ||
| runs-on: ${{ matrix.runner }}-latest | ||
| timeout-minutes: 30 # Installing dependencies on windows can take a while | ||
| env: | ||
| npm_config_loglevel: verbose | ||
| npm_config_foreground_scripts: "true" | ||
| PUPPETEER_SKIP_DOWNLOAD: "true" | ||
| steps: | ||
| - uses: actions/checkout@v5 | ||
| - uses: actions/setup-node@v6 | ||
| with: | ||
| check-latest: true | ||
| node-version: ${{ matrix.node }} | ||
|
|
||
| - name: Install mongosh through download_latest.sh | ||
| run: ./download_latest.sh | ||
|
|
||
| - name: Run smoke tests | ||
| run: npx -y mongodb-runner -- exec -- sh -c 'env MONGOSH_SMOKE_TEST_SERVER=$MONGODB_URI ./mongosh --smokeTests' |
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
| @@ -0,0 +1,121 @@ | ||||
| #!/bin/sh | ||||
|
|
||||
| set -o errexit | ||||
|
|
||||
| MONGOSH_RELEASES_URL=https://downloads.mongodb.com/compass/mongosh.json | ||||
|
|
||||
| say() { | ||||
| echo >&2 "$@" | ||||
| } | ||||
|
|
||||
| sayf() { | ||||
| # shellcheck disable=SC2059 | ||||
| printf >&2 "$@" | ||||
| } | ||||
|
|
||||
| show_download_link() { | ||||
| say "Download mongosh manually from:" | ||||
| say | ||||
| sayf "\t%s\n" 'https://www.mongodb.com/try/download/shell' | ||||
| } | ||||
|
|
||||
| for tool in jq curl; do | ||||
| which "$tool" >/dev/null || { | ||||
| say "This script requires '$tool'." | ||||
| exit 1 | ||||
| } | ||||
| done | ||||
|
|
||||
| os=$(uname -o | tr '[:upper:]' '[:lower:]') | ||||
| arch=$(uname -m) | ||||
|
|
||||
| case "$os" in | ||||
| *linux) | ||||
| ext=tgz | ||||
| os=linux | ||||
| ;; | ||||
| darwin) | ||||
| ext=zip | ||||
| ;; | ||||
| *) | ||||
| say "❌ This script does not support this OS ($os)." | ||||
| show_download_link | ||||
|
|
||||
| exit 1 | ||||
| esac | ||||
|
|
||||
| # normalize $arch: | ||||
| case "$arch" in | ||||
| amd64|x64) | ||||
| arch=x86_64 | ||||
| ;; | ||||
| aarch64) | ||||
| arch=arm64 | ||||
addaleax marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
| ;; | ||||
| *) | ||||
| # Use uname’s reported architecture in the jq query. | ||||
| esac | ||||
|
|
||||
| if [ "$os" = "linux" ]; then | ||||
| if ldd $(which curl) | grep -q libssl.so.3 ; then | ||||
| openssl_query='and .sharedOpenssl == "openssl3"' | ||||
| else | ||||
| openssl_query='and (has("sharedOpenssl") | not)' | ||||
| fi | ||||
| else | ||||
| openssl_query='' | ||||
| fi | ||||
|
|
||||
| jq_query=$(cat <<EOF | ||||
| .versions[0].downloads[] | | ||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can't really do a semver comparison here, right? Otherwise I think that would be highly preferable. If we leave this as-is, I'd leave a comment in
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (@addaleax added the comment since jQ is a funky—if poetic, heh—place to do things like semver sorting.) |
||||
| select( | ||||
| .distro == "$os" and | ||||
| .arch == "$arch" | ||||
| $openssl_query | ||||
| ) | | ||||
| .archive.url | ||||
| EOF | ||||
| ) | ||||
|
|
||||
| url=$(curl -fsSL $MONGOSH_RELEASES_URL | jq -r "$jq_query") | ||||
|
|
||||
| if [ -z "$url" ]; then | ||||
| say "❓ No download found for $os on $arch." | ||||
| show_download_link | ||||
| exit 1 | ||||
| fi | ||||
|
|
||||
| case "$ext" in | ||||
| zip) | ||||
| file=$(mktemp) | ||||
|
|
||||
| say "Downloading $url to $file …" | ||||
| #trap 'rm -f "$file"' EXIT | ||||
|
|
||||
| curl -fsSL "$url" > "$file" | ||||
| say "Downloaded $ext file; extracting mongosh …" | ||||
|
|
||||
| unzip -j "$file" '*/bin/mongosh*' | ||||
| ;; | ||||
| tgz) | ||||
| say "Downloading & extracting from $url …" | ||||
|
|
||||
| curl -fsSL "$url" | tar -xzf - \ | ||||
addaleax marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
| --transform "s/.*\///" \ | ||||
| --wildcards "**/bin/mongosh*" \ | ||||
| | sed -E 's/^.*[/]//' | ||||
|
|
||||
| ;; | ||||
| *) | ||||
| say "Bad file extension: $ext" | ||||
| show_download_link | ||||
| exit 1 | ||||
| esac | ||||
|
|
||||
| ./mongosh --build-info >/dev/null 2>&1 || { | ||||
| say "❌ Downloaded mongosh is not executable." | ||||
| ./mongosh --build-info | ||||
| exit 1 | ||||
| } | ||||
|
|
||||
| say "✅ Success! 'mongosh' and its crypto library are now saved in this directory." | ||||
Uh oh!
There was an error while loading. Please reload this page.