From 5cea2de52c53331984df91813556e9944173655e Mon Sep 17 00:00:00 2001 From: Ophestra Date: Wed, 30 Sep 2026 14:09:09 +0900 Subject: internal/workflows: template common steps This removes duplicate code and significantly eases maintenance. Signed-off-by: Ophestra --- internal/workflows/release.go | 2 +- internal/workflows/step.go | 34 ++++++++++ internal/workflows/test.go | 153 ++++++------------------------------------ 3 files changed, 56 insertions(+), 133 deletions(-) create mode 100644 internal/workflows/step.go (limited to 'internal/workflows') diff --git a/internal/workflows/release.go b/internal/workflows/release.go index 8b7f30bb..6322a0e0 100644 --- a/internal/workflows/release.go +++ b/internal/workflows/release.go @@ -12,7 +12,7 @@ var _ = (&Workflow{ On: "nix", Steps: []Step{ - {Name: "Checkout", Uses: "actions/checkout@v4"}, + checkout, { Name: "Build for release", diff --git a/internal/workflows/step.go b/internal/workflows/step.go new file mode 100644 index 00000000..d09e047e --- /dev/null +++ b/internal/workflows/step.go @@ -0,0 +1,34 @@ +//go:build workflows + +package main + +// checkout is the standard actions/checkout step. +var checkout = Step{Name: "Checkout", Uses: "actions/checkout@v4"} + +// newUploadArtifact returns an actions/upload-artifact step uploading +// everything in the result directory as the specified name. +func newUploadArtifact(display, name string) Step { + return Step{ + Name: "Upload " + display, + Uses: "actions/upload-artifact@v3", + + With: Map[any]{ + {K: "name", V: name}, + {K: "path", V: "result/*"}, + + {K: "retention-days", V: 1}, + }, + } +} + +// newNixOSTest returns a step for running the named NixOS test. +func newNixOSTest(name string) Step { + return Step{ + Name: "Run NixOS test", + Run: "nix build " + + "--out-link result " + + "--print-out-paths " + + "--print-build-logs " + + "./test#checks.x86_64-linux." + name, + } +} diff --git a/internal/workflows/test.go b/internal/workflows/test.go index 1bbb04f9..a6a2abc9 100644 --- a/internal/workflows/test.go +++ b/internal/workflows/test.go @@ -12,31 +12,9 @@ var _ = (&Workflow{ On: "nix", Steps: []Step{ - { - Name: "Checkout", - Uses: "actions/checkout@v4", - }, - - { - Name: "Run NixOS test", - Run: "nix build " + - "--out-link result " + - "--print-out-paths " + - "--print-build-logs " + - "./test#checks.x86_64-linux.hakurei", - }, - - { - Name: "Upload test output", - Uses: "actions/upload-artifact@v3", - - With: Map[any]{ - {K: "name", V: "hakurei-vm-output"}, - {K: "path", V: "result/*"}, - - {K: "retention-days", V: 1}, - }, - }, + checkout, + newNixOSTest("hakurei"), + newUploadArtifact("test output", "hakurei-vm-output"), }, }}, @@ -45,28 +23,9 @@ var _ = (&Workflow{ On: "nix", Steps: []Step{ - {Name: "Checkout", Uses: "actions/checkout@v4"}, - - { - Name: "Run NixOS test", - Run: "nix build " + - "--out-link result " + - "--print-out-paths " + - "--print-build-logs " + - "./test#checks.x86_64-linux.race", - }, - - { - Name: "Upload test output", - Uses: "actions/upload-artifact@v3", - - With: Map[any]{ - {K: "name", V: "hakurei-race-vm-output"}, - {K: "path", V: "result/*"}, - - {K: "retention-days", V: 1}, - }, - }, + checkout, + newNixOSTest("race"), + newUploadArtifact("test output", "hakurei-race-vm-output"), }, }}, @@ -75,28 +34,9 @@ var _ = (&Workflow{ On: "nix", Steps: []Step{ - {Name: "Checkout", Uses: "actions/checkout@v4"}, - - { - Name: "Run NixOS test", - Run: "nix build " + - "--out-link result " + - "--print-out-paths " + - "--print-build-logs " + - "./test#checks.x86_64-linux.sandbox", - }, - - { - Name: "Upload test output", - Uses: "actions/upload-artifact@v3", - - With: Map[any]{ - {K: "name", V: "sandbox-vm-output"}, - {K: "path", V: "result/*"}, - - {K: "retention-days", V: 1}, - }, - }, + checkout, + newNixOSTest("sandbox"), + newUploadArtifact("test output", "sandbox-vm-output"), }, }}, @@ -105,28 +45,9 @@ var _ = (&Workflow{ On: "nix", Steps: []Step{ - {Name: "Checkout", Uses: "actions/checkout@v4"}, - - { - Name: "Run NixOS test", - Run: "nix build " + - "--out-link result " + - "--print-out-paths " + - "--print-build-logs " + - "./test#checks.x86_64-linux.sandbox-race", - }, - - { - Name: "Upload test output", - Uses: "actions/upload-artifact@v3", - - With: Map[any]{ - {K: "name", V: "sandbox-race-vm-output"}, - {K: "path", V: "result/*"}, - - {K: "retention-days", V: 1}, - }, - }, + checkout, + newNixOSTest("sandbox-race"), + newUploadArtifact("test output", "sandbox-race-vm-output"), }, }}, @@ -135,28 +56,9 @@ var _ = (&Workflow{ On: "nix", Steps: []Step{ - {Name: "Checkout", Uses: "actions/checkout@v4"}, - - { - Name: "Run NixOS test", - Run: "nix build " + - "--out-link result " + - "--print-out-paths " + - "--print-build-logs " + - "./test#checks.x86_64-linux.sharefs", - }, - - { - Name: "Upload test output", - Uses: "actions/upload-artifact@v3", - - With: Map[any]{ - {K: "name", V: "sharefs-vm-output"}, - {K: "path", V: "result/*"}, - - {K: "retention-days", V: 1}, - }, - }, + checkout, + newNixOSTest("sharefs"), + newUploadArtifact("test output", "sharefs-vm-output"), }, }}, @@ -173,10 +75,7 @@ var _ = (&Workflow{ }, Steps: []Step{ - { - Name: "Checkout", - Uses: "actions/checkout@v4", - }, + checkout, { Name: "Run checks", @@ -193,10 +92,7 @@ var _ = (&Workflow{ On: "nix", Steps: []Step{ - { - Name: "Checkout", - Uses: "actions/checkout@v4", - }, + checkout, { Name: "Build for test", @@ -210,17 +106,10 @@ var _ = (&Workflow{ "echo \"rev=$HAKUREI_REV\" >> $GITHUB_OUTPUT", }, - { - Name: "Upload test build", - Uses: "actions/upload-artifact@v3", - - With: Map[any]{ - {K: "name", V: "hakurei-${{ steps.build-test.outputs.rev }}"}, - {K: "path", V: "result/*"}, - - {K: "retention-days", V: 1}, - }, - }, + newUploadArtifact( + "test build", + "hakurei-${{ steps.build-test.outputs.rev }}", + ), }, }}, }, -- cgit v1.3.1