-
Notifications
You must be signed in to change notification settings - Fork 3
chore(NODE-6726): make install libmongocrypt script faster #66
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#! /usr/bin/env bash | ||
set -o errexit | ||
|
||
git clone https://github.com/mongodb/libmongocrypt.git _libmongocrypt | ||
cd _libmongocrypt | ||
|
||
git checkout --detach $REF | ||
|
||
COMMIT_HASH=$(git rev-parse HEAD) | ||
|
||
echo "COMMIT_HASH=$COMMIT_HASH" | ||
|
||
cd - | ||
rm -rf _libmongocrypt |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// @ts-check | ||
|
||
import { execSync } from "child_process"; | ||
import path from "path"; | ||
import url from 'node:url'; | ||
import { spawn } from "node:child_process"; | ||
import { once } from "node:events"; | ||
|
||
const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); | ||
|
||
/** Resolves to the root of this repository */ | ||
export function resolveRoot(...paths) { | ||
return path.resolve(__dirname, '..', '..', ...paths); | ||
} | ||
|
||
export function getCommitFromRef(ref) { | ||
console.error(`resolving ref: ${ref}`); | ||
const script = resolveRoot('.github', 'scripts', 'get-commit-from-ref.sh'); | ||
const output = execSync(`bash ${script}`, { env: { REF: ref }, encoding: 'utf-8' }) | ||
|
||
const regex = /COMMIT_HASH=(?<hash>[a-zA-Z0-9]+)/ | ||
const result = regex.exec(output); | ||
|
||
if (!result?.groups) throw new Error('unable to parse ref.') | ||
|
||
const { hash } = result.groups; | ||
|
||
console.error(`resolved to: ${hash}`); | ||
return hash; | ||
} | ||
|
||
export function buildLibmongocryptDownloadUrl(ref, platform) { | ||
const hash = getCommitFromRef(ref); | ||
|
||
// sort of a hack - if we have an official release version, it'll be in the form `major.minor`. otherwise, | ||
// we'd expect a commit hash or `master`. | ||
if (ref.includes('.')) { | ||
const [major, minor, _patch] = ref.split('.'); | ||
|
||
// Just a note: it may appear that this logic _doesn't_ support patch releases but it actually does. | ||
// libmongocrypt's creates release branches for minor releases in the form `r<major>.<minor>`. | ||
// Any patches made to this branch are committed as tags in the form <major>.<minor>.<patch>. | ||
// So, the branch that is used for the AWS s3 upload is `r<major>.<minor>` and the commit hash | ||
// is the commit hash we parse from the `getCommitFromRef()` (which handles switching to git tags and | ||
// getting the commit hash at that tag just fine). | ||
const branch = `r${major}.${minor}` | ||
|
||
return `https://mciuploads.s3.amazonaws.com/libmongocrypt-release/${platform}/${branch}/${hash}/libmongocrypt.tar.gz`; | ||
} | ||
|
||
// just a note here - `master` refers to the branch, the hash is the commit on that branch. | ||
// if we ever need to download binaries from a non-master branch (or non-release branch), | ||
// this will need to be modified somehow. | ||
return `https://mciuploads.s3.amazonaws.com/libmongocrypt/${platform}/master/${hash}/libmongocrypt.tar.gz`; | ||
} | ||
|
||
export function getLibmongocryptPrebuildName() { | ||
const platformMatrix = { | ||
['darwin-arm64']: 'macos', | ||
['darwin-x64']: 'macos', | ||
['linux-ppc64']: 'rhel-71-ppc64el', | ||
['linux-s390x']: 'rhel72-zseries-test', | ||
['linux-arm64']: 'ubuntu1804-arm64', | ||
['linux-x64']: 'rhel-70-64-bit', | ||
['win32-x64']: 'windows-test' | ||
}; | ||
|
||
const detectedPlatform = `${process.platform}-${process.arch}`; | ||
const prebuild = platformMatrix[detectedPlatform]; | ||
|
||
if (prebuild == null) throw new Error(`Unsupported: ${detectedPlatform}`); | ||
|
||
return prebuild; | ||
} | ||
|
||
/** `xtrace` style command runner, uses spawn so that stdio is inherited */ | ||
export async function run(command, args = [], options = {}) { | ||
const commandDetails = `+ ${command} ${args.join(' ')}${options.cwd ? ` (in: ${options.cwd})` : ''}`; | ||
console.error(commandDetails); | ||
const proc = spawn(command, args, { | ||
shell: process.platform === 'win32', | ||
stdio: 'inherit', | ||
cwd: resolveRoot('.'), | ||
...options | ||
}); | ||
await once(proc, 'exit'); | ||
|
||
if (proc.exitCode != 0) throw new Error(`CRASH(${proc.exitCode}): ${commandDetails}`); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.