mirror of
https://github.com/gradle/gradle-build-action.git
synced 2025-07-03 05:45:59 +02:00
Refactor action execution for reuse
Introducing new actions for the GitHub dependency graph will involve reuse of much of the action infrastructure. This commit reorganises things a little to facilitate reuse.
This commit is contained in:
parent
680037c65b
commit
c94d573317
5 changed files with 76 additions and 61 deletions
|
@ -7,14 +7,36 @@ import * as cache from '@actions/cache'
|
|||
import * as toolCache from '@actions/tool-cache'
|
||||
|
||||
import * as gradlew from './gradlew'
|
||||
import * as layout from './repository-layout'
|
||||
import {handleCacheFailure, isCacheDisabled, isCacheReadOnly} from './cache-utils'
|
||||
|
||||
const gradleVersionsBaseUrl = 'https://services.gradle.org/versions'
|
||||
|
||||
/**
|
||||
* @return Gradle executable path
|
||||
* Install any configured version of Gradle, adding the executable to the PATH.
|
||||
* @return Installed Gradle executable or undefined if no version configured.
|
||||
*/
|
||||
export async function gradleVersion(version: string): Promise<string> {
|
||||
export async function provisionGradle(): Promise<string | undefined> {
|
||||
const gradleVersion = core.getInput('gradle-version')
|
||||
if (gradleVersion !== '' && gradleVersion !== 'wrapper') {
|
||||
return addToPath(path.resolve(await installGradle(gradleVersion)))
|
||||
}
|
||||
|
||||
const gradleExecutable = core.getInput('gradle-executable')
|
||||
if (gradleExecutable !== '') {
|
||||
const workspaceDirectory = layout.workspaceDirectory()
|
||||
return addToPath(path.resolve(workspaceDirectory, gradleExecutable))
|
||||
}
|
||||
|
||||
return undefined
|
||||
}
|
||||
|
||||
async function addToPath(executable: string): Promise<string> {
|
||||
core.addPath(path.dirname(executable))
|
||||
return executable
|
||||
}
|
||||
|
||||
async function installGradle(version: string): Promise<string> {
|
||||
switch (version) {
|
||||
case 'current':
|
||||
return gradleCurrent()
|
||||
|
@ -34,13 +56,13 @@ export async function gradleVersion(version: string): Promise<string> {
|
|||
|
||||
async function gradleCurrent(): Promise<string> {
|
||||
const versionInfo = await gradleVersionDeclaration(`${gradleVersionsBaseUrl}/current`)
|
||||
return provisionGradle(versionInfo)
|
||||
return installGradleVersion(versionInfo)
|
||||
}
|
||||
|
||||
async function gradleReleaseCandidate(): Promise<string> {
|
||||
const versionInfo = await gradleVersionDeclaration(`${gradleVersionsBaseUrl}/release-candidate`)
|
||||
if (versionInfo && versionInfo.version && versionInfo.downloadUrl) {
|
||||
return provisionGradle(versionInfo)
|
||||
return installGradleVersion(versionInfo)
|
||||
}
|
||||
core.info('No current release-candidate found, will fallback to current')
|
||||
return gradleCurrent()
|
||||
|
@ -48,12 +70,12 @@ async function gradleReleaseCandidate(): Promise<string> {
|
|||
|
||||
async function gradleNightly(): Promise<string> {
|
||||
const versionInfo = await gradleVersionDeclaration(`${gradleVersionsBaseUrl}/nightly`)
|
||||
return provisionGradle(versionInfo)
|
||||
return installGradleVersion(versionInfo)
|
||||
}
|
||||
|
||||
async function gradleReleaseNightly(): Promise<string> {
|
||||
const versionInfo = await gradleVersionDeclaration(`${gradleVersionsBaseUrl}/release-nightly`)
|
||||
return provisionGradle(versionInfo)
|
||||
return installGradleVersion(versionInfo)
|
||||
}
|
||||
|
||||
async function gradle(version: string): Promise<string> {
|
||||
|
@ -61,7 +83,7 @@ async function gradle(version: string): Promise<string> {
|
|||
if (!versionInfo) {
|
||||
throw new Error(`Gradle version ${version} does not exists`)
|
||||
}
|
||||
return provisionGradle(versionInfo)
|
||||
return installGradleVersion(versionInfo)
|
||||
}
|
||||
|
||||
async function gradleVersionDeclaration(url: string): Promise<GradleVersionInfo> {
|
||||
|
@ -75,7 +97,7 @@ async function findGradleVersionDeclaration(version: string): Promise<GradleVers
|
|||
})
|
||||
}
|
||||
|
||||
async function provisionGradle(versionInfo: GradleVersionInfo): Promise<string> {
|
||||
async function installGradleVersion(versionInfo: GradleVersionInfo): Promise<string> {
|
||||
return core.group(`Provision Gradle ${versionInfo.version}`, async () => {
|
||||
return locateGradleAndDownloadIfRequired(versionInfo)
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue