generated from actions/typescript-action
-
Notifications
You must be signed in to change notification settings - Fork 37
/
main.ts
86 lines (76 loc) · 2.74 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import * as core from '@actions/core';
import * as exec from '@actions/exec';
import which from 'which';
export const IsPost = !!process.env['STATE_isPost']
// inputs
const name = core.getInput('name', { required: true });
const extraPullNames = core.getInput('extraPullNames');
const signingKey = core.getInput('signingKey');
const authToken = core.getInput('authToken')
const skipPush = core.getInput('skipPush');
const pathsToPush = core.getInput('pathsToPush');
const pushFilter = core.getInput('pushFilter');
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 {
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('cachix', ['authtoken', authToken]);
}
core.startGroup(`Cachix: using cache ` + name);
await exec.exec('cachix', ['use', name]);
core.endGroup();
if (extraPullNames != "") {
core.startGroup(`Cachix: using extra caches ` + extraPullNames);
const extraPullNameList = extraPullNames.split(',');
for (let itemName of extraPullNameList) {
const trimmedItemName = itemName.trim();
await exec.exec('cachix', ['use', trimmedItemName]);
}
core.endGroup();
}
if (signingKey !== "") {
core.exportVariable('CACHIX_SIGNING_KEY', signingKey);
}
// Remember existing store paths
await exec.exec("sh", ["-c", `${__dirname}/list-nix-store.sh > /tmp/store-path-pre-build`]);
} catch (error) {
core.setFailed(`Action failed with error: ${error}`);
}
}
async function upload() {
core.startGroup('Cachix: push');
try {
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`, ['cachix', cachixArgs, name, pathsToPush, pushFilter]);
} else {
core.info('Pushing is disabled as signingKey nor authToken are set (or are empty?) in your YAML file.');
}
} catch (error) {
core.setFailed(`Action failed with error: ${error}`);
}
core.endGroup();
}
// 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.
core.saveState('isPost', 'true');
setup()
} else {
// Post
upload()
}