Revamp logic into central class

This commit is contained in:
Luc Perkins 2024-04-26 11:37:43 -03:00
parent ab33fc26af
commit a943771501
No known key found for this signature in database
GPG key ID: 16DB1108FB591835
8 changed files with 916 additions and 854 deletions

View file

@ -33,7 +33,7 @@
"@typescript-eslint/array-type": "error",
"@typescript-eslint/await-thenable": "error",
"@typescript-eslint/ban-ts-comment": "error",
"camelcase": "off",
"camelcase": "error",
"@typescript-eslint/consistent-type-assertions": "error",
"@typescript-eslint/explicit-function-return-type": [
"error",

View file

@ -14,23 +14,6 @@ inputs:
upstream-cache:
description: Your preferred upstream cache. Store paths in this store will not be cached in GitHub Actions' cache.
default: https://cache.nixos.org
source-binary:
description: Run a version of the cache binary from somewhere already on disk. Conflicts with all other `source-*` options.
source-branch:
description: The branch of `magic-nix-cache` to use. Conflicts with all other `source-*` options.
required: false
source-pr:
description: The PR of `magic-nix-cache` to use. Conflicts with all other `source-*` options.
required: false
source-revision:
description: The revision of `nix-magic-nix-cache` to use. Conflicts with all other `source-*` options.
required: false
source-tag:
description: The tag of `magic-nix-cache` to use. Conflicts with all other `source-*` options.
required: false
source-url:
description: A URL pointing to a `magic-nix-cache` binary. Overrides all other `source-*` options.
required: false
diagnostic-endpoint:
description: "Diagnostic endpoint url where diagnostics and performance data is sent. To disable set this to an empty string."
default: "https://install.determinate.systems/magic-nix-cache/perf"
@ -51,6 +34,23 @@ inputs:
startup-notification-port:
description: "The port magic-nix-cache uses for daemon startup notification."
default: 41239
source-binary:
description: Run a version of the cache binary from somewhere already on disk. Conflicts with all other `source-*` options.
source-branch:
description: The branch of `magic-nix-cache` to use. Conflicts with all other `source-*` options.
required: false
source-pr:
description: The PR of `magic-nix-cache` to use. Conflicts with all other `source-*` options.
required: false
source-revision:
description: The revision of `nix-magic-nix-cache` to use. Conflicts with all other `source-*` options.
required: false
source-tag:
description: The tag of `magic-nix-cache` to use. Conflicts with all other `source-*` options.
required: false
source-url:
description: A URL pointing to a `magic-nix-cache` binary. Overrides all other `source-*` options.
required: false
runs:
using: "node20"

599
dist/index.js generated vendored

File diff suppressed because it is too large Load diff

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

View file

@ -40,7 +40,7 @@
"@types/node": "^20.12.7",
"@types/tail": "^2.2.3",
"@types/uuid": "^9.0.8",
"@typescript-eslint/eslint-plugin": "^7.7.0",
"@typescript-eslint/eslint-plugin": "^7.7.1",
"@vercel/ncc": "^0.38.1",
"eslint": "^8.57.0",
"eslint-import-resolver-typescript": "^3.6.1",

View file

@ -19,7 +19,7 @@ dependencies:
version: 2.0.1
detsys-ts:
specifier: github:DeterminateSystems/detsys-ts
version: github.com/DeterminateSystems/detsys-ts/56a244c061429692b1c7d80fc068d684db3ae4d2
version: github.com/DeterminateSystems/detsys-ts/5abcb239472d24b114a53f70800f0e42fc30819c
fetch-retry:
specifier: ^5.0.6
version: 5.0.6
@ -47,8 +47,8 @@ devDependencies:
specifier: ^9.0.8
version: 9.0.8
'@typescript-eslint/eslint-plugin':
specifier: ^7.7.0
version: 7.7.0(@typescript-eslint/parser@7.7.0)(eslint@8.57.0)(typescript@5.4.5)
specifier: ^7.7.1
version: 7.7.1(@typescript-eslint/parser@7.7.1)(eslint@8.57.0)(typescript@5.4.5)
'@vercel/ncc':
specifier: ^0.38.1
version: 0.38.1
@ -57,13 +57,13 @@ devDependencies:
version: 8.57.0
eslint-import-resolver-typescript:
specifier: ^3.6.1
version: 3.6.1(@typescript-eslint/parser@7.7.0)(eslint-plugin-import@2.29.1)(eslint@8.57.0)
version: 3.6.1(@typescript-eslint/parser@7.7.1)(eslint-plugin-import@2.29.1)(eslint@8.57.0)
eslint-plugin-github:
specifier: ^4.10.2
version: 4.10.2(eslint-import-resolver-typescript@3.6.1)(eslint@8.57.0)(typescript@5.4.5)
eslint-plugin-import:
specifier: ^2.29.1
version: 2.29.1(@typescript-eslint/parser@7.7.0)(eslint-import-resolver-typescript@3.6.1)(eslint@8.57.0)
version: 2.29.1(@typescript-eslint/parser@7.7.1)(eslint-import-resolver-typescript@3.6.1)(eslint@8.57.0)
eslint-plugin-prettier:
specifier: ^5.1.3
version: 5.1.3(eslint-config-prettier@9.1.0)(eslint@8.57.0)(prettier@3.2.5)
@ -844,136 +844,136 @@ packages:
engines: {node: ^12.20.0 || ^14.18.0 || >=16.0.0}
dev: true
/@rollup/rollup-android-arm-eabi@4.16.0:
resolution: {integrity: sha512-4fDVBAfWYlw2CtYgHEWarAYSozTx5OYLsSM/cdGW7H51FwI10DaGnjKgdqWyWXY/VjugelzriCiKf1UdM20Bxg==}
/@rollup/rollup-android-arm-eabi@4.16.4:
resolution: {integrity: sha512-GkhjAaQ8oUTOKE4g4gsZ0u8K/IHU1+2WQSgS1TwTcYvL+sjbaQjNHFXbOJ6kgqGHIO1DfUhI/Sphi9GkRT9K+Q==}
cpu: [arm]
os: [android]
requiresBuild: true
dev: true
optional: true
/@rollup/rollup-android-arm64@4.16.0:
resolution: {integrity: sha512-JltUBgsKgN108NO4/hj0B/dJYNrqqmdRCtUet5tFDi/w+0tvQP0FToyWBV4HKBcSX4cvFChrCyt5Rh4FX6M6QQ==}
/@rollup/rollup-android-arm64@4.16.4:
resolution: {integrity: sha512-Bvm6D+NPbGMQOcxvS1zUl8H7DWlywSXsphAeOnVeiZLQ+0J6Is8T7SrjGTH29KtYkiY9vld8ZnpV3G2EPbom+w==}
cpu: [arm64]
os: [android]
requiresBuild: true
dev: true
optional: true
/@rollup/rollup-darwin-arm64@4.16.0:
resolution: {integrity: sha512-UwF7tkWf0roggMRv7Vrkof7VgX9tEZIc4vbaQl0/HNX3loWlcum+0ODp1Qsd8s7XvQGT+Zboxx1qxav3vq8YDw==}
/@rollup/rollup-darwin-arm64@4.16.4:
resolution: {integrity: sha512-i5d64MlnYBO9EkCOGe5vPR/EeDwjnKOGGdd7zKFhU5y8haKhQZTN2DgVtpODDMxUr4t2K90wTUJg7ilgND6bXw==}
cpu: [arm64]
os: [darwin]
requiresBuild: true
dev: true
optional: true
/@rollup/rollup-darwin-x64@4.16.0:
resolution: {integrity: sha512-RIY42wn6+Yb0qD29T7Dvm9/AhxrkGDf7X5dgI6rUFXR19+vCLh3u45yLcKOayu2ZQEba9rf/+BX3EggVwckiIw==}
/@rollup/rollup-darwin-x64@4.16.4:
resolution: {integrity: sha512-WZupV1+CdUYehaZqjaFTClJI72fjJEgTXdf4NbW69I9XyvdmztUExBtcI2yIIU6hJtYvtwS6pkTkHJz+k08mAQ==}
cpu: [x64]
os: [darwin]
requiresBuild: true
dev: true
optional: true
/@rollup/rollup-linux-arm-gnueabihf@4.16.0:
resolution: {integrity: sha512-r2TGCIKzqk8VwjOvW7sveledh6aPao131ejUfZNIyFlWBCruF4HOu51KtLArDa7LL6qKd0vkgxGX3/2NmYpWig==}
/@rollup/rollup-linux-arm-gnueabihf@4.16.4:
resolution: {integrity: sha512-ADm/xt86JUnmAfA9mBqFcRp//RVRt1ohGOYF6yL+IFCYqOBNwy5lbEK05xTsEoJq+/tJzg8ICUtS82WinJRuIw==}
cpu: [arm]
os: [linux]
requiresBuild: true
dev: true
optional: true
/@rollup/rollup-linux-arm-musleabihf@4.16.0:
resolution: {integrity: sha512-/QwaDp0RXQTtm25wQFSl02zEm9oveRXr9qAHbdxWCm9YG9dR8esqpyqzS/3GgHDm7jHktPNz9gTENfoUKRCcXQ==}
/@rollup/rollup-linux-arm-musleabihf@4.16.4:
resolution: {integrity: sha512-tJfJaXPiFAG+Jn3cutp7mCs1ePltuAgRqdDZrzb1aeE3TktWWJ+g7xK9SNlaSUFw6IU4QgOxAY4rA+wZUT5Wfg==}
cpu: [arm]
os: [linux]
requiresBuild: true
dev: true
optional: true
/@rollup/rollup-linux-arm64-gnu@4.16.0:
resolution: {integrity: sha512-iypHsz7YEfoyNL0iHbQ7B7pY6hpymvvMgFXXaMd5+WCtvJ9zqWPZKFmo78UeWzWNmTP9JtPiNIQt6efRxx/MNA==}
/@rollup/rollup-linux-arm64-gnu@4.16.4:
resolution: {integrity: sha512-7dy1BzQkgYlUTapDTvK997cgi0Orh5Iu7JlZVBy1MBURk7/HSbHkzRnXZa19ozy+wwD8/SlpJnOOckuNZtJR9w==}
cpu: [arm64]
os: [linux]
requiresBuild: true
dev: true
optional: true
/@rollup/rollup-linux-arm64-musl@4.16.0:
resolution: {integrity: sha512-7UpYcO0uVeomnoL5MpQhrS0FT7xZUJrEXtKVLmps5bRA7x5AiA1PDuPnMbxcOBWjIM2HHIG1t3ndnRTVMIbk5A==}
/@rollup/rollup-linux-arm64-musl@4.16.4:
resolution: {integrity: sha512-zsFwdUw5XLD1gQe0aoU2HVceI6NEW7q7m05wA46eUAyrkeNYExObfRFQcvA6zw8lfRc5BHtan3tBpo+kqEOxmg==}
cpu: [arm64]
os: [linux]
requiresBuild: true
dev: true
optional: true
/@rollup/rollup-linux-powerpc64le-gnu@4.16.0:
resolution: {integrity: sha512-FSuFy4/hOQy0lH135ifnElP/6dKoHcZGHovsaRY0jrfNRR2yjMnVYaqNHKGKy0b/1I8DkD/JtclgJfq7SPti1w==}
/@rollup/rollup-linux-powerpc64le-gnu@4.16.4:
resolution: {integrity: sha512-p8C3NnxXooRdNrdv6dBmRTddEapfESEUflpICDNKXpHvTjRRq1J82CbU5G3XfebIZyI3B0s074JHMWD36qOW6w==}
cpu: [ppc64]
os: [linux]
requiresBuild: true
dev: true
optional: true
/@rollup/rollup-linux-riscv64-gnu@4.16.0:
resolution: {integrity: sha512-qxAB8MiHuDI8jU0D+WI9Gym3fvUJHA/AjKRXxbEH921SB3AeKQStq1FKFA59dAoqqCArjJ1voXM/gMvgEc1q4Q==}
/@rollup/rollup-linux-riscv64-gnu@4.16.4:
resolution: {integrity: sha512-Lh/8ckoar4s4Id2foY7jNgitTOUQczwMWNYi+Mjt0eQ9LKhr6sK477REqQkmy8YHY3Ca3A2JJVdXnfb3Rrwkng==}
cpu: [riscv64]
os: [linux]
requiresBuild: true
dev: true
optional: true
/@rollup/rollup-linux-s390x-gnu@4.16.0:
resolution: {integrity: sha512-j/9yBgWFlNFBfG/S1M2zkBNLeLkNVG59T5c4tlmlrxU+XITWJ3aMVWdpcZ/+mu7auGZftAXueAgAE9mb4lAlag==}
/@rollup/rollup-linux-s390x-gnu@4.16.4:
resolution: {integrity: sha512-1xwwn9ZCQYuqGmulGsTZoKrrn0z2fAur2ujE60QgyDpHmBbXbxLaQiEvzJWDrscRq43c8DnuHx3QorhMTZgisQ==}
cpu: [s390x]
os: [linux]
requiresBuild: true
dev: true
optional: true
/@rollup/rollup-linux-x64-gnu@4.16.0:
resolution: {integrity: sha512-SjsBA1a9wrEleNneGEsR40HdxKdwCatyHC547o/XINqwPW4cqTYiNy/lL1WTJYWU/KgWIb8HH4SgmFStbWoBzw==}
/@rollup/rollup-linux-x64-gnu@4.16.4:
resolution: {integrity: sha512-LuOGGKAJ7dfRtxVnO1i3qWc6N9sh0Em/8aZ3CezixSTM+E9Oq3OvTsvC4sm6wWjzpsIlOCnZjdluINKESflJLA==}
cpu: [x64]
os: [linux]
requiresBuild: true
dev: true
optional: true
/@rollup/rollup-linux-x64-musl@4.16.0:
resolution: {integrity: sha512-YKCs7ghJZ5po6/qgfONiXyFKOKcTK4Kerzk/Kc89QK0JT94Qg4NurL+3Y3rZh5am2tu1OlvHPpBHQNBE8cFgJQ==}
/@rollup/rollup-linux-x64-musl@4.16.4:
resolution: {integrity: sha512-ch86i7KkJKkLybDP2AtySFTRi5fM3KXp0PnHocHuJMdZwu7BuyIKi35BE9guMlmTpwwBTB3ljHj9IQXnTCD0vA==}
cpu: [x64]
os: [linux]
requiresBuild: true
dev: true
optional: true
/@rollup/rollup-win32-arm64-msvc@4.16.0:
resolution: {integrity: sha512-+wtkF+z2nw0ZwwHji01wOW0loxFl24lBNxPtVAXtnPPDL9Ew0EhiCMOegXe/EAH3Zlr8Iw9tyPJXB3DltQLEyw==}
/@rollup/rollup-win32-arm64-msvc@4.16.4:
resolution: {integrity: sha512-Ma4PwyLfOWZWayfEsNQzTDBVW8PZ6TUUN1uFTBQbF2Chv/+sjenE86lpiEwj2FiviSmSZ4Ap4MaAfl1ciF4aSA==}
cpu: [arm64]
os: [win32]
requiresBuild: true
dev: true
optional: true
/@rollup/rollup-win32-ia32-msvc@4.16.0:
resolution: {integrity: sha512-7qLyKTL7Lf2g0B8bduETVAEI3WVUVwBRVcECojVevPNVAmi19IW1P2X+uMSwhmWNy36Q/qEvxXsfts1I8wpawg==}
/@rollup/rollup-win32-ia32-msvc@4.16.4:
resolution: {integrity: sha512-9m/ZDrQsdo/c06uOlP3W9G2ENRVzgzbSXmXHT4hwVaDQhYcRpi9bgBT0FTG9OhESxwK0WjQxYOSfv40cU+T69w==}
cpu: [ia32]
os: [win32]
requiresBuild: true
dev: true
optional: true
/@rollup/rollup-win32-x64-msvc@4.16.0:
resolution: {integrity: sha512-tkfxXt+7c3Ecgn7ln9NJPdBM+QKwQdmFFpgAP+FYhAuRS5y3tY8xeza82gFjbPpytkHmaQnVdMtuzbToCz2tuw==}
/@rollup/rollup-win32-x64-msvc@4.16.4:
resolution: {integrity: sha512-YunpoOAyGLDseanENHmbFvQSfVL5BxW3k7hhy0eN4rb3gS/ct75dVD0EXOWIqFT/nE8XYW6LP6vz6ctKRi0k9A==}
cpu: [x64]
os: [win32]
requiresBuild: true
dev: true
optional: true
/@sindresorhus/is@6.2.0:
resolution: {integrity: sha512-yM/IGPkVnYGblhDosFBwq0ZGdnVSBkNV4onUtipGMOjZd4kB6GAu3ys91aftSbyMHh6A2GPdt+KDI5NoWP63MQ==}
/@sindresorhus/is@6.3.0:
resolution: {integrity: sha512-bOSPck7aIJjASXIg1qvXSIjXhVBpIEKdl2Wxg4pVqoTRPL8wWExKBrnGIh6CEnhkFQHfc36k7APhO3uXV4g5xg==}
engines: {node: '>=16'}
dev: false
@ -1050,8 +1050,8 @@ packages:
resolution: {integrity: sha512-jg+97EGIcY9AGHJJRaaPVgetKDsrTgbRjQ5Msgjh/DQKEFl0DtyRr/VCOyD1T2R1MNeWPK/u7JoGhlDZnKBAfA==}
dev: true
/@typescript-eslint/eslint-plugin@7.7.0(@typescript-eslint/parser@7.7.0)(eslint@8.57.0)(typescript@5.4.5):
resolution: {integrity: sha512-GJWR0YnfrKnsRoluVO3PRb9r5aMZriiMMM/RHj5nnTrBy1/wIgk76XCtCKcnXGjpZQJQRFtGV9/0JJ6n30uwpQ==}
/@typescript-eslint/eslint-plugin@7.7.1(@typescript-eslint/parser@7.7.1)(eslint@8.57.0)(typescript@5.4.5):
resolution: {integrity: sha512-KwfdWXJBOviaBVhxO3p5TJiLpNuh2iyXyjmWN0f1nU87pwyvfS0EmjC6ukQVYVFJd/K1+0NWGPDXiyEyQorn0Q==}
engines: {node: ^18.18.0 || >=20.0.0}
peerDependencies:
'@typescript-eslint/parser': ^7.0.0
@ -1062,11 +1062,11 @@ packages:
optional: true
dependencies:
'@eslint-community/regexpp': 4.10.0
'@typescript-eslint/parser': 7.7.0(eslint@8.57.0)(typescript@5.4.5)
'@typescript-eslint/scope-manager': 7.7.0
'@typescript-eslint/type-utils': 7.7.0(eslint@8.57.0)(typescript@5.4.5)
'@typescript-eslint/utils': 7.7.0(eslint@8.57.0)(typescript@5.4.5)
'@typescript-eslint/visitor-keys': 7.7.0
'@typescript-eslint/parser': 7.7.1(eslint@8.57.0)(typescript@5.4.5)
'@typescript-eslint/scope-manager': 7.7.1
'@typescript-eslint/type-utils': 7.7.1(eslint@8.57.0)(typescript@5.4.5)
'@typescript-eslint/utils': 7.7.1(eslint@8.57.0)(typescript@5.4.5)
'@typescript-eslint/visitor-keys': 7.7.1
debug: 4.3.4
eslint: 8.57.0
graphemer: 1.4.0
@ -1079,8 +1079,8 @@ packages:
- supports-color
dev: true
/@typescript-eslint/parser@7.7.0(eslint@8.57.0)(typescript@5.4.5):
resolution: {integrity: sha512-fNcDm3wSwVM8QYL4HKVBggdIPAy9Q41vcvC/GtDobw3c4ndVT3K6cqudUmjHPw8EAp4ufax0o58/xvWaP2FmTg==}
/@typescript-eslint/parser@7.7.1(eslint@8.57.0)(typescript@5.4.5):
resolution: {integrity: sha512-vmPzBOOtz48F6JAGVS/kZYk4EkXao6iGrD838sp1w3NQQC0W8ry/q641KU4PrG7AKNAf56NOcR8GOpH8l9FPCw==}
engines: {node: ^18.18.0 || >=20.0.0}
peerDependencies:
eslint: ^8.56.0
@ -1089,10 +1089,10 @@ packages:
typescript:
optional: true
dependencies:
'@typescript-eslint/scope-manager': 7.7.0
'@typescript-eslint/types': 7.7.0
'@typescript-eslint/typescript-estree': 7.7.0(typescript@5.4.5)
'@typescript-eslint/visitor-keys': 7.7.0
'@typescript-eslint/scope-manager': 7.7.1
'@typescript-eslint/types': 7.7.1
'@typescript-eslint/typescript-estree': 7.7.1(typescript@5.4.5)
'@typescript-eslint/visitor-keys': 7.7.1
debug: 4.3.4
eslint: 8.57.0
typescript: 5.4.5
@ -1100,16 +1100,16 @@ packages:
- supports-color
dev: true
/@typescript-eslint/scope-manager@7.7.0:
resolution: {integrity: sha512-/8INDn0YLInbe9Wt7dK4cXLDYp0fNHP5xKLHvZl3mOT5X17rK/YShXaiNmorl+/U4VKCVIjJnx4Ri5b0y+HClw==}
/@typescript-eslint/scope-manager@7.7.1:
resolution: {integrity: sha512-PytBif2SF+9SpEUKynYn5g1RHFddJUcyynGpztX3l/ik7KmZEv19WCMhUBkHXPU9es/VWGD3/zg3wg90+Dh2rA==}
engines: {node: ^18.18.0 || >=20.0.0}
dependencies:
'@typescript-eslint/types': 7.7.0
'@typescript-eslint/visitor-keys': 7.7.0
'@typescript-eslint/types': 7.7.1
'@typescript-eslint/visitor-keys': 7.7.1
dev: true
/@typescript-eslint/type-utils@7.7.0(eslint@8.57.0)(typescript@5.4.5):
resolution: {integrity: sha512-bOp3ejoRYrhAlnT/bozNQi3nio9tIgv3U5C0mVDdZC7cpcQEDZXvq8inrHYghLVwuNABRqrMW5tzAv88Vy77Sg==}
/@typescript-eslint/type-utils@7.7.1(eslint@8.57.0)(typescript@5.4.5):
resolution: {integrity: sha512-ZksJLW3WF7o75zaBPScdW1Gbkwhd/lyeXGf1kQCxJaOeITscoSl0MjynVvCzuV5boUz/3fOI06Lz8La55mu29Q==}
engines: {node: ^18.18.0 || >=20.0.0}
peerDependencies:
eslint: ^8.56.0
@ -1118,8 +1118,8 @@ packages:
typescript:
optional: true
dependencies:
'@typescript-eslint/typescript-estree': 7.7.0(typescript@5.4.5)
'@typescript-eslint/utils': 7.7.0(eslint@8.57.0)(typescript@5.4.5)
'@typescript-eslint/typescript-estree': 7.7.1(typescript@5.4.5)
'@typescript-eslint/utils': 7.7.1(eslint@8.57.0)(typescript@5.4.5)
debug: 4.3.4
eslint: 8.57.0
ts-api-utils: 1.3.0(typescript@5.4.5)
@ -1128,13 +1128,13 @@ packages:
- supports-color
dev: true
/@typescript-eslint/types@7.7.0:
resolution: {integrity: sha512-G01YPZ1Bd2hn+KPpIbrAhEWOn5lQBrjxkzHkWvP6NucMXFtfXoevK82hzQdpfuQYuhkvFDeQYbzXCjR1z9Z03w==}
/@typescript-eslint/types@7.7.1:
resolution: {integrity: sha512-AmPmnGW1ZLTpWa+/2omPrPfR7BcbUU4oha5VIbSbS1a1Tv966bklvLNXxp3mrbc+P2j4MNOTfDffNsk4o0c6/w==}
engines: {node: ^18.18.0 || >=20.0.0}
dev: true
/@typescript-eslint/typescript-estree@7.7.0(typescript@5.4.5):
resolution: {integrity: sha512-8p71HQPE6CbxIBy2kWHqM1KGrC07pk6RJn40n0DSc6bMOBBREZxSDJ+BmRzc8B5OdaMh1ty3mkuWRg4sCFiDQQ==}
/@typescript-eslint/typescript-estree@7.7.1(typescript@5.4.5):
resolution: {integrity: sha512-CXe0JHCXru8Fa36dteXqmH2YxngKJjkQLjxzoj6LYwzZ7qZvgsLSc+eqItCrqIop8Vl2UKoAi0StVWu97FQZIQ==}
engines: {node: ^18.18.0 || >=20.0.0}
peerDependencies:
typescript: '*'
@ -1142,8 +1142,8 @@ packages:
typescript:
optional: true
dependencies:
'@typescript-eslint/types': 7.7.0
'@typescript-eslint/visitor-keys': 7.7.0
'@typescript-eslint/types': 7.7.1
'@typescript-eslint/visitor-keys': 7.7.1
debug: 4.3.4
globby: 11.1.0
is-glob: 4.0.3
@ -1155,8 +1155,8 @@ packages:
- supports-color
dev: true
/@typescript-eslint/utils@7.7.0(eslint@8.57.0)(typescript@5.4.5):
resolution: {integrity: sha512-LKGAXMPQs8U/zMRFXDZOzmMKgFv3COlxUQ+2NMPhbqgVm6R1w+nU1i4836Pmxu9jZAuIeyySNrN/6Rc657ggig==}
/@typescript-eslint/utils@7.7.1(eslint@8.57.0)(typescript@5.4.5):
resolution: {integrity: sha512-QUvBxPEaBXf41ZBbaidKICgVL8Hin0p6prQDu6bbetWo39BKbWJxRsErOzMNT1rXvTll+J7ChrbmMCXM9rsvOQ==}
engines: {node: ^18.18.0 || >=20.0.0}
peerDependencies:
eslint: ^8.56.0
@ -1164,9 +1164,9 @@ packages:
'@eslint-community/eslint-utils': 4.4.0(eslint@8.57.0)
'@types/json-schema': 7.0.15
'@types/semver': 7.5.8
'@typescript-eslint/scope-manager': 7.7.0
'@typescript-eslint/types': 7.7.0
'@typescript-eslint/typescript-estree': 7.7.0(typescript@5.4.5)
'@typescript-eslint/scope-manager': 7.7.1
'@typescript-eslint/types': 7.7.1
'@typescript-eslint/typescript-estree': 7.7.1(typescript@5.4.5)
eslint: 8.57.0
semver: 7.6.0
transitivePeerDependencies:
@ -1174,11 +1174,11 @@ packages:
- typescript
dev: true
/@typescript-eslint/visitor-keys@7.7.0:
resolution: {integrity: sha512-h0WHOj8MhdhY8YWkzIF30R379y0NqyOHExI9N9KCzvmu05EgG4FumeYa3ccfKUSphyWkWQE1ybVrgz/Pbam6YA==}
/@typescript-eslint/visitor-keys@7.7.1:
resolution: {integrity: sha512-gBL3Eq25uADw1LQ9kVpf3hRM+DWzs0uZknHYK3hq4jcTPqVCClHGDnB6UUUV2SFeBeA4KWHWbbLqmbGcZ4FYbw==}
engines: {node: ^18.18.0 || >=20.0.0}
dependencies:
'@typescript-eslint/types': 7.7.0
'@typescript-eslint/types': 7.7.1
eslint-visitor-keys: 3.4.3
dev: true
@ -1405,14 +1405,14 @@ packages:
engines: {node: ^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7}
hasBin: true
dependencies:
caniuse-lite: 1.0.30001611
electron-to-chromium: 1.4.745
caniuse-lite: 1.0.30001612
electron-to-chromium: 1.4.749
node-releases: 2.0.14
update-browserslist-db: 1.0.13(browserslist@4.23.0)
dev: true
/bundle-require@4.0.2(esbuild@0.19.12):
resolution: {integrity: sha512-jwzPOChofl67PSTW2SGubV9HBQAhhR2i6nskiOThauo9dzwDUgOWQScFVaJkjEfYX+UXiD+LEx8EblQMc2wIag==}
/bundle-require@4.0.3(esbuild@0.19.12):
resolution: {integrity: sha512-2iscZ3fcthP2vka4Y7j277YJevwmsby/FpFDwjgw34Nl7dtCpt7zz/4TexmHMzY6KZEih7En9ImlbbgUNNQGtA==}
engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0}
peerDependencies:
esbuild: '>=0.17'
@ -1460,8 +1460,8 @@ packages:
engines: {node: '>=6'}
dev: true
/caniuse-lite@1.0.30001611:
resolution: {integrity: sha512-19NuN1/3PjA3QI8Eki55N8my4LzfkMCRLgCVfrl/slbSAchQfV0+GwjPrK3rq37As4UCLlM/DHajbKkAqbv92Q==}
/caniuse-lite@1.0.30001612:
resolution: {integrity: sha512-lFgnZ07UhaCcsSZgWW0K5j4e69dK1u/ltrL9lTUiFOwNHs12S3UMIEYgBV0Z6C6hRDev7iRnMzzYmKabYdXF9g==}
dev: true
/chalk@2.4.2:
@ -1668,8 +1668,8 @@ packages:
resolution: {integrity: sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==}
dev: true
/electron-to-chromium@1.4.745:
resolution: {integrity: sha512-tRbzkaRI5gbUn5DEvF0dV4TQbMZ5CLkWeTAXmpC9IrYT+GE+x76i9p+o3RJ5l9XmdQlI1pPhVtE9uNcJJ0G0EA==}
/electron-to-chromium@1.4.749:
resolution: {integrity: sha512-LRMMrM9ITOvue0PoBrvNIraVmuDbJV5QC9ierz/z5VilMdPOVMjOtpICNld3PuXuTZ3CHH/UPxX9gHhAPwi+0Q==}
dev: true
/emoji-regex@8.0.0:
@ -1752,8 +1752,8 @@ packages:
engines: {node: '>= 0.4'}
dev: true
/es-iterator-helpers@1.0.18:
resolution: {integrity: sha512-scxAJaewsahbqTYrGKJihhViaM6DDZDDoucfvzNbK0pOren1g/daDQ3IAhzn+1G14rBG7w+i5N+qul60++zlKA==}
/es-iterator-helpers@1.0.19:
resolution: {integrity: sha512-zoMwbCcH5hwUkKJkT8kDIBZSz9I6mVG//+lDCinLCGov4+r7NIy0ld8o03M0cJxl2spVf6ESYVS6/gpIfq1FFw==}
engines: {node: '>= 0.4'}
dependencies:
call-bind: 1.0.7
@ -1868,7 +1868,7 @@ packages:
- supports-color
dev: true
/eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@7.7.0)(eslint-plugin-import@2.29.1)(eslint@8.57.0):
/eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@7.7.1)(eslint-plugin-import@2.29.1)(eslint@8.57.0):
resolution: {integrity: sha512-xgdptdoi5W3niYeuQxKmzVDTATvLYqhpwmykwsh7f6HIOStGWEIL9iqZgQDF9u9OEzrRwR8no5q2VT+bjAujTg==}
engines: {node: ^14.18.0 || >=16.0.0}
peerDependencies:
@ -1878,8 +1878,8 @@ packages:
debug: 4.3.4
enhanced-resolve: 5.16.0
eslint: 8.57.0
eslint-module-utils: 2.8.1(@typescript-eslint/parser@7.7.0)(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1)(eslint@8.57.0)
eslint-plugin-import: 2.29.1(@typescript-eslint/parser@7.7.0)(eslint-import-resolver-typescript@3.6.1)(eslint@8.57.0)
eslint-module-utils: 2.8.1(@typescript-eslint/parser@7.7.1)(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1)(eslint@8.57.0)
eslint-plugin-import: 2.29.1(@typescript-eslint/parser@7.7.1)(eslint-import-resolver-typescript@3.6.1)(eslint@8.57.0)
fast-glob: 3.3.2
get-tsconfig: 4.7.3
is-core-module: 2.13.1
@ -1891,7 +1891,7 @@ packages:
- supports-color
dev: true
/eslint-module-utils@2.8.1(@typescript-eslint/parser@7.7.0)(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1)(eslint@8.57.0):
/eslint-module-utils@2.8.1(@typescript-eslint/parser@7.7.1)(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1)(eslint@8.57.0):
resolution: {integrity: sha512-rXDXR3h7cs7dy9RNpUlQf80nX31XWJEyGq1tRMo+6GsO5VmTe4UTwtmonAD4ZkAsrfMVDA2wlGJ3790Ys+D49Q==}
engines: {node: '>=4'}
peerDependencies:
@ -1912,11 +1912,11 @@ packages:
eslint-import-resolver-webpack:
optional: true
dependencies:
'@typescript-eslint/parser': 7.7.0(eslint@8.57.0)(typescript@5.4.5)
'@typescript-eslint/parser': 7.7.1(eslint@8.57.0)(typescript@5.4.5)
debug: 3.2.7
eslint: 8.57.0
eslint-import-resolver-node: 0.3.9
eslint-import-resolver-typescript: 3.6.1(@typescript-eslint/parser@7.7.0)(eslint-plugin-import@2.29.1)(eslint@8.57.0)
eslint-import-resolver-typescript: 3.6.1(@typescript-eslint/parser@7.7.1)(eslint-plugin-import@2.29.1)(eslint@8.57.0)
transitivePeerDependencies:
- supports-color
dev: true
@ -1960,8 +1960,8 @@ packages:
eslint: ^8.0.1
dependencies:
'@github/browserslist-config': 1.0.0
'@typescript-eslint/eslint-plugin': 7.7.0(@typescript-eslint/parser@7.7.0)(eslint@8.57.0)(typescript@5.4.5)
'@typescript-eslint/parser': 7.7.0(eslint@8.57.0)(typescript@5.4.5)
'@typescript-eslint/eslint-plugin': 7.7.1(@typescript-eslint/parser@7.7.1)(eslint@8.57.0)(typescript@5.4.5)
'@typescript-eslint/parser': 7.7.1(eslint@8.57.0)(typescript@5.4.5)
aria-query: 5.3.0
eslint: 8.57.0
eslint-config-prettier: 9.1.0(eslint@8.57.0)
@ -1969,7 +1969,7 @@ packages:
eslint-plugin-eslint-comments: 3.2.0(eslint@8.57.0)
eslint-plugin-filenames: 1.3.2(eslint@8.57.0)
eslint-plugin-i18n-text: 1.0.1(eslint@8.57.0)
eslint-plugin-import: 2.29.1(@typescript-eslint/parser@7.7.0)(eslint-import-resolver-typescript@3.6.1)(eslint@8.57.0)
eslint-plugin-import: 2.29.1(@typescript-eslint/parser@7.7.1)(eslint-import-resolver-typescript@3.6.1)(eslint@8.57.0)
eslint-plugin-jsx-a11y: 6.8.0(eslint@8.57.0)
eslint-plugin-no-only-tests: 3.1.0
eslint-plugin-prettier: 5.1.3(eslint-config-prettier@9.1.0)(eslint@8.57.0)(prettier@3.2.5)
@ -1993,7 +1993,7 @@ packages:
eslint: 8.57.0
dev: true
/eslint-plugin-import@2.29.1(@typescript-eslint/parser@7.7.0)(eslint-import-resolver-typescript@3.6.1)(eslint@8.57.0):
/eslint-plugin-import@2.29.1(@typescript-eslint/parser@7.7.1)(eslint-import-resolver-typescript@3.6.1)(eslint@8.57.0):
resolution: {integrity: sha512-BbPC0cuExzhiMo4Ff1BTVwHpjjv28C5R+btTOGaCRC7UEz801up0JadwkeSk5Ued6TG34uaczuVuH6qyy5YUxw==}
engines: {node: '>=4'}
peerDependencies:
@ -2003,7 +2003,7 @@ packages:
'@typescript-eslint/parser':
optional: true
dependencies:
'@typescript-eslint/parser': 7.7.0(eslint@8.57.0)(typescript@5.4.5)
'@typescript-eslint/parser': 7.7.1(eslint@8.57.0)(typescript@5.4.5)
array-includes: 3.1.8
array.prototype.findlastindex: 1.2.5
array.prototype.flat: 1.3.2
@ -2012,7 +2012,7 @@ packages:
doctrine: 2.1.0
eslint: 8.57.0
eslint-import-resolver-node: 0.3.9
eslint-module-utils: 2.8.1(@typescript-eslint/parser@7.7.0)(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1)(eslint@8.57.0)
eslint-module-utils: 2.8.1(@typescript-eslint/parser@7.7.1)(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1)(eslint@8.57.0)
hasown: 2.0.2
is-core-module: 2.13.1
is-glob: 4.0.3
@ -2043,7 +2043,7 @@ packages:
axobject-query: 3.2.1
damerau-levenshtein: 1.0.8
emoji-regex: 9.2.2
es-iterator-helpers: 1.0.18
es-iterator-helpers: 1.0.19
eslint: 8.57.0
hasown: 2.0.2
jsx-ast-utils: 3.3.5
@ -2454,7 +2454,7 @@ packages:
resolution: {integrity: sha512-KOaPMremmsvx6l9BLC04LYE6ZFW4x7e4HkTe3LwBmtuYYQwpeS4XKqzhubTIkaQ1Nr+eXxeori0zuwupXMovBQ==}
engines: {node: '>=20'}
dependencies:
'@sindresorhus/is': 6.2.0
'@sindresorhus/is': 6.3.0
'@szmarczak/http-timer': 5.0.1
cacheable-lookup: 7.0.0
cacheable-request: 10.2.14
@ -2921,8 +2921,8 @@ packages:
engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0}
dev: false
/lru-cache@10.2.0:
resolution: {integrity: sha512-2bIM8x+VAf6JT4bKAljS1qUWgMsqZRPGJS6FSahIMPVvctcNhyVp7AJu7quxOW9jwkryBReKZY5tY5JYv2n/7Q==}
/lru-cache@10.2.1:
resolution: {integrity: sha512-tS24spDe/zXhWbNPErCHs/AGOzbKGHT+ybSBqmdLm8WZ1xXLWvH8Qn71QPAlqVhd0qUTWjy+Kl9JmISgDdEjsA==}
engines: {node: 14 || >=16.14}
dev: true
@ -3185,7 +3185,7 @@ packages:
resolution: {integrity: sha512-7xTavNy5RQXnsjANvVvMkEjvloOinkAjv/Z6Ildz9v2RinZ4SBKTWFOVRbaF8p0vpHnyjV/UwNDdKuUv6M5qcA==}
engines: {node: '>=16 || 14 >=14.17'}
dependencies:
lru-cache: 10.2.0
lru-cache: 10.2.1
minipass: 7.0.4
dev: true
@ -3346,29 +3346,29 @@ packages:
glob: 7.2.3
dev: true
/rollup@4.16.0:
resolution: {integrity: sha512-joxy/Hd4Ee289394//Q1aoebcxXyHasDieCTk8YtP4G4al4TUlx85EnuCLrfrdtLzrna9kNjH++Sx063wxSgmA==}
/rollup@4.16.4:
resolution: {integrity: sha512-kuaTJSUbz+Wsb2ATGvEknkI12XV40vIiHmLuFlejoo7HtDok/O5eDDD0UpCVY5bBX5U5RYo8wWP83H7ZsqVEnA==}
engines: {node: '>=18.0.0', npm: '>=8.0.0'}
hasBin: true
dependencies:
'@types/estree': 1.0.5
optionalDependencies:
'@rollup/rollup-android-arm-eabi': 4.16.0
'@rollup/rollup-android-arm64': 4.16.0
'@rollup/rollup-darwin-arm64': 4.16.0
'@rollup/rollup-darwin-x64': 4.16.0
'@rollup/rollup-linux-arm-gnueabihf': 4.16.0
'@rollup/rollup-linux-arm-musleabihf': 4.16.0
'@rollup/rollup-linux-arm64-gnu': 4.16.0
'@rollup/rollup-linux-arm64-musl': 4.16.0
'@rollup/rollup-linux-powerpc64le-gnu': 4.16.0
'@rollup/rollup-linux-riscv64-gnu': 4.16.0
'@rollup/rollup-linux-s390x-gnu': 4.16.0
'@rollup/rollup-linux-x64-gnu': 4.16.0
'@rollup/rollup-linux-x64-musl': 4.16.0
'@rollup/rollup-win32-arm64-msvc': 4.16.0
'@rollup/rollup-win32-ia32-msvc': 4.16.0
'@rollup/rollup-win32-x64-msvc': 4.16.0
'@rollup/rollup-android-arm-eabi': 4.16.4
'@rollup/rollup-android-arm64': 4.16.4
'@rollup/rollup-darwin-arm64': 4.16.4
'@rollup/rollup-darwin-x64': 4.16.4
'@rollup/rollup-linux-arm-gnueabihf': 4.16.4
'@rollup/rollup-linux-arm-musleabihf': 4.16.4
'@rollup/rollup-linux-arm64-gnu': 4.16.4
'@rollup/rollup-linux-arm64-musl': 4.16.4
'@rollup/rollup-linux-powerpc64le-gnu': 4.16.4
'@rollup/rollup-linux-riscv64-gnu': 4.16.4
'@rollup/rollup-linux-s390x-gnu': 4.16.4
'@rollup/rollup-linux-x64-gnu': 4.16.4
'@rollup/rollup-linux-x64-musl': 4.16.4
'@rollup/rollup-win32-arm64-msvc': 4.16.4
'@rollup/rollup-win32-ia32-msvc': 4.16.4
'@rollup/rollup-win32-x64-msvc': 4.16.4
fsevents: 2.3.3
dev: true
@ -3709,7 +3709,7 @@ packages:
typescript:
optional: true
dependencies:
bundle-require: 4.0.2(esbuild@0.19.12)
bundle-require: 4.0.3(esbuild@0.19.12)
cac: 6.7.14
chokidar: 3.6.0
debug: 4.3.4
@ -3719,7 +3719,7 @@ packages:
joycon: 3.1.1
postcss-load-config: 4.0.2
resolve-from: 5.0.0
rollup: 4.16.0
rollup: 4.16.4
source-map: 0.8.0-beta.0
sucrase: 3.35.0
tree-kill: 1.2.2
@ -3976,8 +3976,8 @@ packages:
engines: {node: '>=10'}
dev: true
github.com/DeterminateSystems/detsys-ts/56a244c061429692b1c7d80fc068d684db3ae4d2:
resolution: {tarball: https://codeload.github.com/DeterminateSystems/detsys-ts/tar.gz/56a244c061429692b1c7d80fc068d684db3ae4d2}
github.com/DeterminateSystems/detsys-ts/5abcb239472d24b114a53f70800f0e42fc30819c:
resolution: {tarball: https://codeload.github.com/DeterminateSystems/detsys-ts/tar.gz/5abcb239472d24b114a53f70800f0e42fc30819c}
name: detsys-ts
version: 1.0.0
dependencies:

53
src/helpers.ts Normal file
View file

@ -0,0 +1,53 @@
import * as actionsCore from "@actions/core";
import * as fs from "node:fs/promises";
import * as os from "node:os";
import path from "node:path";
import { Tail } from "tail";
export function tailLog(daemonDir: string): Tail {
const log = new Tail(path.join(daemonDir, "daemon.log"));
actionsCore.debug(`tailing daemon.log...`);
log.on("line", (line) => {
actionsCore.info(line);
});
return log;
}
export async function netrcPath(): Promise<string> {
const expectedNetrcPath = path.join(
process.env["RUNNER_TEMP"] || os.tmpdir(),
"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"] || os.tmpdir(),
"magic-nix-cache-netrc",
);
try {
await flakeHubLogin(destinedNetrcPath);
} catch (e) {
actionsCore.info("FlakeHub cache disabled.");
actionsCore.debug(`Error while logging into FlakeHub: ${e}`);
}
return destinedNetrcPath;
}
}
async function flakeHubLogin(netrc: string): Promise<void> {
const jwt = await actionsCore.getIDToken("api.flakehub.com");
await fs.writeFile(
netrc,
[
`machine api.flakehub.com login flakehub password ${jwt}`,
`machine flakehub.com login flakehub password ${jwt}`,
`machine cache.flakehub.com login flakehub password ${jwt}`,
].join("\n"),
);
actionsCore.info("Logged in to FlakeHub.");
}

View file

@ -1,6 +1,7 @@
import * as core from "@actions/core";
import { IdsToolbox } from "detsys-ts";
import got from "got";
import { netrcPath, tailLog } from "./helpers.js";
import * as actionsCore from "@actions/core";
import { IdsToolbox, inputs } from "detsys-ts";
import got, { Got } from "got";
import * as http from "http";
import { SpawnOptions, exec, spawn } from "node:child_process";
import { openSync, readFileSync } from "node:fs";
@ -8,11 +9,22 @@ import * as fs from "node:fs/promises";
import * as os from "node:os";
import * as path from "node:path";
import { inspect, promisify } from "node:util";
import { Tail } from "tail";
const ENV_CACHE_DAEMONDIR = "MAGIC_NIX_CACHE_DAEMONDIR";
const gotClient = got.extend({
class MagicNixCacheAction {
idslib: IdsToolbox;
private client: Got;
constructor() {
this.idslib = new IdsToolbox({
name: "magic-nix-cache",
fetchStyle: "gh-env-style",
idsProjectName: "magic-nix-cache-closure",
requireNix: "warn",
});
this.client = got.extend({
retry: {
limit: 1,
methods: ["POST", "GET", "PUT", "HEAD", "DELETE", "OPTIONS", "TRACE"],
@ -20,47 +32,28 @@ const gotClient = got.extend({
hooks: {
beforeRetry: [
(error, retryCount) => {
core.info(`Retrying after error ${error.code}, retry #: ${retryCount}`);
actionsCore.info(
`Retrying after error ${error.code}, retry #: ${retryCount}`,
);
},
],
},
});
async function fetchAutoCacher(toolbox: IdsToolbox): Promise<string> {
const closurePath = await toolbox.fetch();
toolbox.recordEvent("load_closure");
const { stdout } = await promisify(exec)(
`cat "${closurePath}" | xz -d | nix-store --import`,
);
const paths = stdout.split(os.EOL);
// Since the export is in reverse topologically sorted order, magic-nix-cache is always the penultimate entry in the list (the empty string left by split being the last).
const last_path = paths.at(-2);
return `${last_path}/bin/magic-nix-cache`;
}
function tailLog(daemonDir: string): Tail {
const log = new Tail(path.join(daemonDir, "daemon.log"));
core.debug(`tailing daemon.log...`);
log.on("line", (line) => {
core.info(line);
});
return log;
}
}
async function setUpAutoCache(toolbox: IdsToolbox): Promise<void> {
async setUpAutoCache(): Promise<void> {
const tmpdir = process.env["RUNNER_TEMP"] || os.tmpdir();
const required_env = [
const requiredEnv = [
"ACTIONS_CACHE_URL",
"ACTIONS_RUNTIME_URL",
"ACTIONS_RUNTIME_TOKEN",
];
let anyMissing = false;
for (const n of required_env) {
for (const n of requiredEnv) {
if (!process.env.hasOwnProperty(n)) {
anyMissing = true;
core.warning(
actionsCore.warning(
`Disabling automatic caching since required environment ${n} isn't available`,
);
}
@ -70,19 +63,17 @@ async function setUpAutoCache(toolbox: IdsToolbox): Promise<void> {
return;
}
core.debug(`GitHub Action Cache URL: ${process.env["ACTIONS_CACHE_URL"]}`);
actionsCore.debug(
`GitHub Action Cache URL: ${process.env["ACTIONS_CACHE_URL"]}`,
);
const daemonDir = await fs.mkdtemp(path.join(tmpdir, "magic-nix-cache-"));
let daemonBin: string;
if (core.getInput("source-binary")) {
daemonBin = core.getInput("source-binary");
} else {
daemonBin = await fetchAutoCacher(toolbox);
}
const sourceBinary = inputs.getStringOrNull("source-binary");
const daemonBin =
sourceBinary !== null ? sourceBinary : await this.fetchAutoCacher();
let runEnv;
if (core.isDebug()) {
if (actionsCore.isDebug()) {
runEnv = {
RUST_LOG: "trace,magic_nix_cache=debug,gha_cache=debug",
RUST_BACKTRACE: "full",
@ -92,13 +83,13 @@ async function setUpAutoCache(toolbox: IdsToolbox): Promise<void> {
runEnv = process.env;
}
const notifyPort = core.getInput("startup-notification-port");
const notifyPort = inputs.getString("startup-notification-port");
const notifyPromise = new Promise<Promise<void>>((resolveListening) => {
const promise = new Promise<void>(async (resolveQuit) => {
const notifyServer = http.createServer((req, res) => {
if (req.method === "POST" && req.url === "/") {
core.debug(`Notify server shutting down.`);
actionsCore.debug(`Notify server shutting down.`);
res.writeHead(200, { "Content-Type": "application/json" });
res.end("{}");
notifyServer.close(() => {
@ -108,7 +99,7 @@ async function setUpAutoCache(toolbox: IdsToolbox): Promise<void> {
});
notifyServer.listen(notifyPort, () => {
core.debug(`Notify server running.`);
actionsCore.debug(`Notify server running.`);
resolveListening(promise);
});
});
@ -121,34 +112,43 @@ async function setUpAutoCache(toolbox: IdsToolbox): Promise<void> {
const netrc = await netrcPath();
const nixConfPath = `${process.env["HOME"]}/.config/nix/nix.conf`;
const hostAndPort = inputs.getString("listen");
const upstreamCache = inputs.getString("upstream-cache");
const diagnosticEndpoint = inputs.getString("diagnostic-endpoint");
const useFlakeHub = inputs.getBool("use-flakehub");
const flakeHubCacheServer = inputs.getString("flakehub-cache-server");
const flakeHubApiServer = inputs.getString("flakehub-api-server");
const flakeHubFlakeName = inputs.getString("flakehub-flake-name");
const useGhaCache = inputs.getBool("use-gha-cache");
const daemonCliFlags: string[] = [
"--startup-notification-url",
`http://127.0.0.1:${notifyPort}`,
"--listen",
core.getInput("listen"),
hostAndPort,
"--upstream",
core.getInput("upstream-cache"),
upstreamCache,
"--diagnostic-endpoint",
core.getInput("diagnostic-endpoint"),
diagnosticEndpoint,
"--nix-conf",
nixConfPath,
]
.concat(
core.getBooleanInput("use-flakehub")
useFlakeHub
? [
"--use-flakehub",
"--flakehub-cache-server",
core.getInput("flakehub-cache-server"),
flakeHubCacheServer,
"--flakehub-api-server",
core.getInput("flakehub-api-server"),
flakeHubApiServer,
"--flakehub-api-server-netrc",
netrc,
"--flakehub-flake-name",
core.getInput("flakehub-flake-name"),
flakeHubFlakeName,
]
: [],
)
.concat(core.getBooleanInput("use-gha-cache") ? ["--use-gha-cache"] : []);
.concat(useGhaCache ? ["--use-gha-cache"] : []);
const opts: SpawnOptions = {
stdio: ["ignore", output, output],
@ -157,8 +157,8 @@ async function setUpAutoCache(toolbox: IdsToolbox): Promise<void> {
};
// Display the final command for debugging purposes
core.debug("Full daemon start command:");
core.debug(`${daemonBin} ${daemonCliFlags.join(" ")}`);
actionsCore.debug("Full daemon start command:");
actionsCore.debug(`${daemonBin} ${daemonCliFlags.join(" ")}`);
// Start the server. Once it is ready, it will notify us via the notification server.
const daemon = spawn(daemonBin, daemonCliFlags, opts);
@ -166,7 +166,7 @@ async function setUpAutoCache(toolbox: IdsToolbox): Promise<void> {
const pidFile = path.join(daemonDir, "daemon.pid");
await fs.writeFile(pidFile, `${daemon.pid}`);
core.info("Waiting for magic-nix-cache to start...");
actionsCore.info("Waiting for magic-nix-cache to start...");
await new Promise<void>((resolve, reject) => {
notifyPromise
@ -191,13 +191,26 @@ async function setUpAutoCache(toolbox: IdsToolbox): Promise<void> {
daemon.unref();
core.info("Launched Magic Nix Cache");
core.exportVariable(ENV_CACHE_DAEMONDIR, daemonDir);
actionsCore.info("Launched Magic Nix Cache");
actionsCore.exportVariable(ENV_CACHE_DAEMONDIR, daemonDir);
log.unwatch();
}
}
async function notifyAutoCache(): Promise<void> {
private async fetchAutoCacher(): Promise<string> {
const closurePath = await this.idslib.fetch();
this.idslib.recordEvent("load_closure");
const { stdout } = await promisify(exec)(
`cat "${closurePath}" | xz -d | nix-store --import`,
);
const paths = stdout.split(os.EOL);
// Since the export is in reverse topologically sorted order, magic-nix-cache is always the penultimate entry in the list (the empty string left by split being the last).
const lastPath = paths.at(-2);
return `${lastPath}/bin/magic-nix-cache`;
}
async notifyAutoCache(): Promise<void> {
const daemonDir = process.env[ENV_CACHE_DAEMONDIR];
if (!daemonDir) {
@ -205,68 +218,30 @@ async function notifyAutoCache(): Promise<void> {
}
try {
core.debug(`Indicating workflow start`);
const res: Response = await gotClient
.post(`http://${core.getInput("listen")}/api/workflow-start`)
actionsCore.debug(`Indicating workflow start`);
const hostAndPort = inputs.getString("listen");
const res: Response = await this.client
.post(`http://${hostAndPort}/api/workflow-start`)
.json();
core.debug(`back from post: ${res}`);
actionsCore.debug(`back from post: ${res}`);
} catch (e) {
core.info(`Error marking the workflow as started:`);
core.info(inspect(e));
core.info(`Magic Nix Cache may not be running for this workflow.`);
actionsCore.info(`Error marking the workflow as started:`);
actionsCore.info(inspect(e));
actionsCore.info(`Magic Nix Cache may not be running for this workflow.`);
}
}
async function netrcPath(): Promise<string> {
const expectedNetrcPath = path.join(
process.env["RUNNER_TEMP"] || os.tmpdir(),
"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"] || os.tmpdir(),
"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): Promise<void> {
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}`,
`machine cache.flakehub.com login flakehub password ${jwt}`,
].join("\n"),
);
core.info("Logged in to FlakeHub.");
}
async function tearDownAutoCache(): Promise<void> {
async tearDownAutoCache(): Promise<void> {
const daemonDir = process.env[ENV_CACHE_DAEMONDIR];
if (!daemonDir) {
core.debug("magic-nix-cache not started - Skipping");
actionsCore.debug("magic-nix-cache not started - Skipping");
return;
}
const pidFile = path.join(daemonDir, "daemon.pid");
const pid = parseInt(await fs.readFile(pidFile, { encoding: "ascii" }));
core.debug(`found daemon pid: ${pid}`);
actionsCore.debug(`found daemon pid: ${pid}`);
if (!pid) {
throw new Error("magic-nix-cache did not start successfully");
}
@ -274,17 +249,18 @@ async function tearDownAutoCache(): Promise<void> {
const log = tailLog(daemonDir);
try {
core.debug(`about to post to localhost`);
const res: Response = await gotClient
.post(`http://${core.getInput("listen")}/api/workflow-finish`)
actionsCore.debug(`about to post to localhost`);
const hostAndPort = inputs.getString("listen");
const res: Response = await this.client
.post(`http://${hostAndPort}/api/workflow-finish`)
.json();
core.debug(`back from post: ${res}`);
actionsCore.debug(`back from post: ${res}`);
} finally {
core.debug(`unwatching the daemon log`);
actionsCore.debug(`unwatching the daemon log`);
log.unwatch();
}
core.debug(`killing`);
actionsCore.debug(`killing`);
try {
process.kill(pid, "SIGTERM");
} catch (e) {
@ -292,27 +268,27 @@ async function tearDownAutoCache(): Promise<void> {
throw e;
}
} finally {
if (core.isDebug()) {
core.info("Entire log:");
if (actionsCore.isDebug()) {
actionsCore.info("Entire log:");
const entireLog = readFileSync(path.join(daemonDir, "daemon.log"));
core.info(entireLog.toString());
actionsCore.info(entireLog.toString());
}
}
}
}
const idslib = new IdsToolbox({
name: "magic-nix-cache",
fetchStyle: "gh-env-style",
idsProjectName: "magic-nix-cache-closure",
requireNix: "warn",
});
function main(): void {
const cacheAction = new MagicNixCacheAction();
idslib.onMain(async () => {
await setUpAutoCache(idslib);
await notifyAutoCache();
});
idslib.onPost(async () => {
await tearDownAutoCache();
});
cacheAction.idslib.onMain(async () => {
await cacheAction.setUpAutoCache();
await cacheAction.notifyAutoCache();
});
cacheAction.idslib.onPost(async () => {
await cacheAction.tearDownAutoCache();
});
idslib.execute();
cacheAction.idslib.execute();
}
main();