added rtx_dir config (#215)

* added rtx_dir config

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip
This commit is contained in:
jdx 2023-12-14 08:38:00 -06:00 committed by GitHub
parent 5ac46849ac
commit 55e5d18e74
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 90 additions and 41 deletions

View file

@ -19,6 +19,10 @@ on:
- '**.md' - '**.md'
workflow_dispatch: workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref_name }}
cancel-in-progress: true
jobs: jobs:
check-dist: check-dist:
name: Check dist/ name: Check dist/

View file

@ -7,6 +7,10 @@ on:
- main - main
- 'releases/*' - 'releases/*'
concurrency:
group: ${{ github.workflow }}-${{ github.ref_name }}
cancel-in-progress: true
jobs: jobs:
test-typescript: test-typescript:
name: TypeScript Tests name: TypeScript Tests

View file

@ -10,6 +10,10 @@ on:
schedule: schedule:
- cron: '31 7 * * 3' - cron: '31 7 * * 3'
concurrency:
group: ${{ github.workflow }}-${{ github.ref_name }}
cancel-in-progress: true
jobs: jobs:
analyze: analyze:
name: Analyze name: Analyze

View file

@ -8,6 +8,10 @@ on:
branches-ignore: branches-ignore:
- main - main
concurrency:
group: ${{ github.workflow }}-${{ github.ref_name }}
cancel-in-progress: true
jobs: jobs:
lint: lint:
name: Lint Code Base name: Lint Code Base

View file

@ -7,6 +7,10 @@ on: # rebuild any PRs and main branch changes
- 'releases/*' - 'releases/*'
workflow_dispatch: workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref_name }}
cancel-in-progress: true
jobs: jobs:
build: # make sure build/ci work properly build: # make sure build/ci work properly
runs-on: ubuntu-latest runs-on: ubuntu-latest
@ -46,6 +50,8 @@ jobs:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: ./ - uses: ./
with: with:
cache_save: ${{ github.ref_name == 'main' }}
cache_key_prefix: rtx-v1
version: 2023.12.23 version: 2023.12.23
rtx_toml: | rtx_toml: |
[tools] [tools]

View file

@ -7,7 +7,13 @@ branding:
inputs: inputs:
version: version:
required: false 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: tool_versions:
required: false required: false
description: If present, this value will be written to the .tool-versions file description: If present, this value will be written to the .tool-versions file
@ -17,14 +23,26 @@ inputs:
install: install:
required: false required: false
default: "true" 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: cache:
required: false required: false
default: "true" 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: outputs:
cache-hit: 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: runs:
using: node20 using: node20
main: dist/index.js main: dist/index.js

34
dist/index.js generated vendored
View file

@ -82935,10 +82935,8 @@ async function run() {
await setRtxToml(); await setRtxToml();
if (core.getBooleanInput('cache')) { if (core.getBooleanInput('cache')) {
await restoreRTXCache(); await restoreRTXCache();
core.saveState('CACHE', false);
} }
else { else {
core.saveState('CACHE', true);
core.setOutput('cache-hit', false); core.setOutput('cache-hit', false);
} }
const version = core.getInput('version'); const version = core.getInput('version');
@ -82964,7 +82962,7 @@ async function setEnvVars() {
core.exportVariable(k, v); 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'); set('RTX_YES', '1');
const shimsDir = path.join((0, utils_1.rtxDir)(), 'shims'); const shimsDir = path.join((0, utils_1.rtxDir)(), 'shims');
core.info(`Adding ${shimsDir} to PATH`); core.info(`Adding ${shimsDir} to PATH`);
@ -82974,12 +82972,15 @@ async function restoreRTXCache() {
core.startGroup('Restoring rtx cache'); core.startGroup('Restoring rtx cache');
const cachePath = (0, utils_1.rtxDir)(); const cachePath = (0, utils_1.rtxDir)();
const fileHash = await glob.hashFiles(`**/.tool-versions\n**/.rtx.toml`); 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('PRIMARY_KEY', primaryKey);
core.saveState('RTX_DIR', cachePath);
const cacheKey = await cache.restoreCache([cachePath], primaryKey); const cacheKey = await cache.restoreCache([cachePath], primaryKey);
core.setOutput('cache-hit', Boolean(cacheKey)); core.setOutput('cache-hit', Boolean(cacheKey));
if (!cacheKey) { if (!cacheKey) {
core.info(`rtx cache not found for ${getOS()}-${os.arch()} tool versions`); core.info(`rtx cache not found for ${primaryKey}`);
return; return;
} }
core.saveState('CACHE_KEY', cacheKey); core.saveState('CACHE_KEY', cacheKey);
@ -83021,8 +83022,12 @@ function getOS() {
return process.platform; return process.platform;
} }
} }
const testRTX = async () => core.group('Running rtx --version', async () => exec.exec('rtx', ['--version'])); const testRTX = async () => rtx(['--version']);
const rtxInstall = async () => core.group('Running rtx --version', async () => exec.exec('rtx', ['install'])); 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 () => { const writeFile = async (p, body) => core.group(`Writing ${p}`, async () => {
core.info(`Body:\n${body}`); core.info(`Body:\n${body}`);
await fs.promises.writeFile(p, body, { encoding: 'utf8' }); 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 })); Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.rtxDir = void 0; exports.rtxDir = void 0;
const core = __importStar(__nccwpck_require__(2186));
const os = __importStar(__nccwpck_require__(2037)); const os = __importStar(__nccwpck_require__(2037));
const path = __importStar(__nccwpck_require__(1017)); const path = __importStar(__nccwpck_require__(1017));
function rtxDir() { function rtxDir() {
if (process.env.RTX_DATA_HOME) { const dir = core.getState('RTX_DIR');
return process.env.RTX_DATA_HOME; if (dir)
} return dir;
if (process.env.XDG_DATA_HOME) { const { RTX_DATA_DIR, XDG_DATA_HOME } = process.env;
return path.join(process.env.XDG_DATA_HOME, 'rtx'); 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'); return path.join(os.homedir(), '.local/share/rtx');
} }
exports.rtxDir = rtxDir; exports.rtxDir = rtxDir;

View file

@ -13,9 +13,7 @@ export async function run(): Promise<void> {
} }
async function cacheRTXTools(): Promise<void> { async function cacheRTXTools(): Promise<void> {
const skipCache = core.getState('CACHE') if (!core.getState('CACHE')) {
if (skipCache) {
core.info('Skipping saving cache') core.info('Skipping saving cache')
return return
} }
@ -29,16 +27,14 @@ async function cacheRTXTools(): Promise<void> {
} }
if (primaryKey === state) { if (primaryKey === state) {
core.info( core.info(`Cache hit occurred on key ${primaryKey}, not saving cache.`)
`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`
)
return return
} }
const cacheId = await cache.saveCache([cachePath], primaryKey) const cacheId = await cache.saveCache([cachePath], primaryKey)
if (cacheId === -1) return if (cacheId === -1) return
core.info(`Cache saved with the primary key: ${primaryKey}`) core.info(`Cache saved from ${cachePath} with key: ${primaryKey}`)
} }
run() run()

