From e629288cba4c8e77602bac183691c6b498798086 Mon Sep 17 00:00:00 2001 From: Mateusz Filipowicz Date: Fri, 7 Feb 2025 17:17:09 +0100 Subject: [PATCH] feat(codegen): rename "fields" to "codegen" for more meaningful naming --- .github/workflows/ci.yaml | 9 ++++++++- .github/workflows/generate.yaml | 8 ++++---- .gitignore | 1 + {fields => codegen}/api.go.tmpl | 0 {fields => codegen}/download.go | 2 +- {fields => codegen}/fwupdate.go | 0 {fields => codegen}/generator.go | 0 {fields => codegen}/generator_test.go | 0 {fields => codegen}/main.go | 1 + {fields => codegen}/version.go | 0 {fields => codegen}/version_test.go | 0 unifi/{fields.go => codegen.go} | 2 +- 12 files changed, 16 insertions(+), 7 deletions(-) rename {fields => codegen}/api.go.tmpl (100%) rename {fields => codegen}/download.go (100%) rename {fields => codegen}/fwupdate.go (100%) rename {fields => codegen}/generator.go (100%) rename {fields => codegen}/generator_test.go (100%) rename {fields => codegen}/main.go (98%) rename {fields => codegen}/version.go (100%) rename {fields => codegen}/version_test.go (100%) rename unifi/{fields.go => codegen.go} (64%) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 4e49869..e82adf8 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -19,7 +19,7 @@ jobs: - uses: 'actions/setup-go@v5' - run: 'go build ./...' - generate: + stringer: needs: 'build' runs-on: 'ubuntu-latest' steps: @@ -49,3 +49,10 @@ jobs: steps: - uses: 'actions/checkout@v4' - uses: 'ibiqlik/action-yamllint@v3' + + test-codegen: + runs-on: "ubuntu-latest" + steps: + - uses: "actions/checkout@v4" + - uses: "actions/setup-go@v5" + - run: "go generate unifi/codegen.go" diff --git a/.github/workflows/generate.yaml b/.github/workflows/generate.yaml index c573ec8..82bc2bf 100644 --- a/.github/workflows/generate.yaml +++ b/.github/workflows/generate.yaml @@ -4,9 +4,10 @@ on: schedule: - cron: "0 0 * * *" workflow_dispatch: {} - pull_request: {} -permissions: "write-all" +permissions: + contents: "write" + pull-requests: "write" jobs: fields: @@ -16,9 +17,8 @@ jobs: - uses: "actions/setup-go@v5" - - name: "Generate new client structures" - run: 'go generate unifi/fields.go' + run: 'go generate unifi/codegen.go' - name: "Read Unifi version marker" id: "unifi_version" diff --git a/.gitignore b/.gitignore index 5c0a48c..f3d6c02 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ # Cache /fields/v*.*.*/ +/codegen/v*.*.*/ # goreleaser /dist/ diff --git a/fields/api.go.tmpl b/codegen/api.go.tmpl similarity index 100% rename from fields/api.go.tmpl rename to codegen/api.go.tmpl diff --git a/fields/download.go b/codegen/download.go similarity index 100% rename from fields/download.go rename to codegen/download.go index cf8449b..9cb78dc 100644 --- a/fields/download.go +++ b/codegen/download.go @@ -7,7 +7,6 @@ import ( "encoding/json" "errors" "fmt" - log "github.com/sirupsen/logrus" "io" "net/http" "net/url" @@ -17,6 +16,7 @@ import ( "strings" "github.com/iancoleman/strcase" + log "github.com/sirupsen/logrus" "github.com/ulikunitz/xz" "github.com/xor-gate/ar" ) diff --git a/fields/fwupdate.go b/codegen/fwupdate.go similarity index 100% rename from fields/fwupdate.go rename to codegen/fwupdate.go diff --git a/fields/generator.go b/codegen/generator.go similarity index 100% rename from fields/generator.go rename to codegen/generator.go diff --git a/fields/generator_test.go b/codegen/generator_test.go similarity index 100% rename from fields/generator_test.go rename to codegen/generator_test.go diff --git a/fields/main.go b/codegen/main.go similarity index 98% rename from fields/main.go rename to codegen/main.go index 9add694..702a995 100644 --- a/fields/main.go +++ b/codegen/main.go @@ -22,6 +22,7 @@ func setupLogging(debugEnabled, traceEnabled bool) { log.SetFormatter(&log.TextFormatter{ DisableTimestamp: true, DisableLevelTruncation: true, + ForceColors: true, FullTimestamp: false, }) if traceEnabled { diff --git a/fields/version.go b/codegen/version.go similarity index 100% rename from fields/version.go rename to codegen/version.go diff --git a/fields/version_test.go b/codegen/version_test.go similarity index 100% rename from fields/version_test.go rename to codegen/version_test.go diff --git a/unifi/fields.go b/unifi/codegen.go similarity index 64% rename from unifi/fields.go rename to unifi/codegen.go index 9b1e1a1..ea30101 100644 --- a/unifi/fields.go +++ b/unifi/codegen.go @@ -2,4 +2,4 @@ package unifi // This will generate the *.generated.go files in this package for the specified // Unifi controller version. -//go:generate go run ../fields/ -version-base-dir=../fields/ latest +//go:generate go run ../codegen/ -version-base-dir=../codegen/ latest