added rtx_toml support (#214)

* added rtx_toml support

Fixes #47

* refactor

* refactor

* bump

* bump

* bump
This commit is contained in:
jdx 2023-12-14 07:56:58 -06:00 committed by GitHub
parent a545a9b90a
commit 5ac46849ac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 258 additions and 235 deletions

View file

@ -24,7 +24,7 @@
"@typescript-eslint/func-call-spacing": ["error", "never"],
"@typescript-eslint/no-array-constructor": "error",
"@typescript-eslint/no-empty-interface": "error",
"@typescript-eslint/no-explicit-any": "error",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-extraneous-class": "error",
"@typescript-eslint/no-for-in-array": "error",
"@typescript-eslint/no-inferrable-types": "error",
@ -52,4 +52,4 @@
"es6": true,
"jest/globals": true
}
}
}

View file

@ -47,3 +47,8 @@ jobs:
- uses: ./
with:
version: 2023.12.23
rtx_toml: |
[tools]
bun = "1"
- run: which bun
- run: bun -v

View file

@ -19,8 +19,13 @@ jobs:
version: 2023.12.0 # [default: latest] rtx version to install
install: true # [default: true] run `rtx install`
cache: true # [default: true] cache rtx using GitHub's cache
# automatically write this .tool-versions file
tool_versions: |
shellcheck 0.9.0
# or, if you prefer .rtx.toml format:
rtx_toml: |
[tools]
shellcheck = "0.9.0"
- run: shellcheck scripts/*.sh
test:
runs-on: ubuntu-latest

View file

@ -11,6 +11,9 @@ inputs:
tool_versions:
required: false
description: If present, this value will be written to the .tool-versions file
rtx_toml:
required: false
description: If present, this value will be written to the .rtx.toml file
install:
required: false
default: "true"

126
dist/index.js generated vendored
View file

@ -82892,7 +82892,7 @@ module.exports.implForWrapper = function (wrapper) {
/***/ }),
/***/ 399:
/***/ 6144:
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
"use strict";
@ -82921,7 +82921,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
return result;
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.run = void 0;
const cache = __importStar(__nccwpck_require__(7799));
const core = __importStar(__nccwpck_require__(2186));
const exec = __importStar(__nccwpck_require__(1514));
@ -82931,35 +82930,48 @@ const os = __importStar(__nccwpck_require__(2037));
const path = __importStar(__nccwpck_require__(1017));
const utils_1 = __nccwpck_require__(1314);
async function run() {
await setToolVersions();
if (core.getBooleanInput('cache')) {
await restoreRTXCache();
core.saveState('CACHE', false);
try {
await setToolVersions();
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');
await setupRTX(version);
await setEnvVars();
await testRTX();
if (core.getBooleanInput('install')) {
await rtxInstall();
}
}
else {
core.saveState('CACHE', true);
core.setOutput('cache-hit', false);
catch (err) {
if (err instanceof Error)
core.setFailed(err.message);
else
throw err;
}
const version = core.getInput('version');
await setupRTX(version);
await setEnvVars();
await exec.exec('rtx', ['--version']);
const install = core.getBooleanInput('install', { required: false });
if (install) {
await exec.exec('rtx', ['install']);
}
await setPaths();
}
exports.run = run;
async function setEnvVars() {
if (!process.env['RTX_TRUSTED_CONFIG_PATHS']) {
core.exportVariable('RTX_TRUSTED_CONFIG_PATHS', path.join(process.cwd(), '.rtx.toml'));
}
if (!process.env['RTX_YES']) {
core.exportVariable('RTX_YES', '1');
}
core.startGroup('Setting env vars');
const set = (k, v) => {
if (!process.env[k]) {
core.info(`Setting ${k}=${v}`);
core.exportVariable(k, v);
}
};
set('RTX_TRUSTED_CONFIG_PATHS', path.join(process.cwd(), '.rtx.toml'));
set('RTX_YES', '1');
const shimsDir = path.join((0, utils_1.rtxDir)(), 'shims');
core.info(`Adding ${shimsDir} to PATH`);
core.addPath(shimsDir);
}
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}`;
@ -82974,25 +82986,32 @@ async function restoreRTXCache() {
core.info(`rtx cache restored from key: ${cacheKey}`);
}
async function setupRTX(version) {
core.startGroup(version ? `Setup rtx@${version}` : 'Setup rtx');
const rtxBinDir = path.join((0, utils_1.rtxDir)(), 'bin');
const url = version
? `https://rtx.jdx.dev/v${version}/rtx-v${version}-${getOS()}-${os.arch()}`
: `https://rtx.jdx.dev/rtx-latest-${getOS()}-${os.arch()}`;
await fs.promises.mkdir(rtxBinDir, { recursive: true });
await exec.exec('curl', [url, '--output', path.join(rtxBinDir, 'rtx')]);
await exec.exec('curl', [
'-fsSL',
url,
'--output',
path.join(rtxBinDir, 'rtx')
]);
await exec.exec('chmod', ['+x', path.join(rtxBinDir, 'rtx')]);
core.addPath(rtxBinDir);
}
// returns true if tool_versions was set
async function setToolVersions() {
const toolVersions = core.getInput('tool_versions', { required: false });
const toolVersions = core.getInput('tool_versions');
if (toolVersions) {
await fs.promises.writeFile('.tool-versions', toolVersions, {
encoding: 'utf8'
});
return true;
await writeFile('.tool-versions', toolVersions);
}
}
async function setRtxToml() {
const toml = core.getInput('rtx_toml');
if (toml) {
await writeFile('.rtx.toml', toml);
}
return false;
}
function getOS() {
switch (process.platform) {
@ -83002,16 +83021,13 @@ function getOS() {
return process.platform;
}
}
async function setPaths() {
for (const binPath of await getBinPaths()) {
core.addPath(binPath);
}
}
async function getBinPaths() {
const output = await exec.getExecOutput('rtx', ['bin-paths']);
return output.stdout.split('\n');
}
if (false) {}
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 writeFile = async (p, body) => core.group(`Writing ${p}`, async () => {
core.info(`Body:\n${body}`);
await fs.promises.writeFile(p, body, { encoding: 'utf8' });
});
run();
/***/ }),
@ -83372,22 +83388,12 @@ module.exports = JSON.parse('[[[0,44],"disallowed_STD3_valid"],[[45,46],"valid"]
/******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/";
/******/
/************************************************************************/
var __webpack_exports__ = {};
// This entry need to be wrapped in an IIFE because it need to be in strict mode.
(() => {
"use strict";
var exports = __webpack_exports__;
Object.defineProperty(exports, "__esModule", ({ value: true }));
/**
* The entrypoint for the action.
*/
const main_1 = __nccwpck_require__(399);
// eslint-disable-next-line @typescript-eslint/no-floating-promises
(0, main_1.run)();
})();
module.exports = __webpack_exports__;
/******/
/******/ // startup
/******/ // Load entry module and return exports
/******/ // This entry module is referenced by other modules so it can't be inlined
/******/ var __webpack_exports__ = __nccwpck_require__(6144);
/******/ module.exports = __webpack_exports__;
/******/
/******/ })()
;

