修改cache问题
All checks were successful
Continuous Integration / GitHub Actions Test (push) Successful in 6s

修改ci测试
This commit is contained in:
soul-walker 2024-03-22 14:59:07 +08:00
parent efea59e180
commit c9410badda
3 changed files with 17 additions and 19 deletions

View File

@ -27,6 +27,8 @@ jobs:
with:
maven-version: 3.8.2
- name: Check Setup Result
id: check-setup
run: mvn -version
- name: Check Output
id: output
run:
echo "The cache-hit value is ${{ steps.test-action.outputs.cache-hit
}}"

BIN
dist/index.js generated vendored

Binary file not shown.

View File

@ -6,26 +6,22 @@ import * as ac from '@actions/cache'
function getToolDirectoryName(version: string): string {
return `apache-maven-${version}`
}
const BaseDir = '/denv/maven'
export async function getMaven(version: string): Promise<void> {
let toolPath: string
toolPath = tc.find('maven', version)
if (!toolPath) {
const toolDirectoryName = getToolDirectoryName(version)
toolPath = path.join(BaseDir, toolDirectoryName)
const rcr = await ac.restoreCache([toolPath], toolDirectoryName)
if (!rcr) {
core.setOutput('cache-hit', false)
core.info(`Maven ${version} is not found in the cache`)
toolPath = await downloadMaven(version, toolDirectoryName)
await ac.saveCache([toolPath], toolDirectoryName)
core.info(`Maven ${version} has been cached, cache path: ${toolPath}`)
} else {
core.setOutput('cache-hit', true)
}
const toolDirectoryName = getToolDirectoryName(version)
toolPath = path.join(BaseDir, toolDirectoryName)
const rcr = await ac.restoreCache([toolPath], toolDirectoryName)
if (!rcr) {
core.setOutput('cache-hit', false)
core.info(`Maven ${version} is not found in the cache`)
toolPath = await downloadMaven(version, toolDirectoryName)
await ac.saveCache([toolPath], toolDirectoryName)
core.info(`Maven ${version} has been cached, cache path: ${toolPath}`)
} else {
core.setOutput('cache-hit', true)
}
toolPath = path.join(toolPath, 'bin')
@ -43,7 +39,7 @@ async function downloadMaven(
const downloadPath = await tc.downloadTool(downloadUrl)
const extractedPath = await tc.extractTar(downloadPath, BaseDir)
let toolRoot = path.join(extractedPath, toolDirectoryName)
return await tc.cacheDir(toolRoot, 'maven', version)
return toolRoot
} catch (err) {
throw err
}