forked from Mirror/attic-action
Compare commits
19 commits
Author | SHA1 | Date | |
---|---|---|---|
6544c41112 | |||
80432ea2ff | |||
31f177f66d | |||
81793b07ae | |||
5121b742ce | |||
fe7e4e104a | |||
54b0d06fc7 | |||
|
5619ef4781 | ||
|
37f74ba5fa | ||
|
6cfb1137df | ||
|
f75ac4b827 | ||
|
6689ac7697 | ||
|
4698511c85 | ||
|
7f0e30fedd | ||
|
40fa276ac0 | ||
|
fae7bd1d97 | ||
|
aa6bedf232 | ||
|
6870271f1d | ||
|
ce977ffab4 |
16 changed files with 91 additions and 137 deletions
25
.forgejo/workflows/test.yml
Normal file
25
.forgejo/workflows/test.yml
Normal file
|
@ -0,0 +1,25 @@
|
|||
name: "Test"
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: ["main"]
|
||||
workflow_call:
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
test-cache:
|
||||
runs-on: nix-flakes
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Attic Cache
|
||||
uses: ./
|
||||
with:
|
||||
endpoint: ${{ vars.ATTIC_ENDPOINT }}
|
||||
cache: ${{ vars.ATTIC_CACHE }}
|
||||
token: ${{ secrets.ATTIC_TOKEN }}
|
||||
|
||||
- name: Build Nix Package
|
||||
run: nix-build test.nix
|
7
.github/dependabot.yml
vendored
7
.github/dependabot.yml
vendored
|
@ -1,7 +0,0 @@
|
|||
version: 2
|
||||
|
||||
updates:
|
||||
- package-ecosystem: "github-actions"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "weekly"
|
30
.github/workflows/release.yml
vendored
30
.github/workflows/release.yml
vendored
|
@ -1,30 +0,0 @@
|
|||
name: Release
|
||||
|
||||
on:
|
||||
release:
|
||||
types: [published, edited]
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
jobs:
|
||||
release:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
ref: ${{ github.event.release.tag_name }}
|
||||
|
||||
- uses: pnpm/action-setup@v2
|
||||
- uses: actions/setup-node@v3
|
||||
with:
|
||||
cache: pnpm
|
||||
cache-dependency-path: pnpm-lock.yaml
|
||||
|
||||
- name: Build
|
||||
run: pnpm install && pnpm build
|
||||
|
||||
- uses: JasonEtco/build-and-tag-action@v2
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ github.token }}
|
41
.github/workflows/test.yml
vendored
41
.github/workflows/test.yml
vendored
|
@ -1,41 +0,0 @@
|
|||
name: "Test"
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: ["main"]
|
||||
workflow_call:
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
test-cache:
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, macos-latest]
|
||||
|
||||
runs-on: ${{ matrix.os }}
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- uses: pnpm/action-setup@v2
|
||||
- uses: actions/setup-node@v3
|
||||
with:
|
||||
cache: pnpm
|
||||
cache-dependency-path: pnpm-lock.yaml
|
||||
|
||||
- name: Build
|
||||
run: pnpm install && pnpm build
|
||||
|
||||
- name: Install Nix
|
||||
uses: cachix/install-nix-action@v23
|
||||
|
||||
- name: Setup Attic Cache
|
||||
uses: ./
|
||||
with:
|
||||
endpoint: ${{ secrets.ATTIC_ENDPOINT }}
|
||||
cache: ${{ secrets.ATTIC_CACHE }}
|
||||
token: ${{ secrets.ATTIC_TOKEN }}
|
||||
|
||||
- name: Build Nix Package
|
||||
run: nix build --impure --show-trace -L .#test
|
|
@ -1 +1 @@
|
|||
16
|
||||
20
|
||||
|
|
|
@ -24,6 +24,6 @@ inputs:
|
|||
required: false
|
||||
|
||||
runs:
|
||||
using: "node16"
|
||||
using: "node20"
|
||||
main: "dist/index.js"
|
||||
post: "dist/index.js"
|
||||
|
|
8
dist/index.js
vendored
Normal file
8
dist/index.js
vendored
Normal file
File diff suppressed because one or more lines are too long
33
flake.nix
33
flake.nix
|
@ -6,36 +6,25 @@
|
|||
};
|
||||
|
||||
outputs = {nixpkgs, ...}: let
|
||||
mkSystems = sys: builtins.map (arch: "${arch}-${sys}") ["x86_64" "aarch64"];
|
||||
systems =
|
||||
mkSystems "linux"
|
||||
++ mkSystems "darwin";
|
||||
systems = [
|
||||
"x86_64-linux"
|
||||
"aarch64-linux"
|
||||
"x86_64-darwin"
|
||||
"aarch64-darwin"
|
||||
];
|
||||
|
||||
forAllSystems = nixpkgs.lib.genAttrs systems;
|
||||
nixpkgsFor = forAllSystems (system: import nixpkgs {inherit system;});
|
||||
|
||||
forEachSystem = fn:
|
||||
forAllSystems (s: fn nixpkgsFor.${s});
|
||||
forAllSystems = fn: nixpkgs.lib.genAttrs systems (system: fn nixpkgs.legacyPackages.${system});
|
||||
in {
|
||||
devShells = forEachSystem (pkgs: {
|
||||
devShells = forAllSystems (pkgs: {
|
||||
default = pkgs.mkShell {
|
||||
packages = with pkgs; [
|
||||
actionlint
|
||||
nodePackages.pnpm
|
||||
nodejs_20
|
||||
(nodePackages_latest.pnpm.override {nodejs = nodejs_20;})
|
||||
];
|
||||
};
|
||||
});
|
||||
|
||||
formatter = forEachSystem (p: p.alejandra);
|
||||
|
||||
packages = forEachSystem (p: let
|
||||
time = toString builtins.currentTime;
|
||||
test = p.runCommand "test-${time}" {} ''
|
||||
echo ${time} > $out
|
||||
'';
|
||||
in {
|
||||
inherit test;
|
||||
default = test;
|
||||
});
|
||||
formatter = forAllSystems (p: p.alejandra);
|
||||
};
|
||||
}
|
||||
|
|
|
@ -11,8 +11,7 @@
|
|||
"dependencies": {
|
||||
"@actions/core": "^1.10.0",
|
||||
"@actions/exec": "^1.1.1",
|
||||
"just-split": "^3.2.0",
|
||||
"ofetch": "^1.1.1"
|
||||
"just-split": "^3.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^16.18.38",
|
||||
|
@ -20,5 +19,5 @@
|
|||
"prettier": "3.0.0",
|
||||
"typescript": "^5.1.6"
|
||||
},
|
||||
"packageManager": "pnpm@8.6.9"
|
||||
"packageManager": "pnpm@8.7.5"
|
||||
}
|
||||
|
|
23
pnpm-lock.yaml
generated
23
pnpm-lock.yaml
generated
|
@ -14,9 +14,6 @@ dependencies:
|
|||
just-split:
|
||||
specifier: ^3.2.0
|
||||
version: 3.2.0
|
||||
ofetch:
|
||||
specifier: ^1.1.1
|
||||
version: 1.1.1
|
||||
|
||||
devDependencies:
|
||||
'@types/node':
|
||||
|
@ -259,10 +256,6 @@ packages:
|
|||
resolution: {integrity: sha512-6sfo1qTulpVbkxECP+AVrHV9OoJqhzCsfTNp5NIG+enM4HyM3HvZCO798WShIXBN0+QtDIcutJCjsVYnQP5rIQ==}
|
||||
dev: true
|
||||
|
||||
/destr@2.0.0:
|
||||
resolution: {integrity: sha512-FJ9RDpf3GicEBvzI3jxc2XhHzbqD8p4ANw/1kPsFBfTvP1b7Gn/Lg1vO7R9J4IVgoMbyUmFrFGZafJ1hPZpvlg==}
|
||||
dev: false
|
||||
|
||||
/esbuild@0.18.14:
|
||||
resolution: {integrity: sha512-uNPj5oHPYmj+ZhSQeYQVFZ+hAlJZbAGOmmILWIqrGvPVlNLbyOvU5Bu6Woi8G8nskcx0vwY0iFoMPrzT86Ko+w==}
|
||||
engines: {node: '>=12'}
|
||||
|
@ -297,18 +290,6 @@ packages:
|
|||
resolution: {integrity: sha512-hh57dN5koTBkmg3T6gBFISVVaW5bgZ6Ct1W5KODD5M7hQJKqGzTKkfMwOil8MBxyztLQEjh/v6UGXE8cP5tnqQ==}
|
||||
dev: false
|
||||
|
||||
/node-fetch-native@1.2.0:
|
||||
resolution: {integrity: sha512-5IAMBTl9p6PaAjYCnMv5FmqIF6GcZnawAVnzaCG0rX2aYZJ4CxEkZNtVPuTRug7fL7wyM5BQYTlAzcyMPi6oTQ==}
|
||||
dev: false
|
||||
|
||||
/ofetch@1.1.1:
|
||||
resolution: {integrity: sha512-SSMoktrp9SNLi20BWfB/BnnKcL0RDigXThD/mZBeQxkIRv1xrd9183MtLdsqRYLYSqW0eTr5t8w8MqjNhvoOQQ==}
|
||||
dependencies:
|
||||
destr: 2.0.0
|
||||
node-fetch-native: 1.2.0
|
||||
ufo: 1.1.2
|
||||
dev: false
|
||||
|
||||
/prettier@3.0.0:
|
||||
resolution: {integrity: sha512-zBf5eHpwHOGPC47h0zrPyNn+eAEIdEzfywMoYn2XPi0P44Zp0tSq64rq0xAREh4auw2cJZHo9QUob+NqCQky4g==}
|
||||
engines: {node: '>=14'}
|
||||
|
@ -326,10 +307,6 @@ packages:
|
|||
hasBin: true
|
||||
dev: true
|
||||
|
||||
/ufo@1.1.2:
|
||||
resolution: {integrity: sha512-TrY6DsjTQQgyS3E3dBaOXf0TpPD8u9FVrVYmKVegJuFw51n/YB9XPt+U6ydzFG5ZIN7+DIjPbNmXoBj9esYhgQ==}
|
||||
dev: false
|
||||
|
||||
/uuid@8.3.2:
|
||||
resolution: {integrity: sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==}
|
||||
hasBin: true
|
||||
|
|
10
src/index.ts
10
src/index.ts
|
@ -1,12 +1,16 @@
|
|||
import { install } from "./stages/install";
|
||||
import { install, isInstalled } from "./stages/install";
|
||||
import { configure } from "./stages/configure";
|
||||
import { push } from "./stages/push";
|
||||
import { getState, saveState } from "@actions/core";
|
||||
import { getState, saveState, info } from "@actions/core";
|
||||
|
||||
const isPost = !!getState("isPost");
|
||||
|
||||
const main = async () => {
|
||||
await install();
|
||||
if (await isInstalled()) {
|
||||
info("Skipping attic installation because it is already installed");
|
||||
} else {
|
||||
await install();
|
||||
}
|
||||
await configure();
|
||||
};
|
||||
|
||||
|
|
|
@ -15,10 +15,10 @@ export const configure = async () => {
|
|||
await exec("attic", ["login", "--set-default", cache, endpoint, token]);
|
||||
|
||||
if (skipUse === "true") {
|
||||
core.info('Not adding attic cache to substituters as skip-use is set to true');
|
||||
core.info("Not adding attic cache to substituters as skip-use is set to true");
|
||||
} else {
|
||||
core.info("Adding attic cache to substituters");
|
||||
await exec.exec('attic', ['use', cache]);
|
||||
await exec("attic", ["use", cache]);
|
||||
}
|
||||
|
||||
core.info("Collecting store paths before build");
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import * as core from "@actions/core";
|
||||
import { exec } from "@actions/exec";
|
||||
import { fetch } from "ofetch";
|
||||
|
||||
import { writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
|
@ -34,3 +33,9 @@ export const install = async () => {
|
|||
|
||||
core.endGroup();
|
||||
};
|
||||
|
||||
export const isInstalled = async () => {
|
||||
let return_code = await exec("attic", ["-V"]);
|
||||
core.info(`Attic command returned code ${return_code}`);
|
||||
return return_code === 0;
|
||||
};
|
||||
|
|
|
@ -3,17 +3,20 @@ import { exec } from "@actions/exec";
|
|||
|
||||
import splitArray from "just-split";
|
||||
import { saveStorePaths, getStorePaths } from "../utils";
|
||||
|
||||
export const push = async () => {
|
||||
core.startGroup("Push to Attic");
|
||||
|
||||
try {
|
||||
const skipPush = core.getInput("skip-push");
|
||||
|
||||
if (skipPush === "true") {
|
||||
core.info("Pushing to cache is disabled by skip-push");
|
||||
} else {
|
||||
const cache = core.getInput("cache");
|
||||
|
||||
core.info("Pushing to cache");
|
||||
|
||||
const oldPaths = await getStorePaths();
|
||||
await saveStorePaths();
|
||||
const newPaths = await getStorePaths();
|
||||
|
@ -29,7 +32,8 @@ export const push = async () => {
|
|||
}
|
||||
}
|
||||
} catch (e) {
|
||||
core.setFailed(`Action failed with error: ${e}`);
|
||||
core.warning(`Action encountered error: ${e}`);
|
||||
core.info("Not considering errors during push a failure.");
|
||||
}
|
||||
|
||||
core.endGroup();
|
||||
|
|
11
src/utils.ts
11
src/utils.ts
|
@ -3,8 +3,15 @@ import { exec } from "@actions/exec";
|
|||
import { readFile } from "node:fs/promises";
|
||||
|
||||
export const saveStorePaths = async () => {
|
||||
await exec("sh", ["-c", "nix path-info --all --json > /tmp/store-paths"]);
|
||||
await exec("sh", ["-c", "nix path-info --all --json > /tmp/store-paths"]);
|
||||
};
|
||||
export const getStorePaths = async () => {
|
||||
return JSON.parse(await readFile("/tmp/store-paths", "utf8")).map((path) => path.path);
|
||||
const rawStorePaths = JSON.parse(await readFile("/tmp/store-paths", "utf8")) as { path: string }[];
|
||||
|
||||
// compatibility with Nix 2.18
|
||||
if (Array.isArray(rawStorePaths)) {
|
||||
return rawStorePaths.map((path) => path.path);
|
||||
};
|
||||
|
||||
return Object.keys(rawStorePaths);
|
||||
};
|
||||
|
|
14
test.nix
Normal file
14
test.nix
Normal file
|
@ -0,0 +1,14 @@
|
|||
let
|
||||
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
|
||||
pkgs = import (
|
||||
fetchTarball {
|
||||
url =
|
||||
lock.nodes.nixpkgs.locked.url
|
||||
or "https://github.com/NixOS/nixpkgs/archive/${lock.nodes.nixpkgs.locked.rev}.tar.gz";
|
||||
sha256 = lock.nodes.nixpkgs.locked.narHash;
|
||||
}
|
||||
) {};
|
||||
in
|
||||
pkgs.runCommand "non-reproducible-test" {} ''
|
||||
echo ${toString builtins.currentTime} > $out
|
||||
''
|
Loading…
Add table
Add a link
Reference in a new issue