Skip to content

Commit

Permalink
use .python-version to compute hashkey
Browse files Browse the repository at this point in the history
  • Loading branch information
eifinger committed Dec 21, 2023
1 parent 5b24b10 commit 4637d11
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 8 deletions.
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: 5 additions & 2 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 src/restore-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import * as glob from '@actions/glob'
import * as core from '@actions/core'

import {getLinuxInfo} from './utils'
import {promises as fs} from 'fs'

export const STATE_CACHE_PRIMARY_KEY = 'cache-primary-key'
export const CACHE_MATCHED_KEY = 'cache-matched-key'
const CACHE_DEPENDENCY_PATH = 'requirements**.lock'
const workingDir = `/${core.getInput('working-directory')}` || ''
const cachePath = `${process.env['GITHUB_WORKSPACE']}${workingDir}/.venv`
const cacheDependencyPath = `${process.env['GITHUB_WORKSPACE']}${workingDir}/${CACHE_DEPENDENCY_PATH}`
const pythonVersionFilePath = `${process.env['GITHUB_WORKSPACE']}${workingDir}/.python-version`

export async function restoreCache(
cachePrefix: string,
Expand Down Expand Up @@ -46,8 +48,9 @@ async function computeKeys(
let primaryKey = ''
let restoreKey = ''
const osInfo = await getLinuxInfo()
primaryKey = `${cachePrefix}-${process.env['RUNNER_OS']}-${osInfo.osVersion}-${osInfo.osName}-rye-${version}-${workingDir}-${hash}`
restoreKey = `${cachePrefix}-${process.env['RUNNER_OS']}-${osInfo.osVersion}-${osInfo.osName}-rye-${version}-${workingDir}`
const pyVersion = await fs.readFile(pythonVersionFilePath, 'utf8')
primaryKey = `${cachePrefix}-${process.env['RUNNER_OS']}-${osInfo.osVersion}-${osInfo.osName}-rye-${version}-${workingDir}-${pyVersion}-${hash}`
restoreKey = `${cachePrefix}-${process.env['RUNNER_OS']}-${osInfo.osVersion}-${osInfo.osName}-rye-${version}-${workingDir}-${pyVersion}`
return {primaryKey, restoreKey}
}

Expand Down

0 comments on commit 4637d11

Please sign in to comment.