mirror of
https://github.com/DeterminateSystems/flake-checker-action.git
synced 2025-04-28 07:22:04 +02:00
Switch to a typescript based action
This commit is contained in:
parent
17d9279de7
commit
5bdec97993
18 changed files with 99582 additions and 84 deletions
73
.eslintrc.json
Normal file
73
.eslintrc.json
Normal file
|
@ -0,0 +1,73 @@
|
|||
{
|
||||
"plugins": ["@typescript-eslint"],
|
||||
"extends": ["plugin:github/recommended"],
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 9,
|
||||
"sourceType": "module",
|
||||
"project": "./tsconfig.json"
|
||||
},
|
||||
"settings": {
|
||||
"import/resolver": {
|
||||
"typescript": {}
|
||||
}
|
||||
},
|
||||
"rules": {
|
||||
"i18n-text/no-en": "off",
|
||||
"eslint-comments/no-use": "off",
|
||||
"import/no-namespace": "off",
|
||||
"no-unused-vars": "off",
|
||||
"@typescript-eslint/no-unused-vars": [
|
||||
"error",
|
||||
{
|
||||
"argsIgnorePattern": "^_"
|
||||
}
|
||||
],
|
||||
"@typescript-eslint/explicit-member-accessibility": [
|
||||
"error",
|
||||
{
|
||||
"accessibility": "no-public"
|
||||
}
|
||||
],
|
||||
"@typescript-eslint/no-require-imports": "error",
|
||||
"@typescript-eslint/array-type": "error",
|
||||
"@typescript-eslint/await-thenable": "error",
|
||||
"@typescript-eslint/ban-ts-comment": "error",
|
||||
"camelcase": "off",
|
||||
"@typescript-eslint/consistent-type-assertions": "error",
|
||||
"@typescript-eslint/explicit-function-return-type": [
|
||||
"error",
|
||||
{
|
||||
"allowExpressions": true
|
||||
}
|
||||
],
|
||||
"@typescript-eslint/func-call-spacing": ["error", "never"],
|
||||
"@typescript-eslint/no-array-constructor": "error",
|
||||
"@typescript-eslint/no-empty-interface": "error",
|
||||
"@typescript-eslint/no-explicit-any": "error",
|
||||
"@typescript-eslint/no-floating-promises": "error",
|
||||
"@typescript-eslint/no-extraneous-class": "error",
|
||||
"@typescript-eslint/no-for-in-array": "error",
|
||||
"@typescript-eslint/no-inferrable-types": "error",
|
||||
"@typescript-eslint/no-misused-new": "error",
|
||||
"@typescript-eslint/no-namespace": "error",
|
||||
"@typescript-eslint/no-non-null-assertion": "warn",
|
||||
"@typescript-eslint/no-unnecessary-qualifier": "error",
|
||||
"@typescript-eslint/no-unnecessary-type-assertion": "error",
|
||||
"@typescript-eslint/no-useless-constructor": "error",
|
||||
"@typescript-eslint/no-var-requires": "error",
|
||||
"@typescript-eslint/prefer-for-of": "warn",
|
||||
"@typescript-eslint/prefer-function-type": "warn",
|
||||
"@typescript-eslint/prefer-includes": "error",
|
||||
"@typescript-eslint/prefer-string-starts-ends-with": "error",
|
||||
"@typescript-eslint/promise-function-async": "error",
|
||||
"@typescript-eslint/require-array-sort-compare": "error",
|
||||
"@typescript-eslint/restrict-plus-operands": "error",
|
||||
"@typescript-eslint/type-annotation-spacing": "error",
|
||||
"@typescript-eslint/unbound-method": "error"
|
||||
},
|
||||
"env": {
|
||||
"node": true,
|
||||
"es6": true
|
||||
}
|
||||
}
|
2
.gitattributes
vendored
Normal file
2
.gitattributes
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
dist/* linguist-generated=true
|
||||
|
26
.github/workflows/ci.yaml
vendored
26
.github/workflows/ci.yaml
vendored
|
@ -6,11 +6,29 @@ on:
|
|||
branches: [main]
|
||||
|
||||
jobs:
|
||||
check-dist-up-to-date:
|
||||
name: Check the dist/ folder is up to date
|
||||
runs-on: ubuntu-22.04
|
||||
permissions:
|
||||
contents: read
|
||||
id-token: write
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: DeterminateSystems/nix-installer-action@main
|
||||
- uses: DeterminateSystems/magic-nix-cache-action@main
|
||||
- run: nix develop --command pnpm install
|
||||
- run: nix develop --command pnpm run format
|
||||
- run: nix develop --command pnpm run lint
|
||||
- run: nix develop --command pnpm run build
|
||||
- run: nix develop --command pnpm run package
|
||||
- run: git status --porcelain=v1
|
||||
- run: test $(git status --porcelain=v1 2>/dev/null | wc -l) -eq 0
|
||||
|
||||
run-x86_64-linux-clean:
|
||||
name: Run x86_64 Linux (clean)
|
||||
runs-on: ubuntu-22.04
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
- name: Check flake.lock
|
||||
uses: ./
|
||||
|
||||
|
@ -18,7 +36,7 @@ jobs:
|
|||
name: Run x86_64 Linux (dirty)
|
||||
runs-on: ubuntu-22.04
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
- name: Check flake.lock
|
||||
uses: ./
|
||||
with:
|
||||
|
@ -28,7 +46,7 @@ jobs:
|
|||
name: Run x86_64 Darwin (clean)
|
||||
runs-on: macos-12
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
- name: Check flake.lock
|
||||
uses: ./
|
||||
|
||||
|
@ -36,7 +54,7 @@ jobs:
|
|||
name: Run x86_64 Darwin (dirty)
|
||||
runs-on: macos-12
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
- name: Check flake.lock
|
||||
uses: ./
|
||||
with:
|
||||
|
|
101
.gitignore
vendored
Normal file
101
.gitignore
vendored
Normal file
|
@ -0,0 +1,101 @@
|
|||
# Dependency directory
|
||||
node_modules
|
||||
|
||||
# Rest pulled from https://github.com/github/gitignore/blob/master/Node.gitignore
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
lerna-debug.log*
|
||||
|
||||
# Diagnostic reports (https://nodejs.org/api/report.html)
|
||||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
*.pid.lock
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
lib-cov
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
*.lcov
|
||||
|
||||
# nyc test coverage
|
||||
.nyc_output
|
||||
|
||||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
||||
.grunt
|
||||
|
||||
# Bower dependency directory (https://bower.io/)
|
||||
bower_components
|
||||
|
||||
# node-waf configuration
|
||||
.lock-wscript
|
||||
|
||||
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||
build/Release
|
||||
|
||||
# Dependency directories
|
||||
jspm_packages/
|
||||
|
||||
# TypeScript v1 declaration files
|
||||
typings/
|
||||
|
||||
# TypeScript cache
|
||||
*.tsbuildinfo
|
||||
|
||||
# Optional npm cache directory
|
||||
.npm
|
||||
|
||||
# Optional eslint cache
|
||||
.eslintcache
|
||||
|
||||
# Optional REPL history
|
||||
.node_repl_history
|
||||
|
||||
# Output of 'npm pack'
|
||||
*.tgz
|
||||
|
||||
# Yarn Integrity file
|
||||
.yarn-integrity
|
||||
|
||||
# dotenv environment variables file
|
||||
.env
|
||||
.env.test
|
||||
|
||||
# parcel-bundler cache (https://parceljs.org/)
|
||||
.cache
|
||||
|
||||
# next.js build output
|
||||
.next
|
||||
|
||||
# nuxt.js build output
|
||||
.nuxt
|
||||
|
||||
# vuepress build output
|
||||
.vuepress/dist
|
||||
|
||||
# Serverless directories
|
||||
.serverless/
|
||||
|
||||
# FuseBox cache
|
||||
.fusebox/
|
||||
|
||||
# DynamoDB Local files
|
||||
.dynamodb/
|
||||
|
||||
# OS metadata
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
|
||||
# Ignore built ts files
|
||||
__tests__/runner/*
|
||||
lib/**/*
|
||||
|
||||
.direnv
|
3
.prettierignore
Normal file
3
.prettierignore
Normal file
|
@ -0,0 +1,3 @@
|
|||
dist/
|
||||
lib/
|
||||
node_modules/
|
1
.prettierrc.json
Normal file
1
.prettierrc.json
Normal file
|
@ -0,0 +1 @@
|
|||
{}
|
27
README.md
27
README.md
|
@ -3,9 +3,9 @@
|
|||
This repo houses a [Github Action][action] from [Determinate Systems][detsys] that performs health checks on your repos' [`flake.lock`][lock] files.
|
||||
Specifically, it wraps the [Nix Flake Checker][flake-checker] tool, which verifies that your root [Nixpkgs] inputs:
|
||||
|
||||
* Have been updated within the last 30 days
|
||||
* Have the [`NixOS`][nixos-org] GitHub org as their owner
|
||||
* Are from a supported Git branch
|
||||
- Have been updated within the last 30 days
|
||||
- Have the [`NixOS`][nixos-org] GitHub org as their owner
|
||||
- Are from a supported Git branch
|
||||
|
||||
Here's an example configuration that uses `flake-checker-action` as part of a broader Actions workflow involving Nix.
|
||||
|
||||
|
@ -33,16 +33,16 @@ jobs:
|
|||
|
||||
The Nix Flake Checker Action has a number of configuration parameters that you can set in the `with` block:
|
||||
|
||||
Parameter | Description | Default
|
||||
:---------|:------------|:-------
|
||||
`flake-lock-path` | The path to the `flake.lock` file you want to check. | `flake.lock`
|
||||
`check-outdated` | Whether to check that the root Nixpkgs input is less than 30 days old. | `true`
|
||||
`check-owner` | Whether to check that the root Nixpkgs input has the `NixOS` GitHub org as its owner. | `true`
|
||||
`check-supported` | Whether to check that the root Nixpkgs input has a supported Git ref. Currently supported refs: `nixos-22.11`, `nixos-22.11-small`, `nixos-23.05`, `nixos-23.05-small`, `nixos-unstable`, `nixos-unstable-small`, `nixpkgs-22.11-darwin`, `nixpkgs-23.05-darwin`, `nixpkgs-unstable`. | `true`
|
||||
`nixpkgs-keys` | The names of the Nixpkgs inputs you want to check. By default the checker only checks the `nixpkgs` but you can specify multiple names as a comma-separated list, such as `nixpkgs,nixpkgs-macos,nixpkgs-unstable`. | `nixpkgs`
|
||||
`ignore-missing-flake-lock` | Whether to ignore a missing `flake.lock` file, where the path to the file is the value of `flake-lock-path` parameter. If set to `false` (the default is `true`), the Action throws an error and the job fails if the lockfile is missing. | `true`
|
||||
`fail-mode` | Fail with an exit code of 1 if any issues are encountered. | `false`
|
||||
`send-statistics` | Anonymously report the number of issues detected by the flake checker. This reporting helps measure the effectiveness of the flake checker. Set to `false` to disable. | `true`
|
||||
| Parameter | Description | Default |
|
||||
| :-------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | :----------- |
|
||||
| `flake-lock-path` | The path to the `flake.lock` file you want to check. | `flake.lock` |
|
||||
| `check-outdated` | Whether to check that the root Nixpkgs input is less than 30 days old. | `true` |
|
||||
| `check-owner` | Whether to check that the root Nixpkgs input has the `NixOS` GitHub org as its owner. | `true` |
|
||||
| `check-supported` | Whether to check that the root Nixpkgs input has a supported Git ref. Currently supported refs: `nixos-22.11`, `nixos-22.11-small`, `nixos-23.05`, `nixos-23.05-small`, `nixos-unstable`, `nixos-unstable-small`, `nixpkgs-22.11-darwin`, `nixpkgs-23.05-darwin`, `nixpkgs-unstable`. | `true` |
|
||||
| `nixpkgs-keys` | The names of the Nixpkgs inputs you want to check. By default the checker only checks the `nixpkgs` but you can specify multiple names as a comma-separated list, such as `nixpkgs,nixpkgs-macos,nixpkgs-unstable`. | `nixpkgs` |
|
||||
| `ignore-missing-flake-lock` | Whether to ignore a missing `flake.lock` file, where the path to the file is the value of `flake-lock-path` parameter. If set to `false` (the default is `true`), the Action throws an error and the job fails if the lockfile is missing. | `true` |
|
||||
| `fail-mode` | Fail with an exit code of 1 if any issues are encountered. | `false` |
|
||||
| `send-statistics` | Anonymously report the number of issues detected by the flake checker. This reporting helps measure the effectiveness of the flake checker. Set to `false` to disable. | `true` |
|
||||
|
||||
Here's an example non-default configuration:
|
||||
|
||||
|
@ -62,4 +62,3 @@ Here's an example non-default configuration:
|
|||
[lock]: https://zero-to-nix.com/concepts/flakes#lockfile
|
||||
[nixos-org]: https://github.com/NixOS
|
||||
[nixpkgs]: https://github.com/NixOS/nixpkgs
|
||||
|
||||
|
|
49
action.yml
49
action.yml
|
@ -44,50 +44,5 @@ inputs:
|
|||
measure (and thereby improve) the effectiveness of the checker. Set to `false` to disable.
|
||||
default: true
|
||||
runs:
|
||||
using: composite
|
||||
steps:
|
||||
- name: Install the flake checker
|
||||
shell: bash
|
||||
run: |
|
||||
set -eu
|
||||
|
||||
curl \
|
||||
--connect-timeout 5 \
|
||||
--retry 5 \
|
||||
--retry-connrefused \
|
||||
--proto '=https' \
|
||||
--tlsv1.2 \
|
||||
-fsLS \
|
||||
https://install.determinate.systems/flake-checker/stable/$RUNNER_ARCH-$RUNNER_OS > "$RUNNER_TEMP/flake-checker"
|
||||
|
||||
chmod +x "$RUNNER_TEMP/flake-checker"
|
||||
|
||||
export NIX_FLAKE_CHECKER_FLAKE_LOCK_PATH="${{ inputs.flake-lock-path }}"
|
||||
|
||||
export NIX_FLAKE_CHECKER_NIXPKGS_KEYS="${{ inputs.nixpkgs-keys }}"
|
||||
|
||||
if [ "${{ inputs.send-statistics }}" == "false" ]; then
|
||||
export NIX_FLAKE_CHECKER_NO_TELEMETRY="false"
|
||||
fi
|
||||
|
||||
if [ "${{ inputs.check-outdated }}" == "false" ]; then
|
||||
export NIX_FLAKE_CHECKER_CHECK_OUTDATED="false"
|
||||
fi
|
||||
|
||||
if [ "${{ inputs.check-owner }}" == "false" ]; then
|
||||
export NIX_FLAKE_CHECKER_CHECK_OWNER="false"
|
||||
fi
|
||||
|
||||
if [ "${{ inputs.check-supported }}" == "false" ]; then
|
||||
export NIX_FLAKE_CHECKER_CHECK_SUPPORTED="false"
|
||||
fi
|
||||
|
||||
if [ "${{ inputs.ignore-missing-flake-lock }}" == "false" ]; then
|
||||
export NIX_FLAKE_CHECKER_IGNORE_MISSING_FLAKE_LOCK="false"
|
||||
fi
|
||||
|
||||
if [ "${{ inputs.fail-mode }}" == "true" ]; then
|
||||
export NIX_FLAKE_CHECKER_FAIL_MODE="true"
|
||||
fi
|
||||
|
||||
"$RUNNER_TEMP/flake-checker"
|
||||
using: "node20"
|
||||
main: "dist/index.js"
|
||||
|
|
94689
dist/index.js
generated
vendored
Normal file
94689
dist/index.js
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
1
dist/main.d.ts
generated
vendored
Normal file
1
dist/main.d.ts
generated
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
export {};
|
83
dist/main.js
generated
vendored
Normal file
83
dist/main.js
generated
vendored
Normal file
|
@ -0,0 +1,83 @@
|
|||
import * as actions_core from "@actions/core";
|
||||
import * as actions_exec from "@actions/exec";
|
||||
import { IdsToolbox } from "detsys-ts";
|
||||
class FlakeCheckerAction {
|
||||
constructor() {
|
||||
this.idslib = new IdsToolbox({
|
||||
name: "flake-checker",
|
||||
fetchStyle: "gh-env-style",
|
||||
});
|
||||
this.flake_lock_path =
|
||||
action_input_string_or_null("flake-lock-path") || "flake.lock";
|
||||
this.nixpkgs_keys =
|
||||
action_input_string_or_null("nixpkgs-keys") || "nixpkgs";
|
||||
this.check_outdated = action_input_bool("check-outdated");
|
||||
this.check_owner = action_input_bool("check-owner");
|
||||
this.check_supported = action_input_bool("check-supported");
|
||||
this.ignore_missing_flake_lock = action_input_bool("ignore-missing-flake-lock");
|
||||
this.fail_mode = action_input_bool("fail-mode");
|
||||
this.send_statistics = action_input_bool("send-statistics");
|
||||
}
|
||||
async executionEnvironment() {
|
||||
const execution_env = {};
|
||||
execution_env.NIX_FLAKE_CHECKER_FLAKE_LOCK_PATH = this.flake_lock_path;
|
||||
execution_env.NIX_FLAKE_CHECKER_NIXPKGS_KEYS = this.nixpkgs_keys;
|
||||
if (!this.send_statistics) {
|
||||
execution_env.NIX_FLAKE_CHECKER_NO_TELEMETRY = "false";
|
||||
}
|
||||
if (!this.check_outdated) {
|
||||
execution_env.NIX_FLAKE_CHECKER_CHECK_OUTDATED = "false";
|
||||
}
|
||||
if (!this.check_owner) {
|
||||
execution_env.NIX_FLAKE_CHECKER_CHECK_OWNER = "false";
|
||||
}
|
||||
if (!this.check_supported) {
|
||||
execution_env.NIX_FLAKE_CHECKER_CHECK_SUPPORTED = "false";
|
||||
}
|
||||
if (!this.ignore_missing_flake_lock) {
|
||||
execution_env.NIX_FLAKE_CHECKER_IGNORE_MISSING_FLAKE_LOCK = "false";
|
||||
}
|
||||
if (this.fail_mode) {
|
||||
execution_env.NIX_FLAKE_CHECKER_FAIL_MODE = "true";
|
||||
}
|
||||
return execution_env;
|
||||
}
|
||||
async check() {
|
||||
const binary_path = await this.idslib.fetchExecutable();
|
||||
const execution_env = await this.executionEnvironment();
|
||||
actions_core.debug(`Execution environment: ${JSON.stringify(execution_env, null, 4)}`);
|
||||
const exit_code = await actions_exec.exec(binary_path, [], {
|
||||
env: {
|
||||
...execution_env,
|
||||
...process.env, // To get $PATH, etc
|
||||
},
|
||||
});
|
||||
if (exit_code !== 0) {
|
||||
this.idslib.recordEvent("execution_failure", {
|
||||
exit_code,
|
||||
});
|
||||
throw new Error(`Non-zero exit code of \`${exit_code}\` detected`);
|
||||
}
|
||||
return exit_code;
|
||||
}
|
||||
}
|
||||
function action_input_string_or_null(name) {
|
||||
const value = actions_core.getInput(name);
|
||||
if (value === "") {
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
function action_input_bool(name) {
|
||||
return actions_core.getBooleanInput(name);
|
||||
}
|
||||
function main() {
|
||||
const checker = new FlakeCheckerAction();
|
||||
checker.idslib.onMain(async () => {
|
||||
await checker.check();
|
||||
});
|
||||
checker.idslib.execute();
|
||||
}
|
||||
main();
|
3
dist/package.json
generated
vendored
Normal file
3
dist/package.json
generated
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"type": "module"
|
||||
}
|
29
flake.lock
generated
29
flake.lock
generated
|
@ -1,21 +1,36 @@
|
|||
{
|
||||
"nodes": {
|
||||
"nixpkgs": {
|
||||
"flake-schemas": {
|
||||
"locked": {
|
||||
"lastModified": 1696604326,
|
||||
"narHash": "sha256-YXUNI0kLEcI5g8lqGMb0nh67fY9f2YoJsILafh6zlMo=",
|
||||
"rev": "87828a0e03d1418e848d3dd3f3014a632e4a4f64",
|
||||
"revCount": 533189,
|
||||
"lastModified": 1697467827,
|
||||
"narHash": "sha256-j8SR19V1SRysyJwpOBF4TLuAvAjF5t+gMiboN4gYQDU=",
|
||||
"rev": "764932025c817d4e500a8d2a4d8c565563923d29",
|
||||
"revCount": 29,
|
||||
"type": "tarball",
|
||||
"url": "https://api.flakehub.com/f/pinned/NixOS/nixpkgs/0.1.533189%2Brev-87828a0e03d1418e848d3dd3f3014a632e4a4f64/018b0dc8-e84f-7c59-b5d6-16849c3b2074/source.tar.gz"
|
||||
"url": "https://api.flakehub.com/f/pinned/DeterminateSystems/flake-schemas/0.1.2/018b3da8-4cc3-7fbb-8ff7-1588413c53e2/source.tar.gz"
|
||||
},
|
||||
"original": {
|
||||
"type": "tarball",
|
||||
"url": "https://flakehub.com/f/NixOS/nixpkgs/0.1.533189.tar.gz"
|
||||
"url": "https://flakehub.com/f/DeterminateSystems/flake-schemas/%2A.tar.gz"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1712791164,
|
||||
"narHash": "sha256-3sbWO1mbpWsLepZGbWaMovSO7ndZeFqDSdX0hZ9nVyw=",
|
||||
"rev": "1042fd8b148a9105f3c0aca3a6177fd1d9360ba5",
|
||||
"revCount": 610435,
|
||||
"type": "tarball",
|
||||
"url": "https://api.flakehub.com/f/pinned/NixOS/nixpkgs/0.1.610435%2Brev-1042fd8b148a9105f3c0aca3a6177fd1d9360ba5/018ed02d-7ab0-7d1c-9ebe-c075011335be/source.tar.gz"
|
||||
},
|
||||
"original": {
|
||||
"type": "tarball",
|
||||
"url": "https://flakehub.com/f/NixOS/nixpkgs/0.1.0.tar.gz"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"flake-schemas": "flake-schemas",
|
||||
"nixpkgs": "nixpkgs"
|
||||
}
|
||||
}
|
||||
|
|
31
flake.nix
31
flake.nix
|
@ -1,24 +1,31 @@
|
|||
# This flake.nix is only here to provide a flake.lock to check in CI
|
||||
# This flake was initially generated by fh, the CLI for FlakeHub (version 0.1.5)
|
||||
{
|
||||
description = "Development environment for the Flake Checker action for GitHub.";
|
||||
|
||||
inputs = {
|
||||
nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/0.1.533189.tar.gz";
|
||||
flake-schemas.url = "https://flakehub.com/f/DeterminateSystems/flake-schemas/*.tar.gz";
|
||||
nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/0.1.0.tar.gz";
|
||||
};
|
||||
|
||||
outputs = { self, nixpkgs, ... }:
|
||||
outputs = { self, flake-schemas, nixpkgs }:
|
||||
let
|
||||
supportedSystems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
|
||||
forAllSystems = f: nixpkgs.lib.genAttrs supportedSystems (system: f rec {
|
||||
supportedSystems = [ "x86_64-linux" "aarch64-darwin" "aarch64-linux" "x86_64-darwin" ];
|
||||
forEachSupportedSystem = f: nixpkgs.lib.genAttrs supportedSystems (system: f {
|
||||
pkgs = import nixpkgs { inherit system; };
|
||||
});
|
||||
in
|
||||
{
|
||||
devShells = forAllSystems ({ pkgs }: {
|
||||
default =
|
||||
pkgs.mkShell {
|
||||
packages = (with pkgs; [
|
||||
nixpkgs-fmt
|
||||
]);
|
||||
};
|
||||
schemas = flake-schemas.schemas;
|
||||
|
||||
devShells = forEachSupportedSystem ({ pkgs }: {
|
||||
default = pkgs.mkShell {
|
||||
packages = with pkgs; [
|
||||
nodejs_latest
|
||||
nixpkgs-fmt
|
||||
nodePackages_latest.pnpm
|
||||
nodePackages_latest.typescript-language-server
|
||||
];
|
||||
};
|
||||
});
|
||||
};
|
||||
}
|
||||
|
|
49
package.json
Normal file
49
package.json
Normal file
|
@ -0,0 +1,49 @@
|
|||
{
|
||||
"name": "flake-checker-action",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "./dist/main.js",
|
||||
"types": "./dist/main.d.ts",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"format": "prettier --write .",
|
||||
"lint": "eslint src/**/*.ts",
|
||||
"package": "ncc build",
|
||||
"all": "pnpm run format && pnpm run lint && pnpm run build && pnpm run package"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/DeterminateSystems/flake-checker-action.git"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/DeterminateSystems/flake-checker-action/issues"
|
||||
},
|
||||
"homepage": "https://github.com/DeterminateSystems/flake-checker-action#readme",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.10.1",
|
||||
"@actions/exec": "^1.1.1",
|
||||
"@actions/github": "^5.1.1",
|
||||
"@actions/tool-cache": "^2.0.1",
|
||||
"detsys-ts": "github:DeterminateSystems/detsys-ts",
|
||||
"fetch-retry": "^5.0.6",
|
||||
"string-argv": "^0.3.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@trivago/prettier-plugin-sort-imports": "^4.3.0",
|
||||
"@types/node": "^20.12.7",
|
||||
"@types/uuid": "^9.0.8",
|
||||
"@typescript-eslint/eslint-plugin": "^7.6.0",
|
||||
"@vercel/ncc": "^0.38.1",
|
||||
"eslint": "^8.57.0",
|
||||
"eslint-import-resolver-typescript": "^3.6.1",
|
||||
"eslint-plugin-github": "^4.10.2",
|
||||
"eslint-plugin-import": "^2.29.1",
|
||||
"eslint-plugin-prettier": "^5.1.3",
|
||||
"prettier": "^3.2.5",
|
||||
"typescript": "^5.4.5"
|
||||
}
|
||||
}
|
4350
pnpm-lock.yaml
generated
Normal file
4350
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load diff
134
src/main.ts
Normal file
134
src/main.ts
Normal file
|
@ -0,0 +1,134 @@
|
|||
import * as actions_core from "@actions/core";
|
||||
import * as actions_exec from "@actions/exec";
|
||||
import { IdsToolbox } from "detsys-ts";
|
||||
|
||||
class FlakeCheckerAction {
|
||||
idslib: IdsToolbox;
|
||||
flake_lock_path: string;
|
||||
nixpkgs_keys: string;
|
||||
check_outdated: boolean;
|
||||
check_owner: boolean;
|
||||
check_supported: boolean;
|
||||
ignore_missing_flake_lock: boolean;
|
||||
fail_mode: boolean;
|
||||
send_statistics: boolean;
|
||||
|
||||
constructor() {
|
||||
this.idslib = new IdsToolbox({
|
||||
name: "flake-checker",
|
||||
fetchStyle: "gh-env-style",
|
||||
});
|
||||
|
||||
this.flake_lock_path =
|
||||
action_input_string_or_null("flake-lock-path") || "flake.lock";
|
||||
this.nixpkgs_keys =
|
||||
action_input_string_or_null("nixpkgs-keys") || "nixpkgs";
|
||||
|
||||
this.check_outdated = action_input_bool("check-outdated");
|
||||
this.check_owner = action_input_bool("check-owner");
|
||||
this.check_supported = action_input_bool("check-supported");
|
||||
|
||||
this.ignore_missing_flake_lock = action_input_bool(
|
||||
"ignore-missing-flake-lock",
|
||||
);
|
||||
|
||||
this.fail_mode = action_input_bool("fail-mode");
|
||||
this.send_statistics = action_input_bool("send-statistics");
|
||||
}
|
||||
|
||||
private async executionEnvironment(): Promise<ExecuteEnvironment> {
|
||||
const execution_env: ExecuteEnvironment = {};
|
||||
|
||||
execution_env.NIX_FLAKE_CHECKER_FLAKE_LOCK_PATH = this.flake_lock_path;
|
||||
execution_env.NIX_FLAKE_CHECKER_NIXPKGS_KEYS = this.nixpkgs_keys;
|
||||
|
||||
if (!this.send_statistics) {
|
||||
execution_env.NIX_FLAKE_CHECKER_NO_TELEMETRY = "false";
|
||||
}
|
||||
|
||||
if (!this.check_outdated) {
|
||||
execution_env.NIX_FLAKE_CHECKER_CHECK_OUTDATED = "false";
|
||||
}
|
||||
|
||||
if (!this.check_owner) {
|
||||
execution_env.NIX_FLAKE_CHECKER_CHECK_OWNER = "false";
|
||||
}
|
||||
|
||||
if (!this.check_supported) {
|
||||
execution_env.NIX_FLAKE_CHECKER_CHECK_SUPPORTED = "false";
|
||||
}
|
||||
|
||||
if (!this.ignore_missing_flake_lock) {
|
||||
execution_env.NIX_FLAKE_CHECKER_IGNORE_MISSING_FLAKE_LOCK = "false";
|
||||
}
|
||||
|
||||
if (this.fail_mode) {
|
||||
execution_env.NIX_FLAKE_CHECKER_FAIL_MODE = "true";
|
||||
}
|
||||
|
||||
return execution_env;
|
||||
}
|
||||
|
||||
async check(): Promise<number> {
|
||||
const binary_path = await this.idslib.fetchExecutable();
|
||||
|
||||
const execution_env = await this.executionEnvironment();
|
||||
actions_core.debug(
|
||||
`Execution environment: ${JSON.stringify(execution_env, null, 4)}`,
|
||||
);
|
||||
|
||||
const exit_code = await actions_exec.exec(binary_path, [], {
|
||||
env: {
|
||||
...execution_env,
|
||||
...process.env, // To get $PATH, etc
|
||||
},
|
||||
});
|
||||
|
||||
if (exit_code !== 0) {
|
||||
this.idslib.recordEvent("execution_failure", {
|
||||
exit_code,
|
||||
});
|
||||
throw new Error(`Non-zero exit code of \`${exit_code}\` detected`);
|
||||
}
|
||||
|
||||
return exit_code;
|
||||
}
|
||||
}
|
||||
|
||||
type ExecuteEnvironment = {
|
||||
// All env vars are strings, no fanciness here.
|
||||
RUST_BACKTRACE?: string;
|
||||
NIX_FLAKE_CHECKER_FLAKE_LOCK_PATH?: string;
|
||||
NIX_FLAKE_CHECKER_NIXPKGS_KEYS?: string;
|
||||
NIX_FLAKE_CHECKER_NO_TELEMETRY?: string;
|
||||
NIX_FLAKE_CHECKER_CHECK_OUTDATED?: string;
|
||||
NIX_FLAKE_CHECKER_CHECK_OWNER?: string;
|
||||
NIX_FLAKE_CHECKER_CHECK_SUPPORTED?: string;
|
||||
NIX_FLAKE_CHECKER_IGNORE_MISSING_FLAKE_LOCK?: string;
|
||||
NIX_FLAKE_CHECKER_FAIL_MODE?: string;
|
||||
};
|
||||
|
||||
function action_input_string_or_null(name: string): string | null {
|
||||
const value = actions_core.getInput(name);
|
||||
if (value === "") {
|
||||
return null;
|
||||
} else {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
function action_input_bool(name: string): boolean {
|
||||
return actions_core.getBooleanInput(name);
|
||||
}
|
||||
|
||||
function main(): void {
|
||||
const checker = new FlakeCheckerAction();
|
||||
|
||||
checker.idslib.onMain(async () => {
|
||||
await checker.check();
|
||||
});
|
||||
|
||||
checker.idslib.execute();
|
||||
}
|
||||
|
||||
main();
|
15
tsconfig.json
Normal file
15
tsconfig.json
Normal file
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2020" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */,
|
||||
"module": "Node16",
|
||||
"moduleResolution": "NodeNext",
|
||||
"outDir": "./dist",
|
||||
"rootDir": "./src",
|
||||
"strict": true /* Enable all strict type-checking options. */,
|
||||
"noImplicitAny": true /* Raise error on expressions and declarations with an implied 'any' type. */,
|
||||
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
|
||||
"resolveJsonModule": true,
|
||||
"declaration": true
|
||||
},
|
||||
"exclude": ["node_modules", "**/*.test.ts", "dist"]
|
||||
}
|
Loading…
Add table
Reference in a new issue