mirror of
https://github.com/gradle/gradle-build-action.git
synced 2024-11-22 17:12:51 +00:00
Lint 2
This commit is contained in:
parent
6cee865aea
commit
1647b85e82
2 changed files with 39 additions and 23 deletions
2
dist/main/index.js
vendored
2
dist/main/index.js
vendored
File diff suppressed because one or more lines are too long
|
@ -30,57 +30,59 @@ export async function gradleVersion(version: string): Promise<string> {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function gradleCurrent(): Promise<string> {
|
async function gradleCurrent(): Promise<string> {
|
||||||
const json = await gradleVersionDeclaration(
|
const versionInfo = await gradleVersionDeclaration(
|
||||||
`${gradleVersionsBaseUrl}/current`
|
`${gradleVersionsBaseUrl}/current`
|
||||||
)
|
)
|
||||||
return provisionGradle(json.version, json.downloadUrl)
|
return provisionGradle(versionInfo.version, versionInfo.downloadUrl)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function gradleReleaseCandidate(): Promise<string> {
|
async function gradleReleaseCandidate(): Promise<string> {
|
||||||
const json = await gradleVersionDeclaration(
|
const versionInfo = await gradleVersionDeclaration(
|
||||||
`${gradleVersionsBaseUrl}/release-candidate`
|
`${gradleVersionsBaseUrl}/release-candidate`
|
||||||
)
|
)
|
||||||
if (json) {
|
if (versionInfo) {
|
||||||
return provisionGradle(json.version, json.downloadUrl)
|
return provisionGradle(versionInfo.version, versionInfo.downloadUrl)
|
||||||
}
|
}
|
||||||
return gradleCurrent()
|
return gradleCurrent()
|
||||||
}
|
}
|
||||||
|
|
||||||
async function gradleNightly(): Promise<string> {
|
async function gradleNightly(): Promise<string> {
|
||||||
const json = await gradleVersionDeclaration(
|
const versionInfo = await gradleVersionDeclaration(
|
||||||
`${gradleVersionsBaseUrl}/nightly`
|
`${gradleVersionsBaseUrl}/nightly`
|
||||||
)
|
)
|
||||||
return provisionGradle(json.version, json.downloadUrl)
|
return provisionGradle(versionInfo.version, versionInfo.downloadUrl)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function gradleReleaseNightly(): Promise<string> {
|
async function gradleReleaseNightly(): Promise<string> {
|
||||||
const json = await gradleVersionDeclaration(
|
const versionInfo = await gradleVersionDeclaration(
|
||||||
`${gradleVersionsBaseUrl}/release-nightly`
|
`${gradleVersionsBaseUrl}/release-nightly`
|
||||||
)
|
)
|
||||||
return provisionGradle(json.version, json.downloadUrl)
|
return provisionGradle(versionInfo.version, versionInfo.downloadUrl)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function gradle(version: string): Promise<string> {
|
async function gradle(version: string): Promise<string> {
|
||||||
const declaration = await findGradleVersionDeclaration(version)
|
const versionInfo = await findGradleVersionDeclaration(version)
|
||||||
if (!declaration) {
|
if (!versionInfo) {
|
||||||
throw new Error(`Gradle version ${version} does not exists`)
|
throw new Error(`Gradle version ${version} does not exists`)
|
||||||
}
|
}
|
||||||
return provisionGradle(declaration.version, declaration.downloadUrl)
|
return provisionGradle(versionInfo.version, versionInfo.downloadUrl)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function gradleVersionDeclaration(url: string): Promise<any | undefined> {
|
async function gradleVersionDeclaration(
|
||||||
const json: any = await httpGetJson(url)
|
url: string
|
||||||
return json.version && json.version.length > 0 ? json : undefined
|
): Promise<GradleVersionInfo> {
|
||||||
|
return await httpGetGradleVersion(url)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function findGradleVersionDeclaration(
|
async function findGradleVersionDeclaration(
|
||||||
version: string
|
version: string
|
||||||
): Promise<any | undefined> {
|
): Promise<GradleVersionInfo | undefined> {
|
||||||
const json: any = await httpGetJson(`${gradleVersionsBaseUrl}/all`)
|
const gradleVersions = await httpGetGradleVersions(
|
||||||
const found: any = json.find((entry: any) => {
|
`${gradleVersionsBaseUrl}/all`
|
||||||
|
)
|
||||||
|
return gradleVersions.find((entry: GradleVersionInfo) => {
|
||||||
return entry.version === version
|
return entry.version === version
|
||||||
})
|
})
|
||||||
return found ? found : undefined
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function provisionGradle(version: string, url: string): Promise<string> {
|
async function provisionGradle(version: string, url: string): Promise<string> {
|
||||||
|
@ -123,10 +125,19 @@ function executableFrom(installDir: string): string {
|
||||||
return path.join(installDir, 'bin', `${gradlew.installScriptFilename()}`)
|
return path.join(installDir, 'bin', `${gradlew.installScriptFilename()}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function httpGetJson(url: string): Promise<any> {
|
async function httpGetGradleVersion(url: string): Promise<GradleVersionInfo> {
|
||||||
|
return JSON.parse(await httpGetString(url))
|
||||||
|
}
|
||||||
|
|
||||||
|
async function httpGetGradleVersions(
|
||||||
|
url: string
|
||||||
|
): Promise<GradleVersionInfo[]> {
|
||||||
|
return JSON.parse(await httpGetString(url))
|
||||||
|
}
|
||||||
|
|
||||||
|
async function httpGetString(url: string): Promise<string> {
|
||||||
const response = await httpc.get(url)
|
const response = await httpc.get(url)
|
||||||
const body = await response.readBody()
|
return response.readBody()
|
||||||
return JSON.parse(body)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function httpDownload(url: string, localPath: string): Promise<void> {
|
async function httpDownload(url: string, localPath: string): Promise<void> {
|
||||||
|
@ -162,3 +173,8 @@ async function extractZip(zip: string, destination: string): Promise<void> {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface GradleVersionInfo {
|
||||||
|
version: string
|
||||||
|
downloadUrl: string
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue