generated from actions/typescript-action
-
Notifications
You must be signed in to change notification settings - Fork 37
/
main.ts
62 lines (54 loc) · 1.97 KB
/
main.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import * as core from '@actions/core';
import * as coreCommand from '@actions/core/lib/command'
import * as exec from '@actions/exec';
export const IsPost = !!process.env['STATE_isPost']
// inputs
const name = core.getInput('name', { required: true });
const signingKey = core.getInput('signingKey');
const authToken = core.getInput('authToken')
const skipPush = core.getInput('skipPush');
const cachixExecutable = '/nix/var/nix/profiles/per-user/runner/profile/bin/cachix';
async function setup() {
try {
core.startGroup('Cachix: installing')
await exec.exec('nix-env', ['--quiet', '-iA', 'cachix', '-f', 'https://cachix.org/api/v1/install']);
core.endGroup()
// for private caches
if (authToken !== "") {
await exec.exec(cachixExecutable, ['authtoken', authToken]);
}
core.startGroup(`Cachix: using cache ` + name);
await exec.exec('cachix', ['use', name]);
core.endGroup();
if (signingKey !== "") {
core.exportVariable('CACHIX_SIGNING_KEY', signingKey);
// Remember existing store paths
await exec.exec("sh", ["-c", `nix path-info --all | grep -v '\.drv$' > /tmp/store-path-pre-build`]);
}
} catch (error) {
core.setFailed(`Action failed with error: ${error}`);
throw (error);
}
}
async function upload() {
try {
if (signingKey !== "" && skipPush !== 'true') {
core.startGroup('Cachix: pushing paths');
await exec.exec("sh", ["-c", `nix path-info --all | grep -v '\.drv$' | cat - /tmp/store-path-pre-build | sort | uniq -u | ${cachixExecutable} push ${name}`]);
core.endGroup();
}
} catch (error) {
core.setFailed(`Action failed with error: ${error}`);
throw (error);
}
}
// Main
if (!IsPost) {
// Publish a variable so that when the POST action runs, it can determine it should run the cleanup logic.
// This is necessary since we don't have a separate entry point.
coreCommand.issueCommand('save-state', {name: 'isPost'}, 'true')
setup()
} else {
// Post
upload()
}