mirror of
https://github.com/gradle/gradle-build-action.git
synced 2025-06-08 01:06:12 +02:00
Use built-in library functions in preference to custom implementations
- Use built-in `hashFiles` function included in '@actions/globv0.2.0' - Use `downloadTool` and `extractZip` functions from '@actions/tool-cache'
This commit is contained in:
parent
47c9af9d7d
commit
738bda9866
6 changed files with 39 additions and 227 deletions
|
@ -2,14 +2,11 @@ import * as fs from 'fs'
|
|||
import * as os from 'os'
|
||||
import * as path from 'path'
|
||||
import * as httpm from '@actions/http-client'
|
||||
import * as unzip from 'unzipper'
|
||||
import * as core from '@actions/core'
|
||||
import * as io from '@actions/io'
|
||||
import * as toolCache from '@actions/tool-cache'
|
||||
|
||||
import * as gradlew from './gradlew'
|
||||
|
||||
const httpc = new httpm.HttpClient('eskatos/gradle-command-action')
|
||||
const gradleVersionsBaseUrl = 'https://services.gradle.org/versions'
|
||||
|
||||
/**
|
||||
|
@ -95,22 +92,21 @@ async function provisionGradle(version: string, url: string): Promise<string> {
|
|||
return cachedExecutable
|
||||
}
|
||||
|
||||
const home = os.homedir()
|
||||
const tmpdir = path.join(home, 'gradle-provision-tmpdir')
|
||||
const downloadsDir = path.join(tmpdir, 'downloads')
|
||||
const installsDir = path.join(tmpdir, 'installs')
|
||||
await io.mkdirP(downloadsDir)
|
||||
await io.mkdirP(installsDir)
|
||||
const tmpdir = path.join(os.homedir(), 'gradle-provision-tmpdir')
|
||||
|
||||
core.info(`Downloading ${url}`)
|
||||
|
||||
const downloadPath = path.join(downloadsDir, `gradle-${version}-bin.zip`)
|
||||
await httpDownload(url, downloadPath)
|
||||
const downloadPath = path.join(
|
||||
tmpdir,
|
||||
`downloads/gradle-${version}-bin.zip`
|
||||
)
|
||||
await toolCache.downloadTool(url, downloadPath)
|
||||
core.info(
|
||||
`Downloaded at ${downloadPath}, size ${fs.statSync(downloadPath).size}`
|
||||
)
|
||||
|
||||
await extractZip(downloadPath, installsDir)
|
||||
const installsDir = path.join(tmpdir, 'installs')
|
||||
await toolCache.extractZip(downloadPath, installsDir)
|
||||
const installDir = path.join(installsDir, `gradle-${version}`)
|
||||
core.info(`Extracted in ${installDir}`)
|
||||
|
||||
|
@ -138,38 +134,11 @@ async function httpGetGradleVersions(
|
|||
}
|
||||
|
||||
async function httpGetString(url: string): Promise<string> {
|
||||
const response = await httpc.get(url)
|
||||
const httpClient = new httpm.HttpClient('eskatos/gradle-command-action')
|
||||
const response = await httpClient.get(url)
|
||||
return response.readBody()
|
||||
}
|
||||
|
||||
async function httpDownload(url: string, localPath: string): Promise<void> {
|
||||
const response = await httpc.get(url)
|
||||
return new Promise<void>(function (resolve, reject) {
|
||||
const writeStream = fs.createWriteStream(localPath)
|
||||
response.message
|
||||
.pipe(writeStream)
|
||||
.on('close', () => {
|
||||
resolve()
|
||||
})
|
||||
.on('error', err => {
|
||||
reject(err)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
async function extractZip(zip: string, destination: string): Promise<void> {
|
||||
return new Promise<void>(function (resolve, reject) {
|
||||
fs.createReadStream(zip)
|
||||
.pipe(unzip.Extract({path: destination}))
|
||||
.on('close', () => {
|
||||
resolve()
|
||||
})
|
||||
.on('error', err => {
|
||||
reject(err)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
interface GradleVersionInfo {
|
||||
version: string
|
||||
downloadUrl: string
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue