diff --git a/.github/workflows/check-dist.yml b/.github/workflows/check-dist.yml index 4d7f663..c372c53 100644 --- a/.github/workflows/check-dist.yml +++ b/.github/workflows/check-dist.yml @@ -19,6 +19,10 @@ on: - '**.md' workflow_dispatch: +concurrency: + group: ${{ github.workflow }}-${{ github.ref_name }} + cancel-in-progress: true + jobs: check-dist: name: Check dist/ diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 715e547..4c135c5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,6 +7,10 @@ on: - main - 'releases/*' +concurrency: + group: ${{ github.workflow }}-${{ github.ref_name }} + cancel-in-progress: true + jobs: test-typescript: name: TypeScript Tests diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index bcaf277..5ed8717 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -10,6 +10,10 @@ on: schedule: - cron: '31 7 * * 3' +concurrency: + group: ${{ github.workflow }}-${{ github.ref_name }} + cancel-in-progress: true + jobs: analyze: name: Analyze diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 5b0eca1..8c7c0b9 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -8,6 +8,10 @@ on: branches-ignore: - main +concurrency: + group: ${{ github.workflow }}-${{ github.ref_name }} + cancel-in-progress: true + jobs: lint: name: Lint Code Base diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 656f14d..57c3273 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -7,6 +7,10 @@ on: # rebuild any PRs and main branch changes - 'releases/*' workflow_dispatch: +concurrency: + group: ${{ github.workflow }}-${{ github.ref_name }} + cancel-in-progress: true + jobs: build: # make sure build/ci work properly runs-on: ubuntu-latest @@ -46,6 +50,8 @@ jobs: - uses: actions/checkout@v4 - uses: ./ with: + cache_save: ${{ github.ref_name == 'main' }} + cache_key_prefix: rtx-v1 version: 2023.12.23 rtx_toml: | [tools] diff --git a/action.yml b/action.yml index 87d3e41..d968b04 100644 --- a/action.yml +++ b/action.yml @@ -7,7 +7,13 @@ branding: inputs: version: required: false - description: 'The version of rtx to use. If not specified, will use the latest release.' + description: The version of rtx to use. If not specified, will use the latest release. + rtx_dir: + required: false + description: | + The directory that rtx will be installed to, defaults to $HOME/.local/share/rtx + Or $XDG_DATA_HOME/rtx if $XDG_DATA_HOME is set. + Or $RTX_DATA_DIR if $RTX_DATA_DIR is set. tool_versions: required: false description: If present, this value will be written to the .tool-versions file @@ -17,14 +23,26 @@ inputs: install: required: false default: "true" - description: 'if false, will not run `rtx install`' + description: if false, will not run `rtx install` + install_dir: + required: false + default: "." + description: The directory that `rtx install` will be executed in cache: required: false default: "true" - description: 'if false, action will not automatically cache' + description: if false, action will not read or write to cache + cache_save: + required: false + default: "true" + description: if false, action will not write to cache + cache_key_prefix: + required: false + default: "rtx-v0" + description: The prefix key to use for the cache, change this to invalidate the cache outputs: cache-hit: - description: 'A boolean value to indicate if a cache was hit.' + description: A boolean value to indicate if a cache was hit. runs: using: node20 main: dist/index.js diff --git a/dist/index.js b/dist/index.js index aa192a1..7b23719 100644 --- a/dist/index.js +++ b/dist/index.js @@ -82935,10 +82935,8 @@ async function run() { await setRtxToml(); if (core.getBooleanInput('cache')) { await restoreRTXCache(); - core.saveState('CACHE', false); } else { - core.saveState('CACHE', true); core.setOutput('cache-hit', false); } const version = core.getInput('version'); @@ -82964,7 +82962,7 @@ async function setEnvVars() { core.exportVariable(k, v); } }; - set('RTX_TRUSTED_CONFIG_PATHS', path.join(process.cwd(), '.rtx.toml')); + set('RTX_TRUSTED_CONFIG_PATHS', process.cwd()); set('RTX_YES', '1'); const shimsDir = path.join((0, utils_1.rtxDir)(), 'shims'); core.info(`Adding ${shimsDir} to PATH`); @@ -82974,12 +82972,15 @@ async function restoreRTXCache() { core.startGroup('Restoring rtx cache'); const cachePath = (0, utils_1.rtxDir)(); const fileHash = await glob.hashFiles(`**/.tool-versions\n**/.rtx.toml`); - const primaryKey = `rtx-tools-${getOS()}-${os.arch()}-${fileHash}`; + const prefix = core.getInput('cache_key_prefix') || 'rtx-v0'; + const primaryKey = `${prefix}-${getOS()}-${os.arch()}-${fileHash}`; + core.saveState('CACHE', core.getBooleanInput('cache_save') ?? true); core.saveState('PRIMARY_KEY', primaryKey); + core.saveState('RTX_DIR', cachePath); const cacheKey = await cache.restoreCache([cachePath], primaryKey); core.setOutput('cache-hit', Boolean(cacheKey)); if (!cacheKey) { - core.info(`rtx cache not found for ${getOS()}-${os.arch()} tool versions`); + core.info(`rtx cache not found for ${primaryKey}`); return; } core.saveState('CACHE_KEY', cacheKey); @@ -83021,8 +83022,12 @@ function getOS() { return process.platform; } } -const testRTX = async () => core.group('Running rtx --version', async () => exec.exec('rtx', ['--version'])); -const rtxInstall = async () => core.group('Running rtx --version', async () => exec.exec('rtx', ['install'])); +const testRTX = async () => rtx(['--version']); +const rtxInstall = async () => rtx(['install']); +const rtx = async (args) => core.group(`Running rtx ${args.join(' ')}`, async () => { + const cwd = core.getInput('install_dir') || process.cwd(); + return exec.exec('rtx', args, { cwd }); +}); const writeFile = async (p, body) => core.group(`Writing ${p}`, async () => { core.info(`Body:\n${body}`); await fs.promises.writeFile(p, body, { encoding: 'utf8' }); @@ -83062,15 +83067,18 @@ var __importStar = (this && this.__importStar) || function (mod) { }; Object.defineProperty(exports, "__esModule", ({ value: true })); exports.rtxDir = void 0; +const core = __importStar(__nccwpck_require__(2186)); const os = __importStar(__nccwpck_require__(2037)); const path = __importStar(__nccwpck_require__(1017)); function rtxDir() { - if (process.env.RTX_DATA_HOME) { - return process.env.RTX_DATA_HOME; - } - if (process.env.XDG_DATA_HOME) { - return path.join(process.env.XDG_DATA_HOME, 'rtx'); - } + const dir = core.getState('RTX_DIR'); + if (dir) + return dir; + const { RTX_DATA_DIR, XDG_DATA_HOME } = process.env; + if (RTX_DATA_DIR) + return RTX_DATA_DIR; + if (XDG_DATA_HOME) + return path.join(XDG_DATA_HOME, 'rtx'); return path.join(os.homedir(), '.local/share/rtx'); } exports.rtxDir = rtxDir; diff --git a/src/cache-save.ts b/src/cache-save.ts index 5674613..5758273 100644 --- a/src/cache-save.ts +++ b/src/cache-save.ts @@ -13,9 +13,7 @@ export async function run(): Promise { } async function cacheRTXTools(): Promise { - const skipCache = core.getState('CACHE') - - if (skipCache) { + if (!core.getState('CACHE')) { core.info('Skipping saving cache') return } @@ -29,16 +27,14 @@ async function cacheRTXTools(): Promise { } if (primaryKey === state) { - core.info( - `Cache hit occurred on the primary key ${primaryKey}, not saving cache.` - ) + core.info(`Cache hit occurred on key ${primaryKey}, not saving cache.`) return } const cacheId = await cache.saveCache([cachePath], primaryKey) if (cacheId === -1) return - core.info(`Cache saved with the primary key: ${primaryKey}`) + core.info(`Cache saved from ${cachePath} with key: ${primaryKey}`) } run() diff --git a/src/index.ts b/src/index.ts index 94e5dec..6568f96 100644 --- a/src/index.ts +++ b/src/index.ts @@ -14,9 +14,7 @@ async function run(): Promise { if (core.getBooleanInput('cache')) { await restoreRTXCache() - core.saveState('CACHE', false) } else { - core.saveState('CACHE', true) core.setOutput('cache-hit', false) } @@ -41,7 +39,7 @@ async function setEnvVars(): Promise { core.exportVariable(k, v) } } - set('RTX_TRUSTED_CONFIG_PATHS', path.join(process.cwd(), '.rtx.toml')) + set('RTX_TRUSTED_CONFIG_PATHS', process.cwd()) set('RTX_YES', '1') const shimsDir = path.join(rtxDir(), 'shims') @@ -53,15 +51,18 @@ async function restoreRTXCache(): Promise { core.startGroup('Restoring rtx cache') const cachePath = rtxDir() const fileHash = await glob.hashFiles(`**/.tool-versions\n**/.rtx.toml`) - const primaryKey = `rtx-tools-${getOS()}-${os.arch()}-${fileHash}` + const prefix = core.getInput('cache_key_prefix') || 'rtx-v0' + const primaryKey = `${prefix}-${getOS()}-${os.arch()}-${fileHash}` + core.saveState('CACHE', core.getBooleanInput('cache_save') ?? true) core.saveState('PRIMARY_KEY', primaryKey) + core.saveState('RTX_DIR', cachePath) const cacheKey = await cache.restoreCache([cachePath], primaryKey) core.setOutput('cache-hit', Boolean(cacheKey)) if (!cacheKey) { - core.info(`rtx cache not found for ${getOS()}-${os.arch()} tool versions`) + core.info(`rtx cache not found for ${primaryKey}`) return } @@ -109,12 +110,14 @@ function getOS(): string { } } -const testRTX = async (): Promise => - core.group('Running rtx --version', async () => - exec.exec('rtx', ['--version']) - ) -const rtxInstall = async (): Promise => - core.group('Running rtx --version', async () => exec.exec('rtx', ['install'])) +const testRTX = async (): Promise => rtx(['--version']) +const rtxInstall = async (): Promise => rtx(['install']) +const rtx = async (args: string[]): Promise => + core.group(`Running rtx ${args.join(' ')}`, async () => { + const cwd = core.getInput('install_dir') || process.cwd() + return exec.exec('rtx', args, { cwd }) + }) + const writeFile = async (p: fs.PathLike, body: string): Promise => core.group(`Writing ${p}`, async () => { core.info(`Body:\n${body}`) diff --git a/src/utils.ts b/src/utils.ts index 86ed87e..f690da2 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,12 +1,14 @@ +import * as core from '@actions/core' import * as os from 'os' import * as path from 'path' export function rtxDir(): string { - if (process.env.RTX_DATA_HOME) { - return process.env.RTX_DATA_HOME - } - if (process.env.XDG_DATA_HOME) { - return path.join(process.env.XDG_DATA_HOME, 'rtx') - } + const dir = core.getState('RTX_DIR') + if (dir) return dir + + const { RTX_DATA_DIR, XDG_DATA_HOME } = process.env + if (RTX_DATA_DIR) return RTX_DATA_DIR + if (XDG_DATA_HOME) return path.join(XDG_DATA_HOME, 'rtx') + return path.join(os.homedir(), '.local/share/rtx') }