Skip to content

Commit 709c6ec

Browse files
committed
Refactor GDS integration.
1 parent 6ceeefe commit 709c6ec

4 files changed

Lines changed: 119 additions & 91 deletions

File tree

__tests__/gds.test.ts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,30 @@
11
import * as path from 'path'
2+
import * as c from '../src/constants'
23
import {
34
downloadGraalVMViaGDSByJavaVersion,
45
downloadGraalVMViaGDSByJavaVersionEELegacy,
56
fetchArtifact,
67
fetchArtifactByJavaVersion,
78
fetchArtifactEE
89
} from '../src/gds'
9-
import { expect, test } from '@jest/globals'
10+
import { afterAll, beforeAll, expect, test } from '@jest/globals'
1011
import { fileURLToPath } from 'url'
1112

1213
const TEST_USER_AGENT = 'GraalVMGitHubActionTest/1.0.4'
14+
const originalGDSTarget = { ...c.GDS_TARGET }
1315

1416
const dirname = path.dirname(fileURLToPath(import.meta.url))
1517
process.env['RUNNER_TEMP'] = path.join(dirname, 'TEMP')
1618

19+
beforeAll(() => {
20+
// The asserted artifact IDs are Linux amd64 artifacts.
21+
Object.assign(c.GDS_TARGET, { os: 'linux', arch: 'amd64' })
22+
})
23+
24+
afterAll(() => {
25+
Object.assign(c.GDS_TARGET, originalGDSTarget)
26+
})
27+
1728
test('fetch artifacts', async () => {
1829
let artifact
1930
// Test innovation releases
@@ -28,32 +39,31 @@ test('fetch artifacts', async () => {
2839
})
2940

3041
test('fetch artifacts by java version', async () => {
31-
let artifact = await fetchArtifactByJavaVersion(TEST_USER_AGENT, 'isBase:True', '17.0.12')
42+
let artifact = await fetchArtifactByJavaVersion(TEST_USER_AGENT, '17.0.12')
3243
expect(artifact.id).toBe('1C351E8F41BB8E9EE0631518000AE5F2')
3344
expect(artifact.checksum).toBe('b6f3dace24cf1960ec790216f4c86f00d4f43df64e4e8b548f6382f04894713f')
34-
artifact = await fetchArtifactByJavaVersion(TEST_USER_AGENT, 'isBase:True', '17')
45+
artifact = await fetchArtifactByJavaVersion(TEST_USER_AGENT, '17')
3546
expect(artifact.checksum).toHaveLength('b6f3dace24cf1960ec790216f4c86f00d4f43df64e4e8b548f6382f04894713f'.length)
3647
})
3748

3849
test('errors when downloading artifacts', async () => {
3950
await expect(downloadGraalVMViaGDSByJavaVersion('invalid', '17')).rejects.toThrow(
4051
'The provided "gds-token" was rejected (reason: "Invalid download token", opc-request-id: '
4152
)
42-
await expect(downloadGraalVMViaGDSByJavaVersion('invalid', '1')).rejects.toThrow('Unable to find GraalVM for JDK 1')
53+
await expect(downloadGraalVMViaGDSByJavaVersion('invalid', '1')).rejects.toThrow(
54+
"Unable to find GDS artifact. Are you sure java-version: '1' is correct?"
55+
)
4356
})
4457

4558
test('fetch legacy artifacts', async () => {
46-
let artifact = await fetchArtifactEE(TEST_USER_AGENT, 'isBase:True', '22.1.0', '11')
59+
let artifact = await fetchArtifactEE(TEST_USER_AGENT, '22.1.0', '11')
4760
expect(artifact.id).toBe('DCECD1C1B0B5B8DBE0536E16000A5C74')
4861
expect(artifact.checksum).toBe('4280782f6c7fcabe0ba707e8389cbfaf7bbe6b0cf634d309e6efcd1b172e3ce6')
49-
artifact = await fetchArtifactEE(TEST_USER_AGENT, 'isBase:True', '22.1.0', '17')
62+
artifact = await fetchArtifactEE(TEST_USER_AGENT, '22.1.0', '17')
5063
expect(artifact.id).toBe('DCECD2068882A0E9E0536E16000A9504')
5164
expect(artifact.checksum).toBe('e897add7d94bc456a61e6f927e831dff759efa3392a4b69c720dd3debc8f947d')
5265

53-
await expect(fetchArtifactEE(TEST_USER_AGENT, 'isBase:False', '22.1.0', '11')).rejects.toThrow(
54-
'Found more than one GDS artifact'
55-
)
56-
await expect(fetchArtifactEE(TEST_USER_AGENT, 'isBase:True', '1.0.0', '11')).rejects.toThrow(
66+
await expect(fetchArtifactEE(TEST_USER_AGENT, '1.0.0', '11')).rejects.toThrow(
5767
'Unable to find JDK11-based GraalVM EE 1.0.0'
5868
)
5969
})

dist/main.js

Lines changed: 47 additions & 33 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/constants.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,28 @@ export const GRAALVM_RELEASES_REPO = 'graalvm-ce-builds'
4242

4343
export const MANDREL_NAMESPACE = 'mandrel-'
4444

45-
export const GDS_BASE = 'https://gds.oracle.com/api/20220101'
46-
export const GDS_GRAALVM_PRODUCT_ID = 'D53FAE8052773FFAE0530F15000AA6C6'
45+
const GDS_BASE = 'https://gds.oracle.com/api/20220101'
46+
const GDS_GRAALVM_PRODUCT_ID = 'D53FAE8052773FFAE0530F15000AA6C6'
47+
const GDS_ARTIFACTS_BASE = `${GDS_BASE}/artifacts?productId=${GDS_GRAALVM_PRODUCT_ID}&metadata=edition:ee&metadata=isBase:True&status=PUBLISHED&responseFields=id&responseFields=checksum`
48+
/* Latest is currently based on timeCreated. Eventually, we should sortBy=m:version when version sorting is fixed. */
49+
export const GDS_LAST_FILTER = '&sortBy=timeCreated&sortOrder=DESC'
50+
export const GDS_LATEST_FILTER = `${GDS_LAST_FILTER}&limit=1`
51+
export const GDS_USER_AGENT = `GraalVMGitHubAction/${ACTION_VERSION} (arch:${GRAALVM_ARCH}; os:${GRAALVM_PLATFORM})`
52+
53+
/**
54+
* Target platform used for GDS artifact queries. The binding remains constant,
55+
* while tests may temporarily replace these fields for fixture-specific IDs.
56+
*/
57+
export const GDS_TARGET = {
58+
arch: GRAALVM_ARCH,
59+
os: IS_MACOS ? 'macos' : GRAALVM_PLATFORM
60+
}
61+
62+
const gdsJDKFilter = (jdkMajorVersion: string | number) =>
63+
`&metadata=java:jdk${jdkMajorVersion}&metadata=os:${GDS_TARGET.os}&metadata=arch:${GDS_TARGET.arch}`
64+
export const gdsArtifactQueryUrl = (jdkMajorVersion: string | number, filter: string) =>
65+
`${GDS_ARTIFACTS_BASE}${gdsJDKFilter(jdkMajorVersion)}${filter}`
66+
export const gdsArtifactDownloadUrl = (artifactId: string) => `${GDS_BASE}/artifacts/${artifactId}/content`
4767

4868
export const ENV_GITHUB_EVENT_NAME = 'GITHUB_EVENT_NAME'
4969
export const EVENT_NAME_PULL_REQUEST = 'pull_request'

0 commit comments

Comments
 (0)