View file

@ -14,9 +14,7 @@ async function run(): Promise<void> {
if (core.getBooleanInput('cache')) { if (core.getBooleanInput('cache')) {
await restoreRTXCache() await restoreRTXCache()
core.saveState('CACHE', false)
} else { } else {
core.saveState('CACHE', true)
core.setOutput('cache-hit', false) core.setOutput('cache-hit', false)
} }
@ -41,7 +39,7 @@ async function setEnvVars(): Promise<void> {
core.exportVariable(k, v) 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') set('RTX_YES', '1')
const shimsDir = path.join(rtxDir(), 'shims') const shimsDir = path.join(rtxDir(), 'shims')
@ -53,15 +51,18 @@ async function restoreRTXCache(): Promise<void> {
core.startGroup('Restoring rtx cache') core.startGroup('Restoring rtx cache')
const cachePath = rtxDir() const cachePath = rtxDir()
const fileHash = await glob.hashFiles(`**/.tool-versions\n**/.rtx.toml`) 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('PRIMARY_KEY', primaryKey)
core.saveState('RTX_DIR', cachePath)
const cacheKey = await cache.restoreCache([cachePath], primaryKey) const cacheKey = await cache.restoreCache([cachePath], primaryKey)
core.setOutput('cache-hit', Boolean(cacheKey)) core.setOutput('cache-hit', Boolean(cacheKey))
if (!cacheKey) { if (!cacheKey) {
core.info(`rtx cache not found for ${getOS()}-${os.arch()} tool versions`) core.info(`rtx cache not found for ${primaryKey}`)
return return
} }
@ -109,12 +110,14 @@ function getOS(): string {
} }
} }
const testRTX = async (): Promise<number> => const testRTX = async (): Promise<number> => rtx(['--version'])
core.group('Running rtx --version', async () => const rtxInstall = async (): Promise<number> => rtx(['install'])
exec.exec('rtx', ['--version']) const rtx = async (args: string[]): Promise<number> =>
) core.group(`Running rtx ${args.join(' ')}`, async () => {
const rtxInstall = async (): Promise<number> => const cwd = core.getInput('install_dir') || process.cwd()
core.group('Running rtx --version', async () => exec.exec('rtx', ['install'])) return exec.exec('rtx', args, { cwd })
})
const writeFile = async (p: fs.PathLike, body: string): Promise<void> => const writeFile = async (p: fs.PathLike, body: string): Promise<void> =>
core.group(`Writing ${p}`, async () => { core.group(`Writing ${p}`, async () => {
core.info(`Body:\n${body}`) core.info(`Body:\n${body}`)

View file

@ -1,12 +1,14 @@
import * as core from '@actions/core'
import * as os from 'os' import * as os from 'os'
import * as path from 'path' import * as path from 'path'
export function rtxDir(): string { export function rtxDir(): string {
if (process.env.RTX_DATA_HOME) { const dir = core.getState('RTX_DIR')
return process.env.RTX_DATA_HOME if (dir) return dir
}
if (process.env.XDG_DATA_HOME) { const { RTX_DATA_DIR, XDG_DATA_HOME } = process.env
return path.join(process.env.XDG_DATA_HOME, 'rtx') 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') return path.join(os.homedir(), '.local/share/rtx')
} }