Skip to content

Commit

Permalink
Move RYE_HOME from workspace home to runner home (#194)
Browse files Browse the repository at this point in the history
Having it "suddenly appear" in the repo root confused some tools like `rye fmt`. We assume that the directory that gets created for the current workflow run is a stable path between workflow runs. If several repositories get checked out or some logic interacts on the workspace level this might lead to unintented behaviour. If this turns out to be a real issue we have to look into using TMPDIR and try to create stable paths there.

Several runs of the same repository on the same runner might run with different options. These must not interfere and thus the `.rye` folder must not be left over after the run. The only way to ensure that is to always run the `post` step of the action. Since there is (currently) no way to determine if the workflow succeeded or failed when the `post` step is started (it is possible to run or not run it) we will always save the cache. Since we are only caching `.rye` and `.venv` there should be no errors because of this.

Breaking: The cache will always be saved, even if the workflow failed.
  • Loading branch information
eifinger authored Mar 3, 2024
1 parent ad84597 commit 9dddc34
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 12 deletions.
1 change: 0 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ runs:
using: 'node20'
main: 'dist/setup/index.js'
post: 'dist/save-cache/index.js'
post-if: success()
branding:
icon: 'package'
color: 'blue'
7 changes: 5 additions & 2 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.

7 changes: 4 additions & 3 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.

5 changes: 3 additions & 2 deletions src/restore-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ 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 = `${process.env['GITHUB_WORKSPACE']}${workingDir}/.rye`
const CACHE_VERSION = '2'
export const ryeHomePath = resolve(`${process.env['GITHUB_WORKSPACE']}/../.rye`)
const CACHE_VERSION = '3'
const cacheLocalStoragePath =
`${core.getInput('cache-local-storage-path')}` || ''
const cacheDependencyPath = `${process.env['GITHUB_WORKSPACE']}${workingDir}/requirements**.lock`
Expand Down
4 changes: 3 additions & 1 deletion src/save-cache.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as cache from '@actions/cache'
import * as core from '@actions/core'
import {mkdirP, cp} from '@actions/io/'
import {mkdirP, cp, rmRF} from '@actions/io/'
import {
STATE_CACHE_MATCHED_KEY,
STATE_CACHE_KEY,
Expand All @@ -21,6 +21,8 @@ export async function run(): Promise<void> {
const err = error as Error
core.setFailed(err.message)
}
rmRF(ryeHomePath)
core.info(`Cleaned up RYE_HOME: ${ryeHomePath}`)
}

async function saveCache(): Promise<void> {
Expand Down
2 changes: 1 addition & 1 deletion src/setup-rye.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ async function run(): Promise<void> {
await restoreCache(cachePrefix, version)
}
core.exportVariable('RYE_HOME', ryeHomePath)
core.debug(`Set RYE_HOME to ${ryeHomePath}`)
core.info(`Set RYE_HOME to ${ryeHomePath}`)
} catch (err) {
core.setFailed((err as Error).message)
}
Expand Down

0 comments on commit 9dddc34

Please sign in to comment.