97
package-lock.json generated
View file

@ -16,13 +16,13 @@
},
"devDependencies": {
"@types/node": "^20.10.4",
"@typescript-eslint/eslint-plugin": "^6.13.2",
"@typescript-eslint/parser": "^6.13.2",
"@typescript-eslint/eslint-plugin": "^6.14.0",
"@typescript-eslint/parser": "^6.14.0",
"@vercel/ncc": "^0.38.1",
"eslint": "^8.55.0",
"eslint-plugin-github": "^4.10.1",
"eslint-plugin-jest": "^27.6.0",
"eslint-plugin-jsonc": "^2.10.0",
"eslint-plugin-jsonc": "^2.11.1",
"eslint-plugin-prettier": "^5.0.1",
"husky": "^8.0.3",
"jest": "^29.7.0",
@ -1722,16 +1722,16 @@
"dev": true
},
"node_modules/@typescript-eslint/eslint-plugin": {
"version": "6.13.2",
"resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-6.13.2.tgz",
"integrity": "sha512-3+9OGAWHhk4O1LlcwLBONbdXsAhLjyCFogJY/cWy2lxdVJ2JrcTF2pTGMaLl2AE7U1l31n8Py4a8bx5DLf/0dQ==",
"version": "6.14.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-6.14.0.tgz",
"integrity": "sha512-1ZJBykBCXaSHG94vMMKmiHoL0MhNHKSVlcHVYZNw+BKxufhqQVTOawNpwwI1P5nIFZ/4jLVop0mcY6mJJDFNaw==",
"dev": true,
"dependencies": {
"@eslint-community/regexpp": "^4.5.1",
"@typescript-eslint/scope-manager": "6.13.2",
"@typescript-eslint/type-utils": "6.13.2",
"@typescript-eslint/utils": "6.13.2",
"@typescript-eslint/visitor-keys": "6.13.2",
"@typescript-eslint/scope-manager": "6.14.0",
"@typescript-eslint/type-utils": "6.14.0",
"@typescript-eslint/utils": "6.14.0",
"@typescript-eslint/visitor-keys": "6.14.0",
"debug": "^4.3.4",
"graphemer": "^1.4.0",
"ignore": "^5.2.4",
@ -1790,15 +1790,15 @@
"dev": true
},
"node_modules/@typescript-eslint/parser": {
"version": "6.13.2",
"resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-6.13.2.tgz",
"integrity": "sha512-MUkcC+7Wt/QOGeVlM8aGGJZy1XV5YKjTpq9jK6r6/iLsGXhBVaGP5N0UYvFsu9BFlSpwY9kMretzdBH01rkRXg==",
"version": "6.14.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-6.14.0.tgz",
"integrity": "sha512-QjToC14CKacd4Pa7JK4GeB/vHmWFJckec49FR4hmIRf97+KXole0T97xxu9IFiPxVQ1DBWrQ5wreLwAGwWAVQA==",
"dev": true,
"dependencies": {
"@typescript-eslint/scope-manager": "6.13.2",
"@typescript-eslint/types": "6.13.2",
"@typescript-eslint/typescript-estree": "6.13.2",
"@typescript-eslint/visitor-keys": "6.13.2",
"@typescript-eslint/scope-manager": "6.14.0",
"@typescript-eslint/types": "6.14.0",
"@typescript-eslint/typescript-estree": "6.14.0",
"@typescript-eslint/visitor-keys": "6.14.0",
"debug": "^4.3.4"
},
"engines": {
@ -1818,13 +1818,13 @@
}
},
"node_modules/@typescript-eslint/scope-manager": {
"version": "6.13.2",
"resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-6.13.2.tgz",
"integrity": "sha512-CXQA0xo7z6x13FeDYCgBkjWzNqzBn8RXaE3QVQVIUm74fWJLkJkaHmHdKStrxQllGh6Q4eUGyNpMe0b1hMkXFA==",
"version": "6.14.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-6.14.0.tgz",
"integrity": "sha512-VT7CFWHbZipPncAZtuALr9y3EuzY1b1t1AEkIq2bTXUPKw+pHoXflGNG5L+Gv6nKul1cz1VH8fz16IThIU0tdg==",
"dev": true,
"dependencies": {
"@typescript-eslint/types": "6.13.2",
"@typescript-eslint/visitor-keys": "6.13.2"
"@typescript-eslint/types": "6.14.0",
"@typescript-eslint/visitor-keys": "6.14.0"
},
"engines": {
"node": "^16.0.0 || >=18.0.0"
@ -1835,13 +1835,13 @@
}
},
"node_modules/@typescript-eslint/type-utils": {
"version": "6.13.2",
"resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-6.13.2.tgz",
"integrity": "sha512-Qr6ssS1GFongzH2qfnWKkAQmMUyZSyOr0W54nZNU1MDfo+U4Mv3XveeLZzadc/yq8iYhQZHYT+eoXJqnACM1tw==",
"version": "6.14.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-6.14.0.tgz",
"integrity": "sha512-x6OC9Q7HfYKqjnuNu5a7kffIYs3No30isapRBJl1iCHLitD8O0lFbRcVGiOcuyN837fqXzPZ1NS10maQzZMKqw==",
"dev": true,
"dependencies": {
"@typescript-eslint/typescript-estree": "6.13.2",
"@typescript-eslint/utils": "6.13.2",
"@typescript-eslint/typescript-estree": "6.14.0",
"@typescript-eslint/utils": "6.14.0",
"debug": "^4.3.4",
"ts-api-utils": "^1.0.1"
},
@ -1862,9 +1862,9 @@
}
},
"node_modules/@typescript-eslint/types": {
"version": "6.13.2",
"resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-6.13.2.tgz",
"integrity": "sha512-7sxbQ+EMRubQc3wTfTsycgYpSujyVbI1xw+3UMRUcrhSy+pN09y/lWzeKDbvhoqcRbHdc+APLs/PWYi/cisLPg==",
"version": "6.14.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-6.14.0.tgz",
"integrity": "sha512-uty9H2K4Xs8E47z3SnXEPRNDfsis8JO27amp2GNCnzGETEW3yTqEIVg5+AI7U276oGF/tw6ZA+UesxeQ104ceA==",
"dev": true,
"engines": {
"node": "^16.0.0 || >=18.0.0"
@ -1875,13 +1875,13 @@
}
},
"node_modules/@typescript-eslint/typescript-estree": {
"version": "6.13.2",
"resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-6.13.2.tgz",
"integrity": "sha512-SuD8YLQv6WHnOEtKv8D6HZUzOub855cfPnPMKvdM/Bh1plv1f7Q/0iFUDLKKlxHcEstQnaUU4QZskgQq74t+3w==",
"version": "6.14.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-6.14.0.tgz",
"integrity": "sha512-yPkaLwK0yH2mZKFE/bXkPAkkFgOv15GJAUzgUVonAbv0Hr4PK/N2yaA/4XQbTZQdygiDkpt5DkxPELqHguNvyw==",
"dev": true,
"dependencies": {
"@typescript-eslint/types": "6.13.2",
"@typescript-eslint/visitor-keys": "6.13.2",
"@typescript-eslint/types": "6.14.0",
"@typescript-eslint/visitor-keys": "6.14.0",
"debug": "^4.3.4",
"globby": "^11.1.0",
"is-glob": "^4.0.3",
@ -1935,17 +1935,17 @@
"dev": true
},
"node_modules/@typescript-eslint/utils": {
"version": "6.13.2",
"resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-6.13.2.tgz",
"integrity": "sha512-b9Ptq4eAZUym4idijCRzl61oPCwwREcfDI8xGk751Vhzig5fFZR9CyzDz4Sp/nxSLBYxUPyh4QdIDqWykFhNmQ==",
"version": "6.14.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-6.14.0.tgz",
"integrity": "sha512-XwRTnbvRr7Ey9a1NT6jqdKX8y/atWG+8fAIu3z73HSP8h06i3r/ClMhmaF/RGWGW1tHJEwij1uEg2GbEmPYvYg==",
"dev": true,
"dependencies": {
"@eslint-community/eslint-utils": "^4.4.0",
"@types/json-schema": "^7.0.12",
"@types/semver": "^7.5.0",
"@typescript-eslint/scope-manager": "6.13.2",
"@typescript-eslint/types": "6.13.2",
"@typescript-eslint/typescript-estree": "6.13.2",
"@typescript-eslint/scope-manager": "6.14.0",
"@typescript-eslint/types": "6.14.0",
"@typescript-eslint/typescript-estree": "6.14.0",
"semver": "^7.5.4"
},
"engines": {
@ -1993,12 +1993,12 @@
"dev": true
},
"node_modules/@typescript-eslint/visitor-keys": {
"version": "6.13.2",
"resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-6.13.2.tgz",
"integrity": "sha512-OGznFs0eAQXJsp+xSd6k/O1UbFi/K/L7WjqeRoFE7vadjAF9y0uppXhYNQNEqygjou782maGClOoZwPqF0Drlw==",
"version": "6.14.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-6.14.0.tgz",
"integrity": "sha512-fB5cw6GRhJUz03MrROVuj5Zm/Q+XWlVdIsFj+Zb1Hvqouc8t+XP2H5y53QYU/MGtd2dPg6/vJJlhoX3xc2ehfw==",
"dev": true,
"dependencies": {
"@typescript-eslint/types": "6.13.2",
"@typescript-eslint/types": "6.14.0",
"eslint-visitor-keys": "^3.4.1"
},
"engines": {
@ -3640,13 +3640,14 @@
"dev": true
},
"node_modules/eslint-plugin-jsonc": {
"version": "2.10.0",
"resolved": "https://registry.npmjs.org/eslint-plugin-jsonc/-/eslint-plugin-jsonc-2.10.0.tgz",
"integrity": "sha512-9d//o6Jyh4s1RxC9fNSt1+MMaFN2ruFdXPG9XZcb/mR2KkfjADYiNL/hbU6W0Cyxfg3tS/XSFuhl5LgtMD8hmw==",
"version": "2.11.1",
"resolved": "https://registry.npmjs.org/eslint-plugin-jsonc/-/eslint-plugin-jsonc-2.11.1.tgz",
"integrity": "sha512-zQ2h7x0gOdUfogfZJzLdclDWu9bksUQtC/zYmU17eLCBv4yETht8r2sbCRx4EECUdZAS8sW/UF7bTba95BoXRQ==",
"dev": true,
"dependencies": {
"@eslint-community/eslint-utils": "^4.2.0",
"eslint-compat-utils": "^0.1.2",
"graphemer": "^1.4.0",
"jsonc-eslint-parser": "^2.0.4",
"natural-compare": "^1.4.0"
},

View file

@ -24,7 +24,8 @@
"lint": "npx eslint . -c ./.github/linters/.eslintrc.yml",
"package": "ncc build src/index.ts --license licenses.txt",
"package:watch": "npm run package -- --watch",
"prepare": "husky install"
"prepare": "husky install",
"postversion": "git push --tags && git tag v1 -f && git push origin v1 -f"
},
"license": "MIT",
"dependencies": {
@ -35,13 +36,13 @@
},
"devDependencies": {
"@types/node": "^20.10.4",
"@typescript-eslint/eslint-plugin": "^6.13.2",
"@typescript-eslint/parser": "^6.13.2",
"@typescript-eslint/eslint-plugin": "^6.14.0",
"@typescript-eslint/parser": "^6.14.0",
"@vercel/ncc": "^0.38.1",
"eslint": "^8.55.0",
"eslint-plugin-github": "^4.10.1",
"eslint-plugin-jest": "^27.6.0",
"eslint-plugin-jsonc": "^2.10.0",
"eslint-plugin-jsonc": "^2.11.1",
"eslint-plugin-prettier": "^5.0.1",
"husky": "^8.0.3",
"jest": "^29.7.0",

View file

@ -8,6 +8,7 @@ export async function run(): Promise<void> {
await cacheRTXTools()
} catch (error) {
if (error instanceof Error) core.setFailed(error.message)
else throw error
}
}

View file

@ -1,7 +1,124 @@
/**
* The entrypoint for the action.
*/
import { run } from './main'
import * as cache from '@actions/cache'
import * as core from '@actions/core'
import * as exec from '@actions/exec'
import * as glob from '@actions/glob'
import * as fs from 'fs'
import * as os from 'os'
import * as path from 'path'
import { rtxDir } from './utils'
async function run(): Promise<void> {
try {
await setToolVersions()
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')
await setupRTX(version)
await setEnvVars()
await testRTX()
if (core.getBooleanInput('install')) {
await rtxInstall()
}
} catch (err) {
if (err instanceof Error) core.setFailed(err.message)
else throw err
}
}
async function setEnvVars(): Promise<void> {
core.startGroup('Setting env vars')
const set = (k: string, v: string): void => {
if (!process.env[k]) {
core.info(`Setting ${k}=${v}`)
core.exportVariable(k, v)
}
}
set('RTX_TRUSTED_CONFIG_PATHS', path.join(process.cwd(), '.rtx.toml'))
set('RTX_YES', '1')
const shimsDir = path.join(rtxDir(), 'shims')
core.info(`Adding ${shimsDir} to PATH`)
core.addPath(shimsDir)
}
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}`
core.saveState('PRIMARY_KEY', primaryKey)
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`)
return
}
core.saveState('CACHE_KEY', cacheKey)
core.info(`rtx cache restored from key: ${cacheKey}`)
}
async function setupRTX(version: string | undefined): Promise<void> {
core.startGroup(version ? `Setup rtx@${version}` : 'Setup rtx')
const rtxBinDir = path.join(rtxDir(), 'bin')
const url = version
? `https://rtx.jdx.dev/v${version}/rtx-v${version}-${getOS()}-${os.arch()}`
: `https://rtx.jdx.dev/rtx-latest-${getOS()}-${os.arch()}`
await fs.promises.mkdir(rtxBinDir, { recursive: true })
await exec.exec('curl', [
'-fsSL',
url,
'--output',
path.join(rtxBinDir, 'rtx')
])
await exec.exec('chmod', ['+x', path.join(rtxBinDir, 'rtx')])
core.addPath(rtxBinDir)
}
async function setToolVersions(): Promise<void> {
const toolVersions = core.getInput('tool_versions')
if (toolVersions) {
await writeFile('.tool-versions', toolVersions)
}
}
async function setRtxToml(): Promise<void> {
const toml = core.getInput('rtx_toml')
if (toml) {
await writeFile('.rtx.toml', toml)
}
}
function getOS(): string {
switch (process.platform) {
case 'darwin':
return 'macos'
default:
return process.platform
}
}
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 writeFile = async (p: fs.PathLike, body: string): Promise<void> =>
core.group(`Writing ${p}`, async () => {
core.info(`Body:\n${body}`)
await fs.promises.writeFile(p, body, { encoding: 'utf8' })
})
// eslint-disable-next-line @typescript-eslint/no-floating-promises
run()

