Skip to content

Commit

Permalink
Backup config.toml before workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
eifinger committed Mar 4, 2024
1 parent 720e7bf commit 3194c4e
Show file tree
Hide file tree
Showing 11 changed files with 103 additions and 78 deletions.
29 changes: 18 additions & 11 deletions dist/save-cache/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/save-cache/index.js.map

Large diffs are not rendered by default.

50 changes: 26 additions & 24 deletions dist/setup/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/setup/index.js.map

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions dist/update-checksums/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/update-checksums/index.js.map

Large diffs are not rendered by default.

12 changes: 1 addition & 11 deletions src/download/download-version.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as core from '@actions/core'
import * as tc from '@actions/tool-cache'
import * as io from '@actions/io'
import {
Architecture,
OWNER,
Expand All @@ -9,7 +8,6 @@ import {
toolsCacheName,
validateChecksum
} from '../utils'
import {ryeHomePath} from '../restore-cache'

export function tryGetFromCache(
arch: Architecture,
Expand All @@ -18,15 +16,7 @@ export function tryGetFromCache(
core.debug(`Trying to get Rye from cache for ${version}...`)
const cachedVersions = tc.findAllVersions(toolsCacheName, arch)
core.debug(`Cached versions: ${cachedVersions}`)
const foundPath = tc.find(toolsCacheName, version, arch)
if (foundPath) {
core.info(`Found Rye in cache for ${version}`)
io.cp(foundPath, ryeHomePath, {
copySourceDirectory: true,
recursive: true
})
return ryeHomePath
}
return tc.find(toolsCacheName, version, arch)
}

export async function downloadVersion(
Expand Down
4 changes: 1 addition & 3 deletions src/restore-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@ import * as glob from '@actions/glob'
import * as core from '@actions/core'
import {cp} from '@actions/io/'
import {exists} from '@actions/io/lib/io-util'
import {resolve} from 'path'
import {getArch} from './utils'

export const STATE_CACHE_KEY = 'cache-key'
export const STATE_CACHE_MATCHED_KEY = 'cache-matched-key'
export const workingDirInput = core.getInput('working-directory')
export const workingDir = workingDirInput ? `/${workingDirInput}` : ''
export const venvPath = `${process.env['GITHUB_WORKSPACE']}${workingDir}/.venv`
export const ryeHomePath = resolve(`${process.env['GITHUB_WORKSPACE']}/../.rye`)
const CACHE_VERSION = '4'
const CACHE_VERSION = '5'
const cacheLocalStoragePath =
`${core.getInput('cache-local-storage-path')}` || ''
const cacheDependencyPath = `${process.env['GITHUB_WORKSPACE']}${workingDir}/requirements**.lock`
Expand Down
26 changes: 19 additions & 7 deletions src/save-cache.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import * as cache from '@actions/cache'
import * as core from '@actions/core'
import {mkdirP, cp, rmRF} from '@actions/io/'
import * as io from '@actions/io/'
import * as fs from 'fs'
import {
STATE_CACHE_MATCHED_KEY,
STATE_CACHE_KEY,
venvPath,
ryeHomePath
venvPath
} from './restore-cache'
import {
RYE_CONFIG_TOML,
RYE_CONFIG_TOML_BACKUP,
STATE_TOOL_CACHED_PATH
} from './utils'

const enableCache = core.getInput('enable-cache') === 'true'
const cacheLocalStoragePath =
Expand All @@ -21,8 +26,15 @@ export async function run(): Promise<void> {
const err = error as Error
core.setFailed(err.message)
}
rmRF(ryeHomePath)
core.info(`Cleaned up RYE_HOME: ${ryeHomePath}`)
const cachedPath = core.getState(STATE_TOOL_CACHED_PATH)
await io.rmRF(`${cachedPath}/${RYE_CONFIG_TOML}`)
if (fs.existsSync(`${cachedPath}/${RYE_CONFIG_TOML}`)) {
await io.mv(
`${cachedPath}/${RYE_CONFIG_TOML_BACKUP}`,
`${cachedPath}/${RYE_CONFIG_TOML}`
)
core.info(`Restored ${cachedPath}/${RYE_CONFIG_TOML}`)
}
}

async function saveCache(): Promise<void> {
Expand All @@ -47,8 +59,8 @@ async function saveCache(): Promise<void> {

async function saveCacheLocal(cacheKey: string): Promise<void> {
const targetPath = `${cacheLocalStoragePath}/${cacheKey}`
await mkdirP(targetPath)
await cp(venvPath, `${targetPath}/.venv`, {
await io.mkdirP(targetPath)
await io.cp(venvPath, `${targetPath}/.venv`, {
recursive: true
})
}
Expand Down
Loading

0 comments on commit 3194c4e

Please sign in to comment.