From 1b86948c602d130039b1e480b0f4c02a955cf732 Mon Sep 17 00:00:00 2001 From: Jan Klattenhoff Date: Wed, 9 Apr 2025 19:28:15 +0200 Subject: [PATCH 1/3] ci: add Go CI workflow configuration file --- .gitea/workflows/CI.yml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 .gitea/workflows/CI.yml diff --git a/.gitea/workflows/CI.yml b/.gitea/workflows/CI.yml new file mode 100644 index 0000000..e962467 --- /dev/null +++ b/.gitea/workflows/CI.yml @@ -0,0 +1,18 @@ +name: "Go CI" + +on: + pull_request: + +jobs: + golangci: + name: lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version: 1.24.2 + - name: golangci-lint + uses: golangci/golangci-lint-action@v7 + with: + version: v2.0 From e332ef87cbab6a7e0ebde5bd17a37b50c9aea967 Mon Sep 17 00:00:00 2001 From: Jan Klattenhoff Date: Wed, 9 Apr 2025 17:40:45 +0000 Subject: [PATCH 2/3] feat: add linters (#11) Reviewed-on: https://git.kjan.de/actions/pull-request-lint/pulls/11 Co-authored-by: Jan Klattenhoff Co-committed-by: Jan Klattenhoff --- .golangci.yml | 4 ++++ internal/validation/validation.go | 2 ++ main.go | 10 +++++++++- 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 .golangci.yml diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..d5ac850 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,4 @@ +version: "2" +linters: + enable: + - revive diff --git a/internal/validation/validation.go b/internal/validation/validation.go index 8c3123e..0a4ada9 100644 --- a/internal/validation/validation.go +++ b/internal/validation/validation.go @@ -1,3 +1,4 @@ +// Package validation General validation tasks package validation import ( @@ -6,6 +7,7 @@ import ( "strings" ) +// ValidateConventionalCommit validates if string follows conventional commit func ValidateConventionalCommit(commit string) error { // Regex to match the commit format // type(scope)!: description diff --git a/main.go b/main.go index 3a70316..507692b 100644 --- a/main.go +++ b/main.go @@ -1,3 +1,4 @@ +// Package main is the main package package main import ( @@ -8,6 +9,7 @@ import ( "git.kjan.de/actions/pull-request-lint/internal/validation" ) +// GithubEvent represents a github actions event type GithubEvent struct { PullRequest struct { Title string `json:"title"` @@ -26,7 +28,13 @@ func main() { fmt.Printf("Error opening %s: %v\n", eventPath, err) os.Exit(1) } - defer eventFile.Close() + defer func() { + closeFileErr := eventFile.Close() + if closeFileErr != nil { + fmt.Println("Error closing eventFile") + os.Exit(1) + } + }() var event GithubEvent decoder := json.NewDecoder(eventFile) From 653e80ee737e01e12f335a4b0ab4f71ad506825b Mon Sep 17 00:00:00 2001 From: Jan Klattenhoff Date: Wed, 9 Apr 2025 17:46:26 +0000 Subject: [PATCH 3/3] ci: add test job to CI configuration (#12) Reviewed-on: https://git.kjan.de/actions/pull-request-lint/pulls/12 Co-authored-by: Jan Klattenhoff Co-committed-by: Jan Klattenhoff --- .gitea/workflows/CI.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.gitea/workflows/CI.yml b/.gitea/workflows/CI.yml index e962467..23d4be6 100644 --- a/.gitea/workflows/CI.yml +++ b/.gitea/workflows/CI.yml @@ -16,3 +16,14 @@ jobs: uses: golangci/golangci-lint-action@v7 with: version: v2.0 + + test: + name: test + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version: 1.24.2 + - name: Test + run: go test ./...