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'
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref_name }}
cancel-in-progress: true
jobs:
check-dist:
name: Check dist/

View file

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

View file

@ -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

View file

@ -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

View file

@ -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]

View file

@ -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

34
dist/index.js generated vendored
View file

@ -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;

View file

@ -13,9 +13,7 @@ export async function run(): Promise<void> {
}
async function cacheRTXTools(): Promise<void> {
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<void> {
}
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()

View file

@ -14,9 +14,7 @@ async function run(): Promise<void> {
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<void> {
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<void> {
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<number> =>
core.group('Running rtx --version', async () =>
exec.exec('rtx', ['--version'])
)
const rtxInstall = async (): Promise<number> =>
core.group('Running rtx --version', async () => exec.exec('rtx', ['install']))
const testRTX = async (): Promise<number> => rtx(['--version'])
const rtxInstall = async (): Promise<number> => rtx(['install'])
const rtx = async (args: string[]): Promise<number> =>
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<void> =>
core.group(`Writing ${p}`, async () => {
core.info(`Body:\n${body}`)

View file

@ -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')
}