Skip to content

Commit

Permalink
feat: generate SDK 22.6 (#1102)
Browse files Browse the repository at this point in the history
* 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
jkaster authored Jun 30, 2022
1 parent 566edeb commit 2162860
Show file tree
Hide file tree
Showing 44 changed files with 11,884 additions and 7,653 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/python-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ jobs:
python-version:
- '3.10'
include:
- python-version: '3.6'
os: ubuntu
- python-version: '3.7'
os: ubuntu
- python-version: '3.8'
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,9 @@ The code generator will:

- validate the OpenAPI 3.x file(s)

- by default, call the code generator for each active language configured in [`codeGenerators.ts`](packages/sdk-codegen/src/codeGenerators.ts)
- by default, call the code generator for each active language

- If you want to generate for one specific language, use `yarn gen {language}`. Currently, supported `{language}` values are `kotlin`, `python`, `swift` and `typescript`
- To generate one specific language SDK, use `yarn gen {language}`. The supported languages have a factory declared in the `Generators` array in [`codeGenerators.ts`](packages/sdk-codegen/src/codeGenerators.ts)

When the generator completes successfully, the output will be similar to:

Expand Down Expand Up @@ -191,7 +191,7 @@ yarn run
to see the list of all scripts that can be run by the code generator.

After generation, the generated code might not conform with the code standards.
Changes cannot be commited until they pass the lint tests.
Changes cannot be committed until they pass the lint tests.
This can be checked with the following:

```sh
Expand Down
21 changes: 21 additions & 0 deletions bin/pullci
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"
172 changes: 172 additions & 0 deletions bin/sdk_gen
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)
})
2 changes: 1 addition & 1 deletion csharp/rtl/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public struct Constants

public const string DefaultApiVersion = "4.0";
public const string AgentPrefix = "CS-SDK";
public const string LookerVersion = "22.4";
public const string LookerVersion = "22.6";

public const string Bearer = "Bearer";
public const string LookerAppiId = "x-looker-appid";
Expand Down
4 changes: 2 additions & 2 deletions csharp/sdk/3.1/models.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4044,7 +4044,7 @@ public class ThemeSettings : SdkModel
{
/// <summary>Default background color</summary>
public string? background_color { get; set; } = null;
/// <summary>Base font size for scaling fonts</summary>
/// <summary>Base font size for scaling fonts (only supported by legacy dashboards)</summary>
public string? base_font_size { get; set; } = null;
/// <summary>Optional. ID of color collection to use with the theme. Use an empty string for none.</summary>
public string? color_collection_id { get; set; } = null;
Expand Down Expand Up @@ -4074,7 +4074,7 @@ public class ThemeSettings : SdkModel
public string? warn_button_color { get; set; } = null;
/// <summary>The text alignment of tile titles (New Dashboards)</summary>
public string? tile_title_alignment { get; set; } = null;
/// <summary>Toggles the tile shadow (New Dashboards)</summary>
/// <summary>Toggles the tile shadow (not supported)</summary>
public bool? tile_shadow { get; set; } = null;
}

Expand Down
20 changes: 19 additions & 1 deletion csharp/sdk/4.0/methods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
/// SOFTWARE.
///

/// 438 API methods
/// 439 API methods

#nullable enable
using System;
Expand Down Expand Up @@ -214,6 +214,19 @@ public async Task<SdkResponse<string, Exception>> enqueue_alert(
{ "force", force }},null,options);
}

/// # Alert Notifications.
/// The endpoint returns all the alert notifications received by the user on email in the past 7 days. It also returns whether the notifications have been read by the user.
///
/// GET /alert_notifications -> AlertNotifications[]
///
/// <returns><c>AlertNotifications[]</c> It shows all the alert notifications received by the user on email. (application/json)</returns>
///
public async Task<SdkResponse<AlertNotifications[], Exception>> alert_notifications(
ITransportSettings? options = null)
{
return await AuthRequest<AlertNotifications[], Exception>(HttpMethod.Get, "/alert_notifications", null,null,options);
}

#endregion Alert: Alert

#region ApiAuth: API Authentication
Expand Down Expand Up @@ -670,6 +683,9 @@ public async Task<SdkResponse<OauthClientApp, Exception>> update_oauth_client_ap
/// Deletes the registration info of the app with the matching client_guid.
/// All active sessions and tokens issued for this app will immediately become invalid.
///
/// As with most REST DELETE operations, this endpoint does not return an error if the
/// indicated resource does not exist.
///
/// ### Note: this deletion cannot be undone.
///
/// DELETE /oauth_client_apps/{client_guid} -> string
Expand Down Expand Up @@ -1961,6 +1977,7 @@ public async Task<SdkResponse<MobileSettings, Exception>> mobile_settings(
///
/// Available settings are:
/// - extension_framework_enabled
/// - extension_load_url_enabled
/// - marketplace_auto_install_enabled
/// - marketplace_enabled
/// - privatelabel_configuration
Expand All @@ -1984,6 +2001,7 @@ public async Task<SdkResponse<Setting, Exception>> get_setting(
///
/// Available settings are:
/// - extension_framework_enabled
/// - extension_load_url_enabled
/// - marketplace_auto_install_enabled
/// - marketplace_enabled
/// - privatelabel_configuration
Expand Down
32 changes: 28 additions & 4 deletions csharp/sdk/4.0/models.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
/// SOFTWARE.
///

/// 310 API models: 231 Spec, 0 Request, 59 Write, 20 Enum
/// 311 API models: 232 Spec, 0 Request, 59 Write, 20 Enum

#nullable enable
using System;
Expand Down Expand Up @@ -154,6 +154,24 @@ public class AlertFieldFilter : SdkModel
public string? filter_value { get; set; } = null;
}

public class AlertNotifications : SdkModel
{
/// <summary>ID of the notification (read-only)</summary>
public string? notification_id { get; set; } = null;
/// <summary>ID of the alert (read-only)</summary>
public string? alert_condition_id { get; set; } = null;
/// <summary>ID of the user (read-only)</summary>
public string? user_id { get; set; } = null;
/// <summary>Read state of the notification</summary>
public bool? is_read { get; set; } = null;
/// <summary>The value of the field on which the alert condition is set (read-only)</summary>
public double? field_value { get; set; } = null;
/// <summary>The value of the threshold which triggers the alert notification (read-only)</summary>
public double? threshold_value { get; set; } = null;
/// <summary>The time at which the alert query ran (read-only)</summary>
public string? ran_at { get; set; } = null;
}

public class AlertPatch : SdkModel
{
/// <summary>New owner ID of the alert</summary>
Expand Down Expand Up @@ -1292,6 +1310,8 @@ public class DashboardElement : SdkModel
public string? title_text_as_html { get; set; } = null;
/// <summary>Text tile subtitle text as Html (read-only)</summary>
public string? subtitle_text_as_html { get; set; } = null;
/// <summary>Extension ID (read-only)</summary>
public string? extension_id { get; set; } = null;
}

public class DashboardFilter : SdkModel
Expand Down Expand Up @@ -4440,6 +4460,8 @@ public class Setting : SdkModel
{
/// <summary>Toggle extension framework on or off</summary>
public bool? extension_framework_enabled { get; set; } = null;
/// <summary>(DEPRECATED) Toggle extension extension load url on or off. Do not use. This is temporary setting that will eventually become a noop and subsequently deleted.</summary>
public bool? extension_load_url_enabled { get; set; } = null;
/// <summary>Toggle marketplace auto install on or off. Note that auto install only runs if marketplace is enabled.</summary>
public bool? marketplace_auto_install_enabled { get; set; } = null;
/// <summary>Toggle marketplace on or off</summary>
Expand Down Expand Up @@ -4734,7 +4756,7 @@ public class ThemeSettings : SdkModel
{
/// <summary>Default background color</summary>
public string? background_color { get; set; } = null;
/// <summary>Base font size for scaling fonts</summary>
/// <summary>Base font size for scaling fonts (only supported by legacy dashboards)</summary>
public string? base_font_size { get; set; } = null;
/// <summary>Optional. ID of color collection to use with the theme. Use an empty string for none.</summary>
public string? color_collection_id { get; set; } = null;
Expand Down Expand Up @@ -4764,7 +4786,7 @@ public class ThemeSettings : SdkModel
public string? warn_button_color { get; set; } = null;
/// <summary>The text alignment of tile titles (New Dashboards)</summary>
public string? tile_title_alignment { get; set; } = null;
/// <summary>Toggles the tile shadow (New Dashboards)</summary>
/// <summary>Toggles the tile shadow (not supported)</summary>
public bool? tile_shadow { get; set; } = null;
}

Expand Down Expand Up @@ -5393,7 +5415,7 @@ public class WriteDashboardBase : SdkModel
}

/// Dynamic writeable type for DashboardElement removes:
/// can, body_text_as_html, edit_uri, id, lookml_link_id, note_text_as_html, refresh_interval_to_i, alert_count, title_text_as_html, subtitle_text_as_html
/// can, body_text_as_html, edit_uri, id, lookml_link_id, note_text_as_html, refresh_interval_to_i, alert_count, title_text_as_html, subtitle_text_as_html, extension_id
public class WriteDashboardElement : SdkModel
{
/// <summary>Text tile body text</summary>
Expand Down Expand Up @@ -6281,6 +6303,8 @@ public class WriteSetting : SdkModel
{
/// <summary>Toggle extension framework on or off</summary>
public bool? extension_framework_enabled { get; set; } = null;
/// <summary>(DEPRECATED) Toggle extension extension load url on or off. Do not use. This is temporary setting that will eventually become a noop and subsequently deleted.</summary>
public bool? extension_load_url_enabled { get; set; } = null;
/// <summary>Toggle marketplace auto install on or off. Note that auto install only runs if marketplace is enabled.</summary>
public bool? marketplace_auto_install_enabled { get; set; } = null;
/// <summary>Toggle marketplace on or off</summary>
Expand Down
Loading

0 comments on commit 2162860

Please sign in to comment.