reimplement github action in typescript
This commit is contained in:
29
src/cache.ts
Normal file
29
src/cache.ts
Normal file
@ -0,0 +1,29 @@
|
||||
import * as core from "@actions/core"
|
||||
import restore from "cache/lib/restore"
|
||||
import save from "cache/lib/save"
|
||||
|
||||
// TODO: ensure dir exists, have access, etc
|
||||
const getCacheDir = (): string => `${process.env.HOME}/.cache/golangci-lint`
|
||||
|
||||
const setCacheInputs = (): void => {
|
||||
process.env.INPUT_KEY = `golangci-lint.analysis-cache`
|
||||
process.env.INPUT_PATH = getCacheDir()
|
||||
}
|
||||
|
||||
export async function restoreCache(): Promise<void> {
|
||||
const startedAt = Date.now()
|
||||
setCacheInputs()
|
||||
|
||||
// Tell golangci-lint to use our cache directory.
|
||||
process.env.GOLANGCI_LINT_CACHE = getCacheDir()
|
||||
|
||||
await restore()
|
||||
core.info(`Restored golangci-lint analysis cache in ${Date.now() - startedAt}ms`)
|
||||
}
|
||||
|
||||
export async function saveCache(): Promise<void> {
|
||||
const startedAt = Date.now()
|
||||
setCacheInputs()
|
||||
await save()
|
||||
core.info(`Saved golangci-lint analysis cache in ${Date.now() - startedAt}ms`)
|
||||
}
|
Reference in New Issue
Block a user