-
Notifications
You must be signed in to change notification settings - Fork 0
[INTT-39] feat: dart workflow #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 { }); | ||
| }; | ||
| }); | ||
| } |
| 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" '' | ||
| 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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
| }; | ||
| } | ||
| 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 { }); | ||
| }; | ||
| }); | ||
| } |
| 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: '' | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
| }; | ||
| }; | ||
| }; | ||
| } | ||
There was a problem hiding this comment.
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.