Skip to content

Commit

Permalink
Allow installing cachix globally for self-hosted runners
Browse files Browse the repository at this point in the history
  • Loading branch information
domenkozar committed Oct 11, 2022
1 parent b5a076c commit 1440da0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
4 changes: 3 additions & 1 deletion package.json
Expand Up @@ -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",
Expand Down
16 changes: 11 additions & 5 deletions 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']

Expand All @@ -12,21 +13,26 @@ 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') ||
"nix-env --quiet -j8 -iA cachix -f https://cachix.org/api/v1/install";

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);
Expand Down Expand Up @@ -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.');
}
Expand Down
12 changes: 12 additions & 0 deletions yarn.lock
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 1440da0

Please sign in to comment.