Skip to content
Merged
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
34 changes: 34 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: CI

on:
pull_request:
branches: [main]

jobs:
test:
name: Go Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod

- name: Install gotestfmt
run: go install github.com/gotesttools/gotestfmt/v2/cmd/gotestfmt@latest

- name: Run tests
run: |
go test ./cmd/... ./pkg/cli/... ./pkg/helpers/proxy/... ./pkg/helpers/routes/... \
-json -coverprofile=coverage.out -covermode=atomic \
2>&1 | tee /tmp/gotest.log | gotestfmt

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
files: coverage.out
fail_ci_if_error: true
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<img alt="background doc" src="Doc/Assets/gothic-hero.png" width="100%"/>

[![CI](https://github.com/felipegenef/gothicframework/actions/workflows/ci.yml/badge.svg)](https://github.com/felipegenef/gothicframework/actions/workflows/ci.yml)
[![codecov](https://codecov.io/gh/felipegenef/gothicframework/branch/main/graph/badge.svg)](https://codecov.io/gh/felipegenef/gothicframework)

<!-- <p align="center">
<img alt="logo" src="Doc/Assets/gothic-g-no-bg.png" width="100"/>
</p>
Expand Down
5 changes: 3 additions & 2 deletions cmd/migrate_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,11 @@ func rewriteGoMod(path string, content []byte, dryRun bool) (bool, error) {
for _, r := range mf.Require {
if r.Mod.Path == oldModulePath {
// /v2 modules require a v2.x.x version per SemVer import compatibility.
// We seed with v2.0.0; `go mod tidy` will resolve to the actual latest.
// Seed with the current CLI version so `go mod tidy` starts from a
// version that is guaranteed to exist on the registry.
newVersion := r.Mod.Version
if !strings.HasPrefix(newVersion, "v2.") {
newVersion = "v2.0.0"
newVersion = CURRENT_VERSION
}
if err := mf.AddRequire(newModulePath, newVersion); err != nil {
return false, err
Expand Down
43 changes: 15 additions & 28 deletions cmd/migrate_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,38 +43,29 @@ func readFile(t *testing.T, p string) string {
return string(b)
}

// equalGoMod compares two go.mod contents semantically (module + requires).
func equalGoMod(t *testing.T, gotPath, wantPath string) bool {
// assertGoMod checks that the migrated go.mod requires newModulePath at CURRENT_VERSION.
func assertGoMod(t *testing.T, gotPath string) {
t.Helper()
gb, err := os.ReadFile(gotPath)
if err != nil {
t.Fatalf("read got: %v", err)
}
wb, err := os.ReadFile(wantPath)
if err != nil {
t.Fatalf("read want: %v", err)
t.Fatalf("read go.mod: %v", err)
}
g, err := modfile.Parse(gotPath, gb, nil)
if err != nil {
t.Fatalf("parse got: %v", err)
}
w, err := modfile.Parse(wantPath, wb, nil)
if err != nil {
t.Fatalf("parse want: %v", err)
t.Fatalf("parse go.mod: %v", err)
}
if g.Module.Mod.Path != w.Module.Mod.Path {
return false
}
if len(g.Require) != len(w.Require) {
return false
}
for i := range g.Require {
if g.Require[i].Mod.Path != w.Require[i].Mod.Path ||
g.Require[i].Mod.Version != w.Require[i].Mod.Version {
return false
for _, r := range g.Require {
if r.Mod.Path == oldModulePath {
t.Errorf("go.mod still requires old path %s", oldModulePath)
}
if r.Mod.Path == newModulePath {
if r.Mod.Version != CURRENT_VERSION {
t.Errorf("go.mod: want %s %s, got %s", newModulePath, CURRENT_VERSION, r.Mod.Version)
}
return
}
}
return true
t.Errorf("go.mod: %s not found in require directives", newModulePath)
}

func setupTempProject(t *testing.T) string {
Expand All @@ -96,11 +87,7 @@ func TestMigrateV2_Migration(t *testing.T) {

afterDir := filepath.Join("testdata", "migrate_v2", "after")

if !equalGoMod(t, filepath.Join(dir, "go.mod"), filepath.Join(afterDir, "go.mod")) {
t.Errorf("go.mod mismatch.\ngot:\n%s\nwant:\n%s",
readFile(t, filepath.Join(dir, "go.mod")),
readFile(t, filepath.Join(afterDir, "go.mod")))
}
assertGoMod(t, filepath.Join(dir, "go.mod"))
for _, name := range []string{"main.go", "page.templ"} {
got := readFile(t, filepath.Join(dir, name))
want := readFile(t, filepath.Join(afterDir, name))
Expand Down
2 changes: 1 addition & 1 deletion cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/spf13/cobra"
)

var CURRENT_VERSION string = "v2.17.2"
var CURRENT_VERSION string = "v2.17.3"

// versionCmd represents the version command
var versionCmd = &cobra.Command{
Expand Down
Loading