Skip to content

Commit 70f3542

Browse files
zakkakclaude
andcommitted
Replace DISCO API with GitHub API for Mandrel latest version resolution.
The Foojay DISCO API is no longer needed for resolving the latest Mandrel release. Instead, use the GitHub Releases API to search for matching assets directly in the graalvm/mandrel repository. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 03e8abf commit 70f3542

3 files changed

Lines changed: 28 additions & 39 deletions

File tree

__tests__/mandrel.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ test('find latest', async () => {
5959
test('get known latest Mandrel for specific JDK', async () => {
6060
// Test deprecated versions that won't get updates anymore
6161
for (const combination of [
62-
['11', '22.2.0.0-Final'],
62+
['11', '21.3.6.0-Final'],
6363
['20', '23.0.1.2-Final']
6464
]) {
6565
const latest = await mandrel.getLatestMandrelReleaseUrl(combination[0])

src/mandrel.ts

Lines changed: 6 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,11 @@
11
import * as c from './constants.js'
2-
import * as httpClient from '@actions/http-client'
3-
import { downloadExtractAndCacheJDK } from './utils.js'
2+
import { downloadExtractAndCacheJDK, findLatestReleaseWithAsset } from './utils.js'
43
import { downloadTool } from '@actions/tool-cache'
54
import { basename } from 'path'
65

76
export const MANDREL_REPO = 'mandrel'
87
export const MANDREL_TAG_PREFIX = c.MANDREL_NAMESPACE
98
const MANDREL_DL_BASE = 'https://github.com/graalvm/mandrel/releases/download'
10-
const DISCO_API_BASE = 'https://api.foojay.io/disco/v3.0/packages/jdks'
11-
12-
interface JdkData {
13-
message: string
14-
/* eslint-disable @typescript-eslint/no-explicit-any */
15-
result: any
16-
/* eslint-enable @typescript-eslint/no-explicit-any */
17-
}
189

1910
export async function setUpMandrel(mandrelVersion: string, javaVersion: string): Promise<string> {
2011
const version = stripMandrelNamespace(mandrelVersion)
@@ -55,38 +46,15 @@ function getTagFromURI(uri: string): string {
5546
}
5647

5748
export async function getLatestMandrelReleaseUrl(javaVersion: string): Promise<string> {
58-
const url = `${DISCO_API_BASE}?jdk_version=${javaVersion}&distribution=${c.DISTRIBUTION_MANDREL}&architecture=${c.JDK_ARCH}&operating_system=${c.JDK_PLATFORM}&latest=per_distro`
59-
const _http = new httpClient.HttpClient()
60-
const response = await _http.getJson<JdkData>(url)
61-
if (response.statusCode !== 200) {
62-
throw new Error(`Failed to fetch latest Mandrel release for Java ${javaVersion} from DISCO API: ${response.result}`)
63-
}
64-
const result = response.result?.result[0]
49+
const expectedPrefix = `mandrel-java${javaVersion}-${c.GRAALVM_PLATFORM}-${c.GRAALVM_ARCH}-`
50+
const expectedSuffix = c.GRAALVM_FILE_EXTENSION
6551
try {
66-
const pkg_info_uri = result.links.pkg_info_uri
67-
return await getLatestMandrelReleaseUrlHelper(_http, javaVersion, pkg_info_uri)
68-
} catch (error) {
69-
throw new Error(`Failed to get latest Mandrel release for Java ${javaVersion} from DISCO API: ${error}`)
70-
}
71-
}
72-
73-
async function getLatestMandrelReleaseUrlHelper(
74-
_http: httpClient.HttpClient,
75-
java_version: string,
76-
pkg_info_uri: string
77-
): Promise<string> {
78-
const response = await _http.getJson<JdkData>(pkg_info_uri)
79-
if (response.statusCode !== 200) {
80-
throw new Error(
81-
`Failed to fetch package info of latest Mandrel release for Java ${java_version} from DISCO API: ${response.result}`
52+
return await findLatestReleaseWithAsset(MANDREL_REPO, (name) =>
53+
name.startsWith(expectedPrefix) && name.endsWith(expectedSuffix)
8254
)
83-
}
84-
const result = response.result?.result[0]
85-
try {
86-
return result.direct_download_uri
8755
} catch (error) {
8856
throw new Error(
89-
`Failed to get download URI of latest Mandrel release for Java ${java_version} from DISCO API: ${error}`
57+
`Failed to find latest Mandrel release for Java ${javaVersion}. Are you sure java-version: '${javaVersion}' is correct? ${error}`
9058
)
9159
}
9260
}

src/utils.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,27 @@ export async function getLatestRelease(repo: string): Promise<c.LatestReleaseRes
2929
).data as c.LatestReleaseResponseData /** missing digest property */
3030
}
3131

32+
export async function findLatestReleaseWithAsset(
33+
repo: string,
34+
assetNamePredicate: (name: string) => boolean
35+
): Promise<string> {
36+
const octokit = getOctokit()
37+
const iterator = octokit.paginate.iterator(octokit.rest.repos.listReleases, {
38+
owner: c.GRAALVM_GH_USER,
39+
repo,
40+
per_page: 100
41+
})
42+
for await (const { data: releases } of iterator) {
43+
for (const release of releases) {
44+
const matchingAsset = release.assets.find((a) => assetNamePredicate(a.name))
45+
if (matchingAsset) {
46+
return matchingAsset.browser_download_url
47+
}
48+
}
49+
}
50+
throw new Error(`Could not find a release in '${repo}' with a matching asset.`)
51+
}
52+
3253
export async function getContents(repo: string, path: string): Promise<c.ContentsResponseData> {
3354
const octokit = getOctokit()
3455
return (

0 commit comments

Comments
 (0)