View file

@ -1,116 +0,0 @@
import * as cache from '@actions/cache'
import * as core from '@actions/core'
import * as exec from '@actions/exec'
import * as glob from '@actions/glob'
import * as fs from 'fs'
import * as os from 'os'
import * as path from 'path'
import { rtxDir } from './utils'
async function run(): Promise<void> {
await setToolVersions()
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')
await setupRTX(version)
await setEnvVars()
await exec.exec('rtx', ['--version'])
const install = core.getBooleanInput('install', { required: false })
if (install) {
await exec.exec('rtx', ['install'])
}
await setPaths()
}
async function setEnvVars(): Promise<void> {
if (!process.env['RTX_TRUSTED_CONFIG_PATHS']) {
core.exportVariable(
'RTX_TRUSTED_CONFIG_PATHS',
path.join(process.cwd(), '.rtx.toml')
)
}
if (!process.env['RTX_YES']) {
core.exportVariable('RTX_YES', '1')
}
}
async function restoreRTXCache(): Promise<void> {
const cachePath = rtxDir()
const fileHash = await glob.hashFiles(`**/.tool-versions\n**/.rtx.toml`)
const primaryKey = `rtx-tools-${getOS()}-${os.arch()}-${fileHash}`
core.saveState('PRIMARY_KEY', primaryKey)
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`)
return
}
core.saveState('CACHE_KEY', cacheKey)
core.info(`rtx cache restored from key: ${cacheKey}`)
}
async function setupRTX(version: string | undefined): Promise<void> {
const rtxBinDir = path.join(rtxDir(), 'bin')
const url = version
? `https://rtx.jdx.dev/v${version}/rtx-v${version}-${getOS()}-${os.arch()}`
: `https://rtx.jdx.dev/rtx-latest-${getOS()}-${os.arch()}`
await fs.promises.mkdir(rtxBinDir, { recursive: true })
await exec.exec('curl', [url, '--output', path.join(rtxBinDir, 'rtx')])
await exec.exec('chmod', ['+x', path.join(rtxBinDir, 'rtx')])
core.addPath(rtxBinDir)
}
// returns true if tool_versions was set
async function setToolVersions(): Promise<boolean> {
const toolVersions = core.getInput('tool_versions', { required: false })
if (toolVersions) {
await fs.promises.writeFile('.tool-versions', toolVersions, {
encoding: 'utf8'
})
return true
}
return false
}
function getOS(): string {
switch (process.platform) {
case 'darwin':
return 'macos'
default:
return process.platform
}
}
async function setPaths(): Promise<void> {
for (const binPath of await getBinPaths()) {
core.addPath(binPath)
}
}
async function getBinPaths(): Promise<string[]> {
const output = await exec.getExecOutput('rtx', ['bin-paths'])
return output.stdout.split('\n')
}
if (require.main === module) {
try {
run()
} catch (err) {
if (err instanceof Error) {
core.setFailed(err.message)
} else throw err
}
}
export { run }