-
Notifications
You must be signed in to change notification settings - Fork 29
build: adopt Magefile for running acceptance tests #256
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
Open
mridang
wants to merge
7
commits into
main
Choose a base branch
from
build/migrate-to-magefile
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c711bff
build: adopt Magefile for running acceptance tests
mridang d42eaed
Merge branch 'main' into build/migrate-to-magefile
mridang 2c18efe
chore: upgrade ZITADEL to v4.7.0 and fix SVG format
mridang aa640ad
Merge branch 'chore/upgrade-zitadel-4.7.0' into build/migrate-to-mage…
mridang 0e7233a
chore: updgrade to zitadel-go 3.19
mridang 3dc233e
Merge branch 'chore/upgrade-zitadel-4.7.0' into build/migrate-to-mage…
mridang 79f5c96
Merge branch 'main' into build/migrate-to-magefile
mridang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,37 +55,15 @@ jobs: | |
| with: | ||
| go-version-file: 'go.mod' | ||
|
|
||
| - name: Make Machinekey Directory Writable | ||
| working-directory: acceptance | ||
| run: "chmod -R 777 keys" | ||
|
|
||
| - name: Setup ZITADEL | ||
| working-directory: acceptance | ||
| run: docker compose run setup | ||
|
|
||
| - name: Download Go Modules | ||
| run: go mod download | ||
|
|
||
| - name: Run Acceptance Tests | ||
| run: TF_ACC=1 go test -p 1 -coverprofile=profile.cov ./... | ||
| run: go run ./mage.go test:cover | ||
|
|
||
| - name: Publish Coverage | ||
| uses: codecov/[email protected] | ||
| with: | ||
| file: profile.cov | ||
| name: acceptance-tests | ||
| flags: acceptance-tests | ||
|
|
||
| - name: Save Docker Compose Logs | ||
| if: always() | ||
| working-directory: acceptance | ||
| run: docker compose logs > .docker-compose.log | ||
|
|
||
| - name: Archive Docker Compose Logs | ||
| if: always() | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: pull-request-tests | ||
| path: | | ||
| acceptance/.docker-compose.log | ||
| retention-days: 30 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| //go:build mage | ||
| // +build mage | ||
|
|
||
| // Package main provides Mage build targets for linting, running tests, and | ||
| // orchestrating a Docker‑Compose test stack. All public functions are | ||
| // exported targets; every docstring is wrapped to 80 columns so that the file | ||
| // remains readable in split‑screen editors. | ||
| package main | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "os" | ||
| "os/exec" | ||
| "strings" | ||
|
|
||
| "github.com/magefile/mage/mg" | ||
| "github.com/magefile/mage/sh" | ||
| ) | ||
|
|
||
| const ( | ||
| composeFile = "./acceptance/docker-compose.yaml" // path to Compose file | ||
| projectName = "tests" // Compose project name | ||
| ) | ||
|
|
||
| // composeEnv builds the environment passed to every docker‑compose command. It | ||
| // injects the current user‑ID so containers can create files with the correct | ||
| // ownership, enables Terraform acceptance tests, and forces Compose to emit | ||
| // plain progress output (useful in CI logs). | ||
| func composeEnv() map[string]string { | ||
| uidBytes, _ := exec.Command("id", "-u").Output() | ||
| return map[string]string{ | ||
| "ZITADEL_DEV_UID": strings.TrimSpace(string(uidBytes)), | ||
| "TF_ACC": "1", | ||
| "COMPOSE_PROGRESS": "plain", | ||
| } | ||
| } | ||
|
|
||
| // runTests brings the stack up, executes `go test`, and always tears the stack | ||
| // down. Extra arguments (e.g. –coverprofile flags) are forwarded to the `go | ||
| // test` invocation so that callers can run both plain and coverage runs with | ||
| // the same orchestration logic. | ||
| func runTests(ctx context.Context, extraArgs ...string) error { | ||
| if err := Up(); err != nil { | ||
| return err | ||
| } | ||
| defer Down() | ||
|
|
||
| args := append([]string{"test"}, extraArgs...) | ||
| args = append(args, "./...") | ||
| return sh.RunV("go", args...) | ||
| } | ||
|
|
||
| // Test is a Mage namespace. `mage test:default` runs the normal test suite, | ||
| // while `mage test:cover` writes a coverage profile. | ||
| type Test mg.Namespace | ||
|
|
||
| // Default executes the full acceptance test suite against the Compose stack. | ||
| func (Test) Default(ctx context.Context) error { | ||
| return runTests(ctx) | ||
| } | ||
|
|
||
| // Cover runs the same suite but saves coverage data to profile.cov so that CI | ||
| // can upload the report. | ||
| func (Test) Cover(ctx context.Context) error { | ||
| return runTests(ctx, "-coverprofile=profile.cov") | ||
| } | ||
|
|
||
| // Lint invokes golangci‑lint if it is available; otherwise it falls back to | ||
| // `go vet` so that developers without the linter installed can still run the | ||
| // target locally without errors. | ||
| func Lint() error { | ||
| if err := sh.Run("golangci-lint", "run", "./..."); err == nil { | ||
| return nil | ||
| } | ||
| fmt.Println("golangci-lint not found – falling back to `go vet`") | ||
| return sh.RunV("go", "vet", "./...") | ||
| } | ||
|
|
||
| // Up starts the Compose stack in detached mode and waits for all health | ||
| // checks. Using a dedicated project name isolates the network and volumes | ||
| // from any other Compose projects that might be running on the same host. | ||
| // Up starts the Compose stack in detached mode, waits for health checks, and | ||
| // then sleeps an extra 30 seconds to give services a buffer before the test | ||
| // suite begins. This is occasionally helpful when containers report healthy | ||
| // but still need a moment to accept connections (e.g. databases warming up). | ||
| func Up() error { | ||
| if err := sh.RunWith(composeEnv(), | ||
| "docker", "compose", | ||
| "--file", composeFile, | ||
| "--project-name="+projectName, | ||
| "up", "--detach", "--wait"); err != nil { | ||
| return err | ||
| } | ||
| // Extra buffer so that flaky startup races are less likely. | ||
| if err := sh.RunV("sleep", "30"); err != nil { | ||
| fmt.Println("warning: sleep command failed:", err) | ||
| } | ||
|
Comment on lines
+95
to
+98
Member
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 there a condition we could retry quering until it is satisfied? |
||
| return nil | ||
| } | ||
|
|
||
| // Down stops the stack and removes volumes. If one of the well‑known debug | ||
| // flags is present (DEBUG, ACTIONS_STEP_DEBUG, or ACTIONS_RUNNER_DEBUG), it | ||
| // streams Compose logs to stdout first so developers can diagnose failures in | ||
| // CI without hunting for artifacts. | ||
| func Down() error { | ||
| if os.Getenv("DEBUG") != "" || | ||
| os.Getenv("ACTIONS_STEP_DEBUG") == "true" || | ||
| os.Getenv("ACTIONS_RUNNER_DEBUG") == "true" { | ||
| if err := sh.RunWith(composeEnv(), | ||
| "docker", "compose", | ||
| "--file", composeFile, | ||
| "--project-name="+projectName, | ||
| "logs"); err != nil { | ||
| fmt.Println("warning: failed to fetch compose logs:", err) | ||
| } | ||
| } | ||
| return sh.RunWith(composeEnv(), | ||
| "docker", "compose", | ||
| "--file", composeFile, | ||
| "--project-name="+projectName, | ||
| "down", "--volumes", "--remove-orphans") | ||
| } | ||
|
|
||
| // Default target: `mage` with no arguments lints the codebase and then runs | ||
| // the default test suite so that a single command ensures code quality and a | ||
| // passing set of integration tests. | ||
| var Default = All | ||
|
|
||
| // All wires the high‑level workflow of linting first and then running tests. | ||
| func All(ctx context.Context) { | ||
| mg.SerialDeps(Lint, Test{}.Default) | ||
| } | ||
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| //go:build mage_install | ||
| // +build mage_install | ||
|
|
||
| package main | ||
|
|
||
| import ( | ||
| "os" | ||
|
|
||
| "github.com/magefile/mage/mage" | ||
| ) | ||
|
|
||
| func main() { os.Exit(mage.Main()) } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Let's try to have reproducible results by requiring a specific version of golangci-lint pinned in go.mod?
https://go.dev/doc/go1.24#tools