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 }}'
|
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.
|
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'
|
description: 'nix-build with the help of caching to Cachix'
|
||||||
author: 'Domen Kožar'
|
author: 'Domen Kožar'
|
||||||
inputs:
|
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:
|
name:
|
||||||
description: 'Name of a cachix cache to push and pull/substitute'
|
description: 'Name of a cachix cache to push and pull/substitute'
|
||||||
required: true
|
required: true
|
||||||
|
|
@ -13,6 +9,12 @@ inputs:
|
||||||
description: 'Authentication token for Cachix, needed only for private cache access'
|
description: 'Authentication token for Cachix, needed only for private cache access'
|
||||||
signingKey:
|
signingKey:
|
||||||
description: 'Signing key secret retrieved after creating binary cache on https://cachix.org'
|
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:
|
branding:
|
||||||
color: 'blue'
|
color: 'blue'
|
||||||
icon: 'database'
|
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 });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
const core = __importStar(require("@actions/core"));
|
const core = __importStar(require("@actions/core"));
|
||||||
const exec = __importStar(require("@actions/exec"));
|
const exec = __importStar(require("@actions/exec"));
|
||||||
|
const os_1 = require("os");
|
||||||
const strings_1 = require("./strings");
|
const strings_1 = require("./strings");
|
||||||
|
function home() {
|
||||||
|
if (os_1.type() == "Darwin") {
|
||||||
|
return "/Users/runner";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return "/home/runner";
|
||||||
|
}
|
||||||
|
}
|
||||||
function run() {
|
function run() {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
try {
|
try {
|
||||||
// inputs
|
// inputs
|
||||||
const file = core.getInput('file');
|
const file = core.getInput('file');
|
||||||
|
const skipNixBuild = core.getInput('skipNixBuild');
|
||||||
const attributes = core.getInput('attributes');
|
const attributes = core.getInput('attributes');
|
||||||
const name = core.getInput('name', { required: true });
|
const name = core.getInput('name', { required: true });
|
||||||
const signingKey = core.getInput('signingKey');
|
const signingKey = core.getInput('signingKey');
|
||||||
const authToken = core.getInput('authToken');
|
const authToken = core.getInput('authToken');
|
||||||
|
const cachixExecutable = "/nix/var/nix/profiles/per-user/runner/profile/bin/cachix";
|
||||||
core.startGroup('Installing Cachix');
|
core.startGroup('Installing Cachix');
|
||||||
// TODO: use cachix official installation link
|
yield exec.exec('nix-env', ['-iA', 'cachix', '-f', 'https://cachix.org/api/v1/install']);
|
||||||
yield exec.exec('nix-env', ['-iA', 'cachix', '-f', 'https://github.com/NixOS/nixpkgs/tarball/ab5863afada3c1b50fc43bf774b75ea71b287cde']);
|
|
||||||
core.endGroup();
|
core.endGroup();
|
||||||
// for private caches
|
// for private caches
|
||||||
if (authToken !== "") {
|
if (authToken !== "") {
|
||||||
yield exec.exec('cachix', ['authtoken', authToken]);
|
yield exec.exec(cachixExecutable, ['authtoken', authToken]);
|
||||||
}
|
}
|
||||||
core.startGroup(`Cachix: using ` + name);
|
core.startGroup(`Cachix: using ` + name);
|
||||||
yield exec.exec('cachix', ['use', name]);
|
yield exec.exec('cachix', ['use', name]);
|
||||||
core.endGroup();
|
core.endGroup();
|
||||||
if (signingKey !== "") {
|
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);
|
core.exportVariable('CACHIX_SIGNING_KEY', signingKey);
|
||||||
}
|
// Reload nix-daemon
|
||||||
// TODO: cachix use --watch-store
|
if (os_1.type() == "Darwin") {
|
||||||
core.startGroup(`Invoking nix-build`);
|
// kickstart awaits nix-daemon to get up again
|
||||||
let paths = '';
|
yield exec.exec("sudo", ["launchctl", "kickstart", "-k", "system/org.nixos.nix-daemon"]);
|
||||||
const options = {
|
}
|
||||||
listeners: {
|
else {
|
||||||
stdout: (data) => {
|
yield exec.exec("sudo", ["pkill", "-HUP", "nix-daemon"]);
|
||||||
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();
|
|
||||||
// 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();
|
core.endGroup();
|
||||||
}
|
}
|
||||||
else {
|
if (skipNixBuild !== 'true') {
|
||||||
console.log("No signing key. Assuming it's a pull request, nothing will be pushed.");
|
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) {
|
catch (error) {
|
||||||
|
|
|
||||||
60
src/main.ts
60
src/main.ts
|
|
@ -1,15 +1,26 @@
|
||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import * as exec from '@actions/exec';
|
import * as exec from '@actions/exec';
|
||||||
|
import {type} from 'os';
|
||||||
import {prependEach, nonEmptySplit} from './strings';
|
import {prependEach, nonEmptySplit} from './strings';
|
||||||
|
|
||||||
|
function home() {
|
||||||
|
if (type() == "Darwin") {
|
||||||
|
return "/Users/runner";
|
||||||
|
} else {
|
||||||
|
return "/home/runner";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function run() {
|
async function run() {
|
||||||
try {
|
try {
|
||||||
// inputs
|
// inputs
|
||||||
const file = core.getInput('file');
|
const file = core.getInput('file');
|
||||||
|
const skipNixBuild = core.getInput('skipNixBuild');
|
||||||
const attributes = core.getInput('attributes');
|
const attributes = core.getInput('attributes');
|
||||||
const name = core.getInput('name', { required: true });
|
const name = core.getInput('name', { required: true });
|
||||||
const signingKey = core.getInput('signingKey');
|
const signingKey = core.getInput('signingKey');
|
||||||
const authToken = core.getInput('authToken')
|
const authToken = core.getInput('authToken')
|
||||||
|
const cachixExecutable = "/nix/var/nix/profiles/per-user/runner/profile/bin/cachix";
|
||||||
|
|
||||||
core.startGroup('Installing Cachix')
|
core.startGroup('Installing Cachix')
|
||||||
await exec.exec('nix-env', ['-iA', 'cachix', '-f', 'https://cachix.org/api/v1/install']);
|
await exec.exec('nix-env', ['-iA', 'cachix', '-f', 'https://cachix.org/api/v1/install']);
|
||||||
|
|
@ -17,38 +28,45 @@ async function run() {
|
||||||
|
|
||||||
// for private caches
|
// for private caches
|
||||||
if (authToken !== "") {
|
if (authToken !== "") {
|
||||||
await exec.exec('cachix', ['authtoken', authToken]);
|
await exec.exec(cachixExecutable, ['authtoken', authToken]);
|
||||||
}
|
}
|
||||||
|
|
||||||
core.startGroup(`Cachix: using ` + name);
|
core.startGroup(`Cachix: using ` + name);
|
||||||
await exec.exec('cachix', ['use', name]);
|
await exec.exec('cachix', ['use', name]);
|
||||||
core.endGroup()
|
core.endGroup();
|
||||||
|
|
||||||
if (signingKey !== "") {
|
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);
|
core.exportVariable('CACHIX_SIGNING_KEY', signingKey);
|
||||||
}
|
|
||||||
// TODO: cachix use --watch-store
|
|
||||||
|
|
||||||
core.startGroup(`Invoking nix-build`);
|
// Reload nix-daemon
|
||||||
let paths = '';
|
if (type() == "Darwin") {
|
||||||
const options = {
|
// kickstart awaits nix-daemon to get up again
|
||||||
listeners: {
|
await exec.exec("sudo", ["launchctl", "kickstart", "-k", "system/org.nixos.nix-daemon"]);
|
||||||
stdout: (data: Buffer) => {
|
} else {
|
||||||
paths += data.toString();
|
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
|
core.endGroup();
|
||||||
if (signingKey !== "") {
|
}
|
||||||
core.startGroup(`Cachix: pushing to ` + name);
|
if (skipNixBuild !== 'true') {
|
||||||
await exec.exec('cachix', ['push', name].concat(nonEmptySplit(paths, /\s+/)));
|
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()
|
core.endGroup()
|
||||||
} else {
|
|
||||||
console.log("No signing key. Assuming it's a pull request, nothing will be pushed.");
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
core.setFailed(`Action failed with error: ${error}`);
|
core.setFailed(`Action failed with error: ${error}`);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue