From 1440da0afb56fc83763b7e77ab18fb59b9297de9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Domen=20Ko=C5=BEar?= Date: Tue, 11 Oct 2022 16:04:33 +0100 Subject: [PATCH] Allow installing cachix globally for self-hosted runners --- package.json | 4 +++- src/main.ts | 16 +++++++++++----- yarn.lock | 12 ++++++++++++ 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index bc6351fb..ef3938c2 100644 --- a/package.json +++ b/package.json @@ -21,12 +21,14 @@ "license": "ASL2", "dependencies": { "@actions/core": "^1.2.6", - "@actions/exec": "^1.0.1" + "@actions/exec": "^1.0.1", + "which": "^2.0.2" }, "devDependencies": { "@types/jest": "^24.0.13", "@types/node": "^12.0.4", "@zeit/ncc": "^0.20.5", + "@types/which": "^2.0.1", "jest": "^24.8.0", "jest-circus": "^24.7.1", "ts-jest": "^24.0.2", diff --git a/src/main.ts b/src/main.ts index 0dc2fa5b..3b547362 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,6 +1,7 @@ import * as core from '@actions/core'; import * as coreCommand from '@actions/core/lib/command' import * as exec from '@actions/exec'; +import which from 'which'; export const IsPost = !!process.env['STATE_isPost'] @@ -12,7 +13,6 @@ const authToken = core.getInput('authToken') const skipPush = core.getInput('skipPush'); const pathsToPush = core.getInput('pathsToPush'); const pushFilter = core.getInput('pushFilter'); -const cachixExecutable = process.env.HOME + '/.nix-profile/bin/cachix'; const cachixArgs = core.getInput('cachixArgs'); const installCommand = core.getInput('installCommand') || @@ -20,13 +20,19 @@ const installCommand = async function setup() { try { - core.startGroup('Cachix: installing') - await exec.exec('bash', ['-c', installCommand]); + if(!which.sync('cachix', { nothrow: true })) { + core.startGroup('Cachix: installing') + await exec.exec('bash', ['-c', installCommand]); + core.endGroup() + } + + core.startGroup('Cachix: checking version') + await exec.exec('cachix', ['--version']); core.endGroup() // for managed signing key and private caches if (authToken !== "") { - await exec.exec(cachixExecutable, ['authtoken', authToken]); + await exec.exec('cachix', ['authtoken', authToken]); } core.startGroup(`Cachix: using cache ` + name); @@ -59,7 +65,7 @@ async function upload() { if (skipPush === 'true') { core.info('Pushing is disabled as skipPush is set to true'); } else if (signingKey !== "" || authToken !== "") { - await exec.exec(`${__dirname}/push-paths.sh`, [cachixExecutable, cachixArgs, name, pathsToPush, pushFilter]); + await exec.exec(`${__dirname}/push-paths.sh`, ['cachix', cachixArgs, name, pathsToPush, pushFilter]); } else { core.info('Pushing is disabled as signingKey nor authToken are set (or are empty?) in your YAML file.'); } diff --git a/yarn.lock b/yarn.lock index 002dfd68..9c4f0605 100644 --- a/yarn.lock +++ b/yarn.lock @@ -432,6 +432,11 @@ resolved "https://registry.yarnpkg.com/@types/stack-utils/-/stack-utils-1.0.1.tgz#0a851d3bd96498fa25c33ab7278ed3bd65f06c3e" integrity sha512-l42BggppR6zLmpfU6fq9HEa2oGPEI8yrSPL3GITjfRInppYFahObbIQOQK3UGxEnyQpltZLaPe75046NOZQikw== +"@types/which@^2.0.1": + version "2.0.1" + resolved "https://registry.yarnpkg.com/@types/which/-/which-2.0.1.tgz#27ecd67f915b7c3d6ba552135bb1eecd66e63501" + integrity sha512-Jjakcv8Roqtio6w1gr0D7y6twbhx6gGgFGF5BLwajPpnOIOxFkakFhCq+LmyyeAz7BX6ULrjBOxdKaCDy+4+dQ== + "@types/yargs-parser@*": version "15.0.0" resolved "https://registry.yarnpkg.com/@types/yargs-parser/-/yargs-parser-15.0.0.tgz#cb3f9f741869e20cce330ffbeb9271590483882d" @@ -3332,6 +3337,13 @@ which@^1.2.9, which@^1.3.0: dependencies: isexe "^2.0.0" +which@^2.0.2: + version "2.0.2" + resolved "https://registry.yarnpkg.com/which/-/which-2.0.2.tgz#7c6a8dd0a636a0327e10b59c9286eee93f3f51b1" + integrity sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA== + dependencies: + isexe "^2.0.0" + word-wrap@~1.2.3: version "1.2.3" resolved "https://registry.yarnpkg.com/word-wrap/-/word-wrap-1.2.3.tgz#610636f6b1f703891bd34771ccb17fb93b47079c"