mirror of
https://github.com/DeterminateSystems/magic-nix-cache-action.git
synced 2024-12-26 09:20:35 +01:00
Merge pull request #11 from DeterminateSystems/hoverbear/fh-169-magic-nix-cache-priv-try-logging-in-to-flakehub-if-it-hasnt
Try logging into FlakeHub if nix-installer didn't do that for us
This commit is contained in:
commit
d51480460f
4 changed files with 68 additions and 6 deletions
BIN
bun.lockb
BIN
bun.lockb
Binary file not shown.
30
dist/index.js
generated
vendored
30
dist/index.js
generated
vendored
|
@ -12192,6 +12192,7 @@ async function setUpAutoCache() {
|
||||||
const output = openSync(outputPath, 'a');
|
const output = openSync(outputPath, 'a');
|
||||||
const log = tailLog(daemonDir);
|
const log = tailLog(daemonDir);
|
||||||
const notifyFd = 3;
|
const notifyFd = 3;
|
||||||
|
const netrc = await netrcPath();
|
||||||
const daemon = spawn(daemonBin, [
|
const daemon = spawn(daemonBin, [
|
||||||
'--notify-fd', String(notifyFd),
|
'--notify-fd', String(notifyFd),
|
||||||
'--listen', coreExports.getInput('listen'),
|
'--listen', coreExports.getInput('listen'),
|
||||||
|
@ -12202,7 +12203,7 @@ async function setUpAutoCache() {
|
||||||
'--use-flakehub',
|
'--use-flakehub',
|
||||||
'--flakehub-cache-server', coreExports.getInput('flakehub-cache-server'),
|
'--flakehub-cache-server', coreExports.getInput('flakehub-cache-server'),
|
||||||
'--flakehub-api-server', coreExports.getInput('flakehub-api-server'),
|
'--flakehub-api-server', coreExports.getInput('flakehub-api-server'),
|
||||||
'--flakehub-api-server-netrc', path$1.join(process.env['RUNNER_TEMP'], 'determinate-nix-installer-netrc'),
|
'--flakehub-api-server-netrc', netrc,
|
||||||
] : []).concat(coreExports.getInput('use-gha-cache') === 'true' ? [
|
] : []).concat(coreExports.getInput('use-gha-cache') === 'true' ? [
|
||||||
'--use-gha-cache'
|
'--use-gha-cache'
|
||||||
] : []), {
|
] : []), {
|
||||||
|
@ -12252,6 +12253,33 @@ async function notifyAutoCache() {
|
||||||
coreExports.info(`Magic Nix Cache may not be running for this workflow.`);
|
coreExports.info(`Magic Nix Cache may not be running for this workflow.`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
async function netrcPath() {
|
||||||
|
const expectedNetrcPath = path$1.join(process.env['RUNNER_TEMP'], 'determinate-nix-installer-netrc');
|
||||||
|
try {
|
||||||
|
await fs$2.access(expectedNetrcPath);
|
||||||
|
return expectedNetrcPath;
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
// `nix-installer` was not used, the user may be registered with FlakeHub though.
|
||||||
|
const destinedNetrcPath = path$1.join(process.env['RUNNER_TEMP'], 'magic-nix-cache-netrc');
|
||||||
|
try {
|
||||||
|
await flakehub_login(destinedNetrcPath);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
coreExports.info("FlakeHub cache disabled.");
|
||||||
|
coreExports.debug(`Error while logging into FlakeHub: ${e}`);
|
||||||
|
}
|
||||||
|
return destinedNetrcPath;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function flakehub_login(netrc) {
|
||||||
|
const jwt = await coreExports.getIDToken("api.flakehub.com");
|
||||||
|
await fs$2.writeFile(netrc, [
|
||||||
|
`machine api.flakehub.com login flakehub password ${jwt}`,
|
||||||
|
`machine flakehub.com login flakehub password ${jwt}`,
|
||||||
|
].join("\n"));
|
||||||
|
coreExports.info("Logged in to FlakeHub.");
|
||||||
|
}
|
||||||
async function tearDownAutoCache() {
|
async function tearDownAutoCache() {
|
||||||
const daemonDir = process.env[ENV_CACHE_DAEMONDIR];
|
const daemonDir = process.env[ENV_CACHE_DAEMONDIR];
|
||||||
if (!daemonDir) {
|
if (!daemonDir) {
|
||||||
|
|
|
@ -10,15 +10,15 @@
|
||||||
"license": "LGPL",
|
"license": "LGPL",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.10.0",
|
"@actions/core": "^1.10.0",
|
||||||
|
"got": "^12.6.0",
|
||||||
"tail": "^2.2.6",
|
"tail": "^2.2.6",
|
||||||
"tslib": "^2.5.2",
|
"tslib": "^2.5.2"
|
||||||
"got": "^12.6.0"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@rollup/plugin-commonjs": "^25.0.0",
|
"@rollup/plugin-commonjs": "^25.0.0",
|
||||||
"@rollup/plugin-node-resolve": "^15.0.2",
|
"@rollup/plugin-node-resolve": "^15.0.2",
|
||||||
"@rollup/plugin-typescript": "^11.1.1",
|
"@rollup/plugin-typescript": "^11.1.1",
|
||||||
"@types/node": "^20.2.1",
|
"@types/node": "^20.11.17",
|
||||||
"rollup": "^3.22.0",
|
"rollup": "^3.22.0",
|
||||||
"typescript": "^5.0.4"
|
"typescript": "^5.0.4"
|
||||||
}
|
}
|
||||||
|
|
38
src/index.ts
38
src/index.ts
|
@ -123,6 +123,8 @@ async function setUpAutoCache() {
|
||||||
const output = openSync(outputPath, 'a');
|
const output = openSync(outputPath, 'a');
|
||||||
const log = tailLog(daemonDir);
|
const log = tailLog(daemonDir);
|
||||||
const notifyFd = 3;
|
const notifyFd = 3;
|
||||||
|
const netrc = await netrcPath();
|
||||||
|
|
||||||
const daemon = spawn(
|
const daemon = spawn(
|
||||||
daemonBin,
|
daemonBin,
|
||||||
[
|
[
|
||||||
|
@ -136,7 +138,7 @@ async function setUpAutoCache() {
|
||||||
'--use-flakehub',
|
'--use-flakehub',
|
||||||
'--flakehub-cache-server', core.getInput('flakehub-cache-server'),
|
'--flakehub-cache-server', core.getInput('flakehub-cache-server'),
|
||||||
'--flakehub-api-server', core.getInput('flakehub-api-server'),
|
'--flakehub-api-server', core.getInput('flakehub-api-server'),
|
||||||
'--flakehub-api-server-netrc', path.join(process.env['RUNNER_TEMP'], 'determinate-nix-installer-netrc'),
|
'--flakehub-api-server-netrc', netrc,
|
||||||
] : []).concat(
|
] : []).concat(
|
||||||
core.getInput('use-gha-cache') === 'true' ? [
|
core.getInput('use-gha-cache') === 'true' ? [
|
||||||
'--use-gha-cache'
|
'--use-gha-cache'
|
||||||
|
@ -196,6 +198,39 @@ async function notifyAutoCache() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async function netrcPath() {
|
||||||
|
const expectedNetrcPath = path.join(process.env['RUNNER_TEMP'], 'determinate-nix-installer-netrc')
|
||||||
|
try {
|
||||||
|
await fs.access(expectedNetrcPath)
|
||||||
|
return expectedNetrcPath;
|
||||||
|
} catch {
|
||||||
|
// `nix-installer` was not used, the user may be registered with FlakeHub though.
|
||||||
|
const destinedNetrcPath = path.join(process.env['RUNNER_TEMP'], 'magic-nix-cache-netrc')
|
||||||
|
try {
|
||||||
|
await flakehub_login(destinedNetrcPath);
|
||||||
|
} catch (e) {
|
||||||
|
core.info("FlakeHub cache disabled.");
|
||||||
|
core.debug(`Error while logging into FlakeHub: ${e}`)
|
||||||
|
}
|
||||||
|
return destinedNetrcPath;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function flakehub_login(netrc: string) {
|
||||||
|
const jwt = await core.getIDToken("api.flakehub.com");
|
||||||
|
|
||||||
|
await fs.writeFile(
|
||||||
|
netrc,
|
||||||
|
[
|
||||||
|
`machine api.flakehub.com login flakehub password ${jwt}`,
|
||||||
|
`machine flakehub.com login flakehub password ${jwt}`,
|
||||||
|
].join("\n"),
|
||||||
|
);
|
||||||
|
|
||||||
|
core.info("Logged in to FlakeHub.");
|
||||||
|
}
|
||||||
|
|
||||||
async function tearDownAutoCache() {
|
async function tearDownAutoCache() {
|
||||||
const daemonDir = process.env[ENV_CACHE_DAEMONDIR];
|
const daemonDir = process.env[ENV_CACHE_DAEMONDIR];
|
||||||
|
|
||||||
|
@ -258,4 +293,3 @@ try {
|
||||||
}}
|
}}
|
||||||
|
|
||||||
core.debug(`rip`);
|
core.debug(`rip`);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue