Attempt to use pre/post for caching

This commit is contained in:
Kirill Chernyshov 2022-07-19 12:16:49 +02:00
parent 28aba54040
commit c3c99992f9
No known key found for this signature in database
GPG Key ID: 83C196363AF97C4C
18 changed files with 198069 additions and 17495 deletions

View File

@ -36,4 +36,6 @@ inputs:
required: false
runs:
using: 'node12'
main: 'dist/index.js'
main: 'dist/main/index.js'
pre: 'dist/pre/index.js'
post: 'dist/post/index.js'

7057
dist/index.js vendored

File diff suppressed because it is too large Load Diff

1
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

65552
dist/main/index.js vendored Normal file

File diff suppressed because one or more lines are too long

1
dist/main/index.js.map vendored Normal file

File diff suppressed because one or more lines are too long

65552
dist/post/index.js vendored Normal file

File diff suppressed because one or more lines are too long

1
dist/post/index.js.map vendored Normal file

File diff suppressed because one or more lines are too long

1
dist/post/sourcemap-register.js vendored Normal file

File diff suppressed because one or more lines are too long

65552
dist/pre/index.js vendored Normal file

File diff suppressed because one or more lines are too long

1
dist/pre/index.js.map vendored Normal file

File diff suppressed because one or more lines are too long

1
dist/pre/sourcemap-register.js vendored Normal file

File diff suppressed because one or more lines are too long

11764
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -9,10 +9,14 @@
"format": "prettier --write **/*.ts",
"format-check": "prettier --check **/*.ts",
"lint": "eslint src/**/*.ts",
"package": "ncc build --source-map",
"package_main": "ncc build ./lib/setup-clojure.js --source-map --out ./dist/main",
"package_pre": "ncc build ./lib/pre-setup-clojure.js --source-map --out ./dist/pre",
"package_post": "ncc build ./lib/post-setup-clojure.js --source-map --out ./dist/post",
"package": "npm run package_main && npm run package_pre && npm run package_post",
"test": "jest",
"update-deps": "ncu -u",
"all": "npm run build && npm run format && npm run lint && npm run package && npm test"
"release": "npm run build && npm run format && npm run lint && npm run package",
"all": "npm run release && npm test"
},
"repository": {
"type": "git",
@ -26,6 +30,7 @@
"author": "DeLaGuardo",
"license": "MIT",
"dependencies": {
"@actions/cache": "^3.0.0",
"@actions/core": "^1.9.0",
"@actions/exec": "^1.1.1",
"@actions/http-client": "^2.0.1",
@ -33,20 +38,20 @@
"@actions/tool-cache": "^2.0.1"
},
"devDependencies": {
"@types/jest": "^28.1.4",
"@types/node": "^18.0.0",
"@types/jest": "^28.1.6",
"@types/node": "^18.0.6",
"@types/semver": "^7.3.10",
"@typescript-eslint/parser": "^5.30.0",
"@typescript-eslint/parser": "^5.30.7",
"@vercel/ncc": "^0.34.0",
"eslint": "^8.18.0",
"eslint": "^8.20.0",
"eslint-plugin-github": "^4.3.6",
"eslint-plugin-jest": "^26.5.3",
"jest": "^28.1.2",
"jest-circus": "^28.1.2",
"eslint-plugin-jest": "^26.6.0",
"jest": "^28.1.3",
"jest-circus": "^28.1.3",
"js-yaml": "^4.1.0",
"npm-check-updates": "^15.0.1",
"npm-check-updates": "^15.3.4",
"prettier": "2.7.1",
"ts-jest": "^28.0.5",
"ts-jest": "^28.0.7",
"typescript": "^4.7.4"
}
}

35
src/cache.ts Normal file
View File

@ -0,0 +1,35 @@
import * as cache from '@actions/cache'
import * as core from '@actions/core'
import * as path from 'path'
const cacheDir = _getCacheDirectory()
const tools = [
'Babashka',
'Boot',
'ClojureToolsDeps',
'cljstyle',
'clj-kondo',
'Leiningen',
'zprint'
]
const cachePaths = tools.map(tool => path.join(cacheDir, tool))
const cacheKey = `action-setup-clojure-tools-${tools.join('-')}`
export async function save(): Promise<void> {
const cacheId = await cache.saveCache(cachePaths, cacheKey)
if (cacheId !== -1) {
core.info(`Cache saved with key: ${cacheKey}`)
}
}
export async function restore(): Promise<void> {
await cache.restoreCache(cachePaths, cacheKey, [
'action-setup-clojure-tools-'
])
}
function _getCacheDirectory(): string {
const cacheDirectory = process.env['RUNNER_TOOL_CACHE'] || ''
return cacheDirectory
}

View File

@ -7,6 +7,7 @@ import * as cljKondo from './clj-kondo'
import * as cljstyle from './cljstyle'
import * as zprint from './zprint'
import * as utils from './utils'
import {save, restore} from './cache'
export async function run(): Promise<void> {
try {
@ -83,3 +84,11 @@ export async function run(): Promise<void> {
core.setFailed(error)
}
}
export async function pre(): Promise<void> {
restore()
}
export async function post(): Promise<void> {
save()
}

View File

@ -0,0 +1,3 @@
import {post} from './entrypoint'
post()

3
src/pre-setup-clojure.ts Normal file
View File

@ -0,0 +1,3 @@
import {pre} from './entrypoint'
pre()