diff --git a/.github/workflows/qa-checks.yml b/.github/workflows/qa-checks.yml new file mode 100644 index 0000000..fa31f5d --- /dev/null +++ b/.github/workflows/qa-checks.yml @@ -0,0 +1,69 @@ +name: QA Checks + +on: + pull_request: + push: + branches: + - main + +permissions: + contents: read + +jobs: + go: + name: Go checks + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-go@v5 + with: + go-version-file: go.mod + cache: true + + - name: Verify go.mod is tidy + run: | + go mod tidy + if ! git diff --quiet go.mod go.sum; then + echo "::error::go.mod or go.sum is not tidy. Run 'go mod tidy' and commit the result." + git diff go.mod go.sum + exit 1 + fi + + - name: go vet + run: go vet ./... + + - name: go test + run: go test -race ./... + + - name: golangci-lint + uses: golangci/golangci-lint-action@v7 + with: + version: v2.2.2 + + docs: + name: Docs lint + runs-on: ubuntu-latest + defaults: + run: + working-directory: docs + steps: + - uses: actions/checkout@v4 + + - uses: pnpm/action-setup@v4 + with: + version: 11 + + - uses: actions/setup-node@v4 + with: + node-version: 22 + cache: pnpm + cache-dependency-path: docs/pnpm-lock.yaml + + - run: pnpm install --frozen-lockfile + + - name: Generate Nuxt types + run: pnpm exec nuxt prepare + + - name: ESLint + run: pnpm lint diff --git a/cmd/clean.go b/cmd/clean.go index caa50c5..688a13b 100644 --- a/cmd/clean.go +++ b/cmd/clean.go @@ -26,8 +26,8 @@ var cleanCmd = &cobra.Command{ Long: cleanLongUsage, Example: "terox clean\nterox gc\nterox cleanup", Args: cobra.NoArgs, - Run: func(cmd *cobra.Command, args []string) { - template.Clean() + RunE: func(cmd *cobra.Command, args []string) error { + return template.Clean() }, } diff --git a/cmd/list.go b/cmd/list.go index d172f6e..a9900d3 100644 --- a/cmd/list.go +++ b/cmd/list.go @@ -34,8 +34,8 @@ var listCmd = &cobra.Command{ Example: listExample, Long: listCmdLongHelp, Args: cobra.NoArgs, - Run: func(cmd *cobra.Command, args []string) { - template.List() + RunE: func(cmd *cobra.Command, args []string) error { + return template.List() }, } diff --git a/internal/template/clean.go b/internal/template/clean.go index 498b84f..21b9ca4 100644 --- a/internal/template/clean.go +++ b/internal/template/clean.go @@ -19,7 +19,7 @@ func Clean() error { // Read the contents of the template directory to check for templates if templates, err := os.ReadDir(templateDir); err != nil { return fmt.Errorf( - "Failed to find any templates at %s: %w", + "failed to find any templates at %s: %w", templateDir, err, ) @@ -30,7 +30,7 @@ func Clean() error { fmt.Printf("%s\n", template.Name()) if err := os.RemoveAll(path); err != nil { return fmt.Errorf( - "Failed to remove %s: %w", + "failed to remove %s: %w", template.Name(), err, ) diff --git a/internal/template/list.go b/internal/template/list.go index 75665a7..877e33e 100644 --- a/internal/template/list.go +++ b/internal/template/list.go @@ -18,7 +18,7 @@ func List() error { // Check if any template exists locally, if yes, list them to STDOUT if templates, err := os.ReadDir(templateDir); err != nil { return fmt.Errorf( - "Failed to read the contents of %s directory: %w", + "failed to read the contents of %s directory: %w", templateDir, err, ) diff --git a/internal/template/scaffold.go b/internal/template/scaffold.go index 3410a66..93d599c 100644 --- a/internal/template/scaffold.go +++ b/internal/template/scaffold.go @@ -74,7 +74,7 @@ func downloadTemplate(repo string) (string, error) { if err != nil { return "", fmt.Errorf("download %s: %w", url, err) } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() if resp.StatusCode != http.StatusOK { return "", fmt.Errorf("bad server response: %d", resp.StatusCode) @@ -100,7 +100,7 @@ func extractTemplate(zipfile, dest string) (string, error) { if err != nil { return "", fmt.Errorf("open zip: %w", err) } - defer r.Close() + defer func() { _ = r.Close() }() var topLevelFolder string for _, f := range r.File {