-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* create sdk_gen script For streamlining the generation of a specific SDK version * expanding the script * - don't pull ci if the correct version is active - generate all SDKs - smoke test typescript - ran `bin/gensdk 22.6` * skipping a serialization test hoping to unblock CI * remove Python 3.6 support
- Loading branch information
Showing
44 changed files
with
11,884 additions
and
7,653 deletions.
There are no files selected for viewing
This file contains 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 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 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,21 @@ | ||
#!/bin/sh | ||
# pull a version and start up looker dockerized container | ||
|
||
if [[ $# -ne 1 ]]; then | ||
echo "$0 <release_version>" | ||
echo " release_version: XX_XX, like 22_4, not 22.4" | ||
exit 2 | ||
fi | ||
|
||
VERSION=$1 | ||
NAME=looker-sdk-codegen-ci | ||
DOCK=us-west1-docker.pkg.dev/cloud-looker-sdk-codegen-cicd/looker/$VERSION | ||
|
||
function dock_stop() { | ||
docker kill $(docker ps -a -q) 1> /dev/null | ||
} | ||
|
||
dock_stop | ||
docker rm -f "$NAME" 1> /dev/null | ||
docker pull "$DOCK" | ||
docker run --name "$NAME" -d -p 10000:9999 -p 20000:19999 "$DOCK" |
This file contains 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,172 @@ | ||
#!/usr/bin/env node | ||
|
||
/** | ||
* Create branch if on main, | ||
* generate SDK bindings, | ||
* run smoke tests for TS and Python, | ||
* commit and push if everything passes | ||
* create pull request https://docs.github.com/en/rest/pulls/pulls#create-a-pull-request | ||
* */ | ||
|
||
const path = require('path') | ||
const proc = require('child_process') | ||
const looker = require('@looker/sdk-node') | ||
const utf8 = { encoding: 'utf-8' } | ||
|
||
const root = path.join(__dirname, '/../') | ||
const sdk = looker.LookerNodeSDK.init40() | ||
|
||
async function sleep(ms) { | ||
return new Promise(resolve => setTimeout(resolve, ms)) | ||
} | ||
|
||
/** wait for the Looker CI image to be responsive */ | ||
const waitForLooker = async () => { | ||
const max_tries = 30 | ||
const delay = 5 | ||
let alive = false | ||
let tries = 1 | ||
while (tries <= max_tries && !alive) { | ||
try { | ||
const user = await sdk.ok(sdk.me()) // make any API call | ||
alive = sdk.authSession.isAuthenticated() | ||
console.info(`Hi, ${user.first_name} ${user.last_name}!`) | ||
await sdk.authSession.logout() | ||
} catch { | ||
await sleep(delay * 1000) | ||
tries++ | ||
console.info(`Waiting ${delay} seconds before attempt ${tries} of ${max_tries} (Total: ${delay * (tries - 1)})`) | ||
} | ||
} | ||
return alive | ||
} | ||
|
||
/** | ||
* Get the CI version for the release | ||
* @param release to munge | ||
* @returns release version with _ instead of . | ||
*/ | ||
const ciVersion = (release) => release.replace('.', '_') | ||
|
||
const ok = (result) => { | ||
if (typeof result === 'string') { | ||
return true | ||
} | ||
console.error(result) | ||
return false | ||
} | ||
|
||
const run = (command) => { | ||
let result | ||
try { | ||
console.info(`Running ${command} ...`) | ||
result = proc.execSync(command).toString() | ||
} | ||
catch (error) { | ||
result = error | ||
} | ||
return result | ||
} | ||
|
||
/** | ||
* Run multiple commands one after another, returning on first failure | ||
* @param commands | ||
*/ | ||
const batch = (commands) => { | ||
let result = '' | ||
commands.forEach(command => { | ||
result = run(command) | ||
if (!ok(result)) { | ||
console.error(`${command} failed.`) | ||
return result | ||
} | ||
}) | ||
return result | ||
} | ||
|
||
/** get the trimmed output of the command as a UTF-8 string */ | ||
const execRead = (command) => { | ||
return proc.execSync(command, utf8).trim() | ||
} | ||
|
||
/** get this git repository's current branch name */ | ||
const getCurrentBranch = () => execRead('git rev-parse --abbrev-ref HEAD') | ||
|
||
/** | ||
* Get the standardized name for this branch | ||
* @param release either xx.xx or xx_xx | ||
* @returns sdk_<release> | ||
*/ | ||
const branchName = (release) => `sdk_${ciVersion(release)}` | ||
|
||
/** | ||
* Is the running version the desired release? | ||
* @param release version to check | ||
* @returns {Promise<boolean>} | ||
*/ | ||
const checkVersion = async (release) => { | ||
try { | ||
const payload = await sdk.ok(sdk.versions()) | ||
return payload.looker_release_version.startsWith(release) | ||
} catch { | ||
// don't care what the error was, it failed | ||
return false | ||
} | ||
} | ||
|
||
/** | ||
* Pull the specified Looker CI image and wait for it to be ready | ||
* @param release like '21.10' | ||
*/ | ||
const pullci = async (release) => { | ||
const opts = { | ||
cwd: root, | ||
maxBuffer: 1024 * 1024, | ||
stdio: 'inherit', | ||
} | ||
if (! await checkVersion(release)) { | ||
const script = path.resolve(root, 'bin/pullci') | ||
// Throws exception on error, which we want | ||
proc.execFileSync(script, [ciVersion(release)], opts) | ||
return await waitForLooker() | ||
} | ||
} | ||
|
||
/** Regen against the specified release and complete flows */ | ||
const regen = async (release) => { | ||
let result | ||
console.info(`Generating SDKs for Looker ${release} ...`) | ||
let current = getCurrentBranch() | ||
if (current === 'main') { | ||
const branch = branchName(release) | ||
console.log(`Creating branch ${branch} ...`) | ||
result = run(`git checkout -b ${branch} origin/main`) | ||
if (!(ok(result))) return result | ||
} | ||
await pullci(release) | ||
return batch([ | ||
'yarn gen', | ||
'bin/smoke typescript', | ||
/* | ||
Test these out after first cut is merged to main | ||
'git add -A', | ||
`git commit -m "feat: generate SDK version ${release}"`, | ||
'git push' | ||
create PR | ||
*/ | ||
]) | ||
} | ||
|
||
(async () => { | ||
console.info(`${process.argv[1]} <version>`) | ||
console.info(' version: Looker release version, like 22.10') | ||
const args = process.argv.slice(2) | ||
if (args.length >= 1) { | ||
await regen(args[0]) | ||
} else | ||
{ | ||
console.error('No release version was specified') | ||
} | ||
})().catch( e => { | ||
console.error(e) | ||
}) |
This file contains 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 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 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 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
Oops, something went wrong.