mirror of
https://codeberg.org/icewind/attic-action.git
synced 2026-06-03 17:44:07 +02:00
Allow skipping nix-build
This commit is contained in:
parent
7fd13f5091
commit
074294984a
4 changed files with 98 additions and 48 deletions
13
README.md
13
README.md
|
|
@ -56,6 +56,19 @@ jobs:
|
|||
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
|
||||
```
|
||||
|
||||
Alternatively, you can use this action to only configure cachix for substitution:
|
||||
|
||||
```yaml
|
||||
...
|
||||
- uses: cachix/cachix-action@v2
|
||||
with:
|
||||
name: mycache
|
||||
skipNixBuild: true
|
||||
# Only needed for private caches
|
||||
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
|
||||
...
|
||||
```
|
||||
|
||||
See [action.yml](action.yml) for all options.
|
||||
|
||||
---
|
||||
|
|
|
|||
10
action.yml
10
action.yml
|
|
@ -2,10 +2,6 @@ name: 'Cachix'
|
|||
description: 'nix-build with the help of caching to Cachix'
|
||||
author: 'Domen Kožar'
|
||||
inputs:
|
||||
file:
|
||||
description: 'Nix file to build. Defaults to default.nix'
|
||||
attributes:
|
||||
description: 'Nix attributes to nix-build. By default, all attributes are built.'
|
||||
name:
|
||||
description: 'Name of a cachix cache to push and pull/substitute'
|
||||
required: true
|
||||
|
|
@ -13,6 +9,12 @@ inputs:
|
|||
description: 'Authentication token for Cachix, needed only for private cache access'
|
||||
signingKey:
|
||||
description: 'Signing key secret retrieved after creating binary cache on https://cachix.org'
|
||||
skipNixBuild:
|
||||
description: 'Set to true to not invoke nix-build after setup.'
|
||||
file:
|
||||
description: 'Nix file to build. Defaults to default.nix'
|
||||
attributes:
|
||||
description: 'Nix attributes to nix-build. By default, all attributes are built.'
|
||||
branding:
|
||||
color: 'blue'
|
||||
icon: 'database'
|
||||
|
|
|
|||
61
lib/main.js
61
lib/main.js
|
|
@ -18,51 +18,68 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const core = __importStar(require("@actions/core"));
|
||||
const exec = __importStar(require("@actions/exec"));
|
||||
const os_1 = require("os");
|
||||
const strings_1 = require("./strings");
|
||||
function home() {
|
||||
if (os_1.type() == "Darwin") {
|
||||
return "/Users/runner";
|
||||
}
|
||||
else {
|
||||
return "/home/runner";
|
||||
}
|
||||
}
|
||||
function run() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
try {
|
||||
// inputs
|
||||
const file = core.getInput('file');
|
||||
const skipNixBuild = core.getInput('skipNixBuild');
|
||||
const attributes = core.getInput('attributes');
|
||||
const name = core.getInput('name', { required: true });
|
||||
const signingKey = core.getInput('signingKey');
|
||||
const authToken = core.getInput('authToken');
|
||||
const cachixExecutable = "/nix/var/nix/profiles/per-user/runner/profile/bin/cachix";
|
||||
core.startGroup('Installing Cachix');
|
||||
// TODO: use cachix official installation link
|
||||
yield exec.exec('nix-env', ['-iA', 'cachix', '-f', 'https://github.com/NixOS/nixpkgs/tarball/ab5863afada3c1b50fc43bf774b75ea71b287cde']);
|
||||
yield exec.exec('nix-env', ['-iA', 'cachix', '-f', 'https://cachix.org/api/v1/install']);
|
||||
core.endGroup();
|
||||
// for private caches
|
||||
if (authToken !== "") {
|
||||
yield exec.exec('cachix', ['authtoken', authToken]);
|
||||
yield exec.exec(cachixExecutable, ['authtoken', authToken]);
|
||||
}
|
||||
core.startGroup(`Cachix: using ` + name);
|
||||
yield exec.exec('cachix', ['use', name]);
|
||||
core.endGroup();
|
||||
if (signingKey !== "") {
|
||||
core.startGroup('Cachix: Configuring push');
|
||||
yield exec.exec("sudo", ["sh", "-c", `echo export HOME=${home()} > /etc/nix/cachix-push.sh`]);
|
||||
yield exec.exec("sudo", ["sh", "-c", `echo export CACHIX_SIGNING_KEY=${signingKey} >> /etc/nix/cachix-push.sh`]);
|
||||
yield exec.exec("sudo", ["sh", "-c", `echo ${cachixExecutable} push ${name} \$OUT_PATHS >> /etc/nix/cachix-push.sh`]);
|
||||
yield exec.exec("sudo", ["sh", "-c", `chmod +x /etc/nix/cachix-push.sh`]);
|
||||
yield exec.exec("sudo", ["sh", "-c", `echo post-build-hook = /etc/nix/cachix-push.sh >> /etc/nix/nix.conf`]);
|
||||
core.exportVariable('CACHIX_SIGNING_KEY', signingKey);
|
||||
}
|
||||
// TODO: cachix use --watch-store
|
||||
core.startGroup(`Invoking nix-build`);
|
||||
let paths = '';
|
||||
const options = {
|
||||
listeners: {
|
||||
stdout: (data) => {
|
||||
paths += data.toString();
|
||||
},
|
||||
// Reload nix-daemon
|
||||
if (os_1.type() == "Darwin") {
|
||||
// kickstart awaits nix-daemon to get up again
|
||||
yield exec.exec("sudo", ["launchctl", "kickstart", "-k", "system/org.nixos.nix-daemon"]);
|
||||
}
|
||||
else {
|
||||
yield exec.exec("sudo", ["pkill", "-HUP", "nix-daemon"]);
|
||||
}
|
||||
};
|
||||
const args = strings_1.prependEach('-A', strings_1.nonEmptySplit(attributes, /\s+/)).concat([file || "default.nix"]);
|
||||
yield exec.exec('nix-build', args, options);
|
||||
core.endGroup();
|
||||
// Needed for PRs
|
||||
if (signingKey !== "") {
|
||||
core.startGroup(`Cachix: pushing to ` + name);
|
||||
yield exec.exec('cachix', ['push', name].concat(strings_1.nonEmptySplit(paths, /\s+/)));
|
||||
core.endGroup();
|
||||
}
|
||||
else {
|
||||
console.log("No signing key. Assuming it's a pull request, nothing will be pushed.");
|
||||
if (skipNixBuild !== 'true') {
|
||||
core.startGroup(`Invoking nix-build`);
|
||||
let paths = '';
|
||||
const options = {
|
||||
listeners: {
|
||||
stdout: (data) => {
|
||||
paths += data.toString();
|
||||
},
|
||||
}
|
||||
};
|
||||
const args = strings_1.prependEach('-A', strings_1.nonEmptySplit(attributes, /\s+/)).concat([file || "default.nix"]);
|
||||
yield exec.exec('nix-build', args, options);
|
||||
core.endGroup();
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
|
|
|
|||
60
src/main.ts
60
src/main.ts
|
|
@ -1,15 +1,26 @@
|
|||
import * as core from '@actions/core';
|
||||
import * as exec from '@actions/exec';
|
||||
import {type} from 'os';
|
||||
import {prependEach, nonEmptySplit} from './strings';
|
||||
|
||||
function home() {
|
||||
if (type() == "Darwin") {
|
||||
return "/Users/runner";
|
||||
} else {
|
||||
return "/home/runner";
|
||||
}
|
||||
}
|
||||
|
||||
async function run() {
|
||||
try {
|
||||
// inputs
|
||||
const file = core.getInput('file');
|
||||
const skipNixBuild = core.getInput('skipNixBuild');
|
||||
const attributes = core.getInput('attributes');
|
||||
const name = core.getInput('name', { required: true });
|
||||
const signingKey = core.getInput('signingKey');
|
||||
const authToken = core.getInput('authToken')
|
||||
const cachixExecutable = "/nix/var/nix/profiles/per-user/runner/profile/bin/cachix";
|
||||
|
||||
core.startGroup('Installing Cachix')
|
||||
await exec.exec('nix-env', ['-iA', 'cachix', '-f', 'https://cachix.org/api/v1/install']);
|
||||
|
|
@ -17,38 +28,45 @@ async function run() {
|
|||
|
||||
// for private caches
|
||||
if (authToken !== "") {
|
||||
await exec.exec('cachix', ['authtoken', authToken]);
|
||||
await exec.exec(cachixExecutable, ['authtoken', authToken]);
|
||||
}
|
||||
|
||||
core.startGroup(`Cachix: using ` + name);
|
||||
await exec.exec('cachix', ['use', name]);
|
||||
core.endGroup()
|
||||
core.endGroup();
|
||||
|
||||
if (signingKey !== "") {
|
||||
core.startGroup('Cachix: Configuring push');
|
||||
await exec.exec("sudo", ["sh", "-c", `echo export HOME=${home()} > /etc/nix/cachix-push.sh`]);
|
||||
await exec.exec("sudo", ["sh", "-c", `echo export CACHIX_SIGNING_KEY=${signingKey} >> /etc/nix/cachix-push.sh`]);
|
||||
await exec.exec("sudo", ["sh", "-c", `echo ${cachixExecutable} push ${name} \$OUT_PATHS >> /etc/nix/cachix-push.sh`]);
|
||||
await exec.exec("sudo", ["sh", "-c", `chmod +x /etc/nix/cachix-push.sh`]);
|
||||
await exec.exec("sudo", ["sh", "-c", `echo post-build-hook = /etc/nix/cachix-push.sh >> /etc/nix/nix.conf`]);
|
||||
core.exportVariable('CACHIX_SIGNING_KEY', signingKey);
|
||||
}
|
||||
// TODO: cachix use --watch-store
|
||||
|
||||
core.startGroup(`Invoking nix-build`);
|
||||
let paths = '';
|
||||
const options = {
|
||||
listeners: {
|
||||
stdout: (data: Buffer) => {
|
||||
paths += data.toString();
|
||||
},
|
||||
// Reload nix-daemon
|
||||
if (type() == "Darwin") {
|
||||
// kickstart awaits nix-daemon to get up again
|
||||
await exec.exec("sudo", ["launchctl", "kickstart", "-k", "system/org.nixos.nix-daemon"]);
|
||||
} else {
|
||||
await exec.exec("sudo", ["pkill", "-HUP", "nix-daemon"]);
|
||||
}
|
||||
};
|
||||
const args = prependEach('-A', nonEmptySplit(attributes, /\s+/)).concat([file || "default.nix"]);
|
||||
await exec.exec('nix-build', args, options);
|
||||
core.endGroup()
|
||||
|
||||
// Needed for PRs
|
||||
if (signingKey !== "") {
|
||||
core.startGroup(`Cachix: pushing to ` + name);
|
||||
await exec.exec('cachix', ['push', name].concat(nonEmptySplit(paths, /\s+/)));
|
||||
core.endGroup();
|
||||
}
|
||||
if (skipNixBuild !== 'true') {
|
||||
core.startGroup(`Invoking nix-build`);
|
||||
let paths = '';
|
||||
const options = {
|
||||
listeners: {
|
||||
stdout: (data: Buffer) => {
|
||||
paths += data.toString();
|
||||
},
|
||||
}
|
||||
};
|
||||
const args = prependEach('-A', nonEmptySplit(attributes, /\s+/)).concat([file || "default.nix"]);
|
||||
await exec.exec('nix-build', args, options);
|
||||
core.endGroup()
|
||||
} else {
|
||||
console.log("No signing key. Assuming it's a pull request, nothing will be pushed.");
|
||||
}
|
||||
} catch (error) {
|
||||
core.setFailed(`Action failed with error: ${error}`);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue