Skip to content

Commit

Permalink
#167: Generate extension registry using latest releases
Browse files Browse the repository at this point in the history
  • Loading branch information
kaklakariada committed Mar 21, 2024
1 parent da93118 commit cb0d994
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 1 deletion.
11 changes: 11 additions & 0 deletions doc/developer_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,17 @@ aws cloudformation describe-stacks --stack-name ExtensionManagerRegistry --query

### Deploy Registry Content

#### Generate Registry Content

Run the following command to generate the registry content using the latest extension versions:

```sh
cd registry-upload
npm run generate
```

#### Upload Registry

To deploy the content of the Extension Registry to `test` or `prod` stage, run the following command:

```sh
Expand Down
7 changes: 6 additions & 1 deletion registry-upload/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ export function getAvailableStages(): string[] {
return Object.keys(Stage).map(value => value.toLowerCase())
}

export function getExtensionGitHubRepos(): string[] {
// "oracle-virtual-schema" extension is not yet released, see https://github.com/exasol/oracle-virtual-schema/issues/45
return ["s3-document-files-virtual-schema", "row-level-security-lua", "cloud-storage-extension",
"kafka-connector-extension", "kinesis-connector-extension"]
}

export interface CommandLineArgs {
stage: Stage
dryRun: boolean
}

56 changes: 56 additions & 0 deletions registry-upload/src/generate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { exec } from "child_process";
import { writeFileSync } from "fs";
import { Octokit } from "octokit";
import { promisify } from "util";
import { Stage, getExtensionGitHubRepos } from "./common";

const TESTING_EXTENSION: Extension = { id: "testing-extension", url: "https://d3d6d68cbkri8h.cloudfront.net/testing-extension.js" }

generateAllRegistries().catch((reason) => console.log("Failure:", reason))


async function generateAllRegistries() {
const extensions = await fetchLatestExtensions(getExtensionGitHubRepos())
const testStageExtensions = extensions.concat(TESTING_EXTENSION)
writeRegistry(Stage.Prod, { extensions })
writeRegistry(Stage.Test, { extensions: testStageExtensions })
}

interface RegistryContent {
extensions: Extension[]
}

interface Extension {
id: string
url: string
}

async function fetchLatestExtensions(gitHubRepos: string[]): Promise<Extension[]> {
const octokit = await createGitHubClient()
async function fetchLatestExtension(gitHubRepo: string): Promise<Extension> {
const latestRelease = await octokit.rest.repos.getLatestRelease({ owner: "exasol", repo: gitHubRepo })
const version = latestRelease.data.tag_name
const extensionAssetsNames = latestRelease.data.assets.map(asset => asset.name).filter(name => name.endsWith(".js"))
if (extensionAssetsNames.length !== 1) {
const url = `https://github.com/exasol/${gitHubRepo}/releases/tag/${version}`
throw new Error(`Expected exactly one .js extension in release ${url}, but got ${extensionAssetsNames.length}`)
}
return { id: gitHubRepo, url: `https://extensions-internal.exasol.com/com.exasol/${gitHubRepo}/${version}/${extensionAssetsNames[0]}` }
}
return Promise.all(gitHubRepos.map(fetchLatestExtension))
}

function writeRegistry(stage: Stage, content: RegistryContent) {
writeFileSync(`content/${stage}-registry.json`, JSON.stringify(content, null, 2))
}

async function createGitHubClient(): Promise<Octokit> {
const token = await getGitHubToken()
return new Octokit({ auth: token });
}

async function getGitHubToken(): Promise<string> {
const asyncExec = promisify(exec)
const { stdout } = await asyncExec("gh auth token")
return stdout
}

0 comments on commit cb0d994

Please sign in to comment.