Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions .config/filegen-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,31 @@
"clobber": true,
"deactivate": null,
"ignore-modification": null,
"source": "/nix/store/7lmqw9hjcp0wrrcr1fn8vgyjcpsiryns-pre-commit-config.yaml",
"source": "/nix/store/yhbigqfbyr91f9si3b6y6ib5558ddzx3-pre-commit-config.yaml",
"target": "./.pre-commit-config.yaml",
"type": "copy"
},
{
"clobber": true,
"deactivate": null,
"ignore-modification": null,
"source": "/nix/store/lai6c0kl9c0r0j1ld4j8ilrw53k3bxmq-rust-test.yml",
"source": "/nix/store/1i9xz4fis8a12qlv03ss9smrhhv8nicn-dart-test.yml",
"target": "./.github/workflows/dart-test.yml",
"type": "copy"
},
{
"clobber": true,
"deactivate": null,
"ignore-modification": null,
"source": "/nix/store/59cxdgpnmw5y43fhn7q2bcvz0jv5v9b3-rust-test.yml",
"target": "./.github/workflows/rust-test.yml",
"type": "copy"
},
{
"clobber": true,
"deactivate": null,
"ignore-modification": null,
"source": "/nix/store/glxwjx24212kdvwwwpzcqkhdzck96cvi-envrc",
"source": "/nix/store/qxl4d2ablir1lzshp9manp44nkl0328x-envrc",
"target": "./.envrc",
"type": "copy"
}
Expand Down
34 changes: 34 additions & 0 deletions nix/dart/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
flake-parts-lib,
lib,
importApply,
...
}@args:
importingFlake: {
imports = [
(importApply ./pre-commit-hooks.nix args)

./workflows/workflow.nix
];

options.perSystem = flake-parts-lib.mkPerSystemOption ({
options.famedly.standards.dart.projects = lib.mkOption {
description = ''
Dart projects in the repository that should be equipped with our
standards.

This must be a relative path starting with `.`. Simply use `.` if the
whole project is a Dart project.
'';
default = { };

example = ''
{
"." = { };
}
'';

type = lib.types.attrsOf (lib.types.submodule { });
};
});
}
84 changes: 84 additions & 0 deletions nix/dart/pre-commit-hooks.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
{
flakeModules,
inputs,
flake-parts-lib,
lib,
...
}:
importingFlake: {
config.perSystem =
{
pkgs,
config,
...
}:
let
dart = lib.getExe pkgs.dart;
grep = lib.getExe pkgs.gnugrep;

check-conventional-commits = pkgs.writeShellScript "check-conventional-commits" ''

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a general lint, not part of the dart pre-commit hooks.

Let's use a project like https://keisukeyamashita.github.io/commitlint-rs/ instead of a hand-rolled regex, too, or if we must write a shell script, use nushell.

set -eu

commit_message_file="$1"
accepted_prefixes='ci|fix|feat|chore|test|perf|refactor|style|builds|docs|revert'

if ! ${grep} -Eq "^($accepted_prefixes)(\([[:alnum:]_.-]+\))?!?: .+" "$commit_message_file"; then
echo "Commit message must start with one of: $accepted_prefixes"
exit 1
fi
'';

dart-analyze = pkgs.writeShellScript "dart-analyze" ''
set -eu

if [ -f pubspec.yaml ] && ${grep} -Eq '^flutter:' pubspec.yaml; then

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we actually need the complexity of testing for flutter vs dart projects? If we do, can we make this two separate lints instead, perhaps with an option defining which one should be used instead of doing this at runtime?

command=flutter
else
command=${dart}
fi

${dart} format lib/ --set-exit-if-changed
"$command" pub get
"$command" analyze

if command -v dart_code_metrics >/dev/null 2>&1; then
dart_code_metrics analyze lib || true
fi
Comment on lines +40 to +46

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should probably be separate hooks, not a single one.

We should not do a check for the existence of software, and instead provide it via devshell/nix store paths.

'';
in
{
prek-pre-commit.workspaces = lib.mapAttrs (name: _: {
default_language_version.dart = "system";

repos = [
{
repo = "local";
hooks = [
{
id = "check-conventional-commits";
name = "check-conventional-commits";
description = "Check commit messages follow conventional commits";

entry = "${check-conventional-commits}";

language = "system";
stages = [ "commit-msg" ];
}

{
id = "dart-analyze";
name = "dart-analyze";
description = "Run dart analyze on all targets";

entry = "${dart-analyze}";

language = "system";
types = [ "dart" ];
pass_filenames = false;
}
];
}
];
}) config.famedly.standards.dart.projects;
};
}
34 changes: 34 additions & 0 deletions nix/dart/workflows/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
flake-parts-lib,
lib,
importApply,
...
}@args:
importingFlake: {
imports = [
(importApply ./pre-commit-hooks.nix args)

./workflow.nix
];

options.perSystem = flake-parts-lib.mkPerSystemOption ({
options.famedly.standards.dart.projects = lib.mkOption {
description = ''
Dart projects in the repository that should be equipped with our
standards.

This must be a relative path starting with `.`. Simply use `.` if the
whole project is a Dart project.
'';
default = { };

example = ''
{
"." = { };
}
'';

type = lib.types.attrsOf (lib.types.submodule { });
};
});
}
56 changes: 56 additions & 0 deletions nix/dart/workflows/workflow.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{ config, lib, ... }:
let
allowed-actions = config.famedly.standards.allowed-action-versions;
in
{
perSystem =
{ config, ... }:
let
run-pre-commit = project: ''

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should do the pre-commit as a different, generic workflow, and not inside the dart-specific workflow.

nix develop .#general --command sh -c ${lib.escapeShellArg "cd ${lib.escapeShellArg project} && prek run --all-files"}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prek doesn't need project stuff, that's the entire point of using these workspaces, that should be removed. We shouldn't use a function for this at all.

'';
dart-project-steps = lib.mapAttrsToList (project: _: {
name = "Run Dart pre-commit checks (${project})";
run = run-pre-commit project;
}) config.famedly.standards.dart.projects;
in
{
githubActions.workflows.dart-test = {
name = "Dart test workflow";

on = {
push = {
branches = [ "main" ];
tags = [ "*" ];
};

pullRequest = {
branches = [ "*" ];
types = [
"opened"
"reopened"
"synchronize"
"ready_for_review"
];
};
};

concurrency = {
group = "\${{ github.workflow }}-\${{ github.ref }}";
cancelInProgress = true;
};

defaults.run.shell = "nu --no-config-file --no-history {0}";
env.DART_TERM_COLOR = "always";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this actually a thing (and necessary) or just halluci-copied from the rust workflow?


jobs.test = {
runsOn = "ubuntu-latest-4core";

steps = [
{ uses = allowed-actions."actions/checkout".uses; }
{ uses = allowed-actions."cachix/install-nix-action".uses; }
] ++ dart-project-steps;
};
};
};
}
1 change: 1 addition & 0 deletions nix/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ importingFlake: {
flakeModules.prek-pre-commit

(importApply ./general args)
(importApply ./dart args)
(importApply ./rust args)
];
}