From d0e7c0bec7dcaec6ab6d2bd43a0375ce359ffe5e Mon Sep 17 00:00:00 2001 From: Gitea Actions Date: Wed, 9 Apr 2025 14:59:03 +0000 Subject: [PATCH 01/33] chore(release): [skip ci] --- docs/CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 3383ec9..e25ad19 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,3 +1,10 @@ +## [0.2.1](https://git.kjan.de/actions/pull-request-lint/compare/v0.2.0...v0.2.1) (2025-04-09) + + +### Bug Fixes + +* Fix release pipeline ([bc0bf00](https://git.kjan.de/actions/pull-request-lint/commit/bc0bf00947c563652b674cab947f863c5c477dd2)) + # [0.2.0](https://git.kjan.de/actions/pull-request-lint/compare/v0.1.0...v0.2.0) (2025-04-09) From 09380fb8d002b200cebb4d56e8800569a0b60f16 Mon Sep 17 00:00:00 2001 From: Jan Klattenhoff Date: Wed, 9 Apr 2025 17:16:18 +0200 Subject: [PATCH 02/33] feat: add pull request linting action and validation logic --- action.yml | 5 ++ go.mod | 13 +++++ go.sum | 26 ++++++++++ internal/gitea/gitea.go | 16 ++++++ internal/validation/validation.go | 83 +++++++++++++++++++++++++++++++ main.go | 11 ++++ 6 files changed, 154 insertions(+) create mode 100644 action.yml create mode 100644 go.mod create mode 100644 go.sum create mode 100644 internal/gitea/gitea.go create mode 100644 internal/validation/validation.go create mode 100644 main.go diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..524d19d --- /dev/null +++ b/action.yml @@ -0,0 +1,5 @@ +name: 'Pull Request Lint' +description: 'Validates a pull request for semantical commit message' +runs: + using: 'go' + main: 'main.go' diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..d682129 --- /dev/null +++ b/go.mod @@ -0,0 +1,13 @@ +module git.kjan.de/actions/pull-request-lint + +go 1.24.2 + +require ( + code.gitea.io/sdk/gitea v0.21.0 // indirect + github.com/42wim/httpsig v1.2.2 // indirect + github.com/davidmz/go-pageant v1.0.2 // indirect + github.com/go-fed/httpsig v1.1.0 // indirect + github.com/hashicorp/go-version v1.7.0 // indirect + golang.org/x/crypto v0.33.0 // indirect + golang.org/x/sys v0.30.0 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..27105a4 --- /dev/null +++ b/go.sum @@ -0,0 +1,26 @@ +code.gitea.io/sdk/gitea v0.21.0 h1:69n6oz6kEVHRo1+APQQyizkhrZrLsTLXey9142pfkD4= +code.gitea.io/sdk/gitea v0.21.0/go.mod h1:tnBjVhuKJCn8ibdyyhvUyxrR1Ca2KHEoTWoukNhXQPA= +github.com/42wim/httpsig v1.2.2 h1:ofAYoHUNs/MJOLqQ8hIxeyz2QxOz8qdSVvp3PX/oPgA= +github.com/42wim/httpsig v1.2.2/go.mod h1:P/UYo7ytNBFwc+dg35IubuAUIs8zj5zzFIgUCEl55WY= +github.com/davidmz/go-pageant v1.0.2 h1:bPblRCh5jGU+Uptpz6LgMZGD5hJoOt7otgT454WvHn0= +github.com/davidmz/go-pageant v1.0.2/go.mod h1:P2EDDnMqIwG5Rrp05dTRITj9z2zpGcD9efWSkTNKLIE= +github.com/go-fed/httpsig v1.1.0 h1:9M+hb0jkEICD8/cAiNqEB66R87tTINszBRTjwjQzWcI= +github.com/go-fed/httpsig v1.1.0/go.mod h1:RCMrTZvN1bJYtofsG4rd5NaO5obxQ5xBkdiS7xsT7bM= +github.com/hashicorp/go-version v1.7.0 h1:5tqGy27NaOTB8yJKUZELlFAS/LTKJkrmONwQKeRZfjY= +github.com/hashicorp/go-version v1.7.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8= +golang.org/x/crypto v0.33.0 h1:IOBPskki6Lysi0lo9qQvbxiQ+FvsCC/YWOecCHAixus= +golang.org/x/crypto v0.33.0/go.mod h1:bVdXmD7IV/4GdElGPozy6U7lWdRXA4qyRVGJV57uQ5M= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc= +golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= diff --git a/internal/gitea/gitea.go b/internal/gitea/gitea.go new file mode 100644 index 0000000..a798720 --- /dev/null +++ b/internal/gitea/gitea.go @@ -0,0 +1,16 @@ +package gitea + +import ( + "fmt" + "os" + + "code.gitea.io/sdk/gitea" +) + +func getPrTitle() { + _, err := gitea.NewClient("https://git.kjan.de") + if err != nil { + fmt.Println(err) + os.Exit(1) + } +} diff --git a/internal/validation/validation.go b/internal/validation/validation.go new file mode 100644 index 0000000..46efd86 --- /dev/null +++ b/internal/validation/validation.go @@ -0,0 +1,83 @@ +package validation + +import ( + "fmt" + "regexp" + "strings" +) + +func ValidateConventionalCommit(commit string) error { + // Regex to match the commit format + // type(scope)!: description + // or + // type!: description + // or + // type: description + re := regexp.MustCompile(`^(?P[a-z]+)(?P\([a-z]+\))?(?P!)?: (?P[a-z].+)$`) + match := re.FindStringSubmatch(commit) + + if len(match) == 0 { + return fmt.Errorf("invalid commit format") + } + + typeIndex := re.SubexpIndex("type") + scopeIndex := re.SubexpIndex("scope") + breakingIndex := re.SubexpIndex("breaking") + descriptionIndex := re.SubexpIndex("description") + + commitType := match[typeIndex] + scope := match[scopeIndex] + breaking := match[breakingIndex] + description := match[descriptionIndex] + + // Type MUST be lowercase + if commitType != strings.ToLower(commitType) { + return fmt.Errorf("type must be lowercase") + } + + // Description MUST start with lowercase + if description != strings.ToLower(description) { + return fmt.Errorf("description must start with lowercase") + } + + // Scope MUST be lowercase + if scope != "" && scope != strings.ToLower(scope) { + return fmt.Errorf("scope must be lowercase") + } + + // Check for breaking change indicator + hasBreakingChangeFooter := strings.Contains(commit, "BREAKING CHANGE:") + if breaking == "!" && hasBreakingChangeFooter { + return fmt.Errorf("breaking change indicator and footer are mutually exclusive") + } + + lines := strings.Split(commit, "\n") + if len(lines) > 1 { + body := strings.Join(lines[1:], "\n") + // Check if body is separated from description by a blank line + if !strings.HasPrefix(body, "\n") { + return fmt.Errorf("body must be separated from description by a blank line") + } + } + + // Check for footers + footerRegex := regexp.MustCompile(`(?m)^(?P[A-Za-z-]+|BREAKING CHANGE): (?P.*)$`) + footerMatches := footerRegex.FindAllStringSubmatch(commit, -1) + + for _, footerMatch := range footerMatches { + tokenIndex := footerRegex.SubexpIndex("token") + token := footerMatch[tokenIndex] + + // BREAKING-CHANGE MUST be synonymous with BREAKING CHANGE + if token == "BREAKING-CHANGE" { + continue + } + + // Token MUST use - in place of whitespace characters, except for BREAKING CHANGE + if token != "BREAKING CHANGE" && strings.Contains(token, " ") { + return fmt.Errorf("footer token must use - in place of whitespace characters") + } + } + + return nil +} diff --git a/main.go b/main.go new file mode 100644 index 0000000..537ff8d --- /dev/null +++ b/main.go @@ -0,0 +1,11 @@ +package pullrequestlint + +import ( + "fmt" + "os" +) + +func main() { + prTitle := os.Getenv("GITEA_PULL_REQUEST_TITLE") + fmt.Println(prTitle) +} From aa1601e75185bab23b233142f732607f824b6d4a Mon Sep 17 00:00:00 2001 From: Jan Klattenhoff Date: Wed, 9 Apr 2025 17:17:55 +0200 Subject: [PATCH 03/33] ci: add pull request linting workflow configuration --- .gitea/workflows/pr.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 .gitea/workflows/pr.yml diff --git a/.gitea/workflows/pr.yml b/.gitea/workflows/pr.yml new file mode 100644 index 0000000..c16a160 --- /dev/null +++ b/.gitea/workflows/pr.yml @@ -0,0 +1,13 @@ +name: "Lint Pull Request" + +on: + pull_request: + +jobs: + lint: + name: Lint Pr Title + runs-on: ubuntu-latest + + steps: + - name: Lint + uses: https://git.kjan.de/actions/pull-request-lint@main From 6c118fb9ffa179ef433aedcd3d891ee7dd7368e1 Mon Sep 17 00:00:00 2001 From: Jan Klattenhoff Date: Wed, 9 Apr 2025 17:20:20 +0200 Subject: [PATCH 04/33] build: add Go installation step in PR workflow --- .gitea/workflows/pr.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitea/workflows/pr.yml b/.gitea/workflows/pr.yml index c16a160..125764b 100644 --- a/.gitea/workflows/pr.yml +++ b/.gitea/workflows/pr.yml @@ -9,5 +9,9 @@ jobs: runs-on: ubuntu-latest steps: + - name: Install go + uses: actions/setup-go@v5 + with: + go-version: 1.24.2 - name: Lint uses: https://git.kjan.de/actions/pull-request-lint@main From 5fd5b36be7957613aa3a616dff7fd809d0e8ccd8 Mon Sep 17 00:00:00 2001 From: Jan Klattenhoff Date: Wed, 9 Apr 2025 17:39:19 +0200 Subject: [PATCH 05/33] ci: add test workflow for Go Action --- .gitea/workflows/test.yml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 .gitea/workflows/test.yml diff --git a/.gitea/workflows/test.yml b/.gitea/workflows/test.yml new file mode 100644 index 0000000..5cf5f4b --- /dev/null +++ b/.gitea/workflows/test.yml @@ -0,0 +1,19 @@ +name: 'Test Go Action' +on: [push] +jobs: + use-go-action: + runs-on: ubuntu-latest + steps: + - name: Setup Go + uses: actions/setup-go@v3 + with: + go-version: '1.20' + + - name: Use Go Action + id: use-go-action + uses: https://gitea.com/Zettat123/simple-go-action@v1 + with: + username: foo + + - name: Print Output + run: echo 'output time is ${{ steps.use-go-action.outputs.time }}' From c9fd83e531b1f205e6d3132be55caee0c36ef41e Mon Sep 17 00:00:00 2001 From: Jan Klattenhoff Date: Wed, 9 Apr 2025 17:47:32 +0200 Subject: [PATCH 06/33] ci: add debugging steps and permission settings to CI --- .gitea/workflows/pr.yml | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/.gitea/workflows/pr.yml b/.gitea/workflows/pr.yml index 125764b..8358f67 100644 --- a/.gitea/workflows/pr.yml +++ b/.gitea/workflows/pr.yml @@ -13,5 +13,20 @@ jobs: uses: actions/setup-go@v5 with: go-version: 1.24.2 - - name: Lint + + - name: Inspect the Action Directory (Debugging) + run: | + echo "Listing files in action directory:" + ls -l ./ + + - name: Set execute permissions (Attempt 1 - Relative Path) + run: chmod +x main.go.out + + - name: Set execute permissions (Attempt 2 - Absolute Path) + run: chmod +x $(pwd)/main.go.out + + - name: Set execute permissions (Attempt 3 - Explicit Path) + run: chmod +x /github/workspace/main.go.out #This is a path commonly used by actions, might work + + - name: Run Pull Request Lint Action uses: https://git.kjan.de/actions/pull-request-lint@main From 50c451f69eb3217189813c0e506c794552b15fc8 Mon Sep 17 00:00:00 2001 From: Jan Klattenhoff Date: Wed, 9 Apr 2025 17:51:05 +0200 Subject: [PATCH 07/33] ci: update action directory path in workflow config --- .gitea/workflows/pr.yml | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/.gitea/workflows/pr.yml b/.gitea/workflows/pr.yml index 8358f67..9b91d2c 100644 --- a/.gitea/workflows/pr.yml +++ b/.gitea/workflows/pr.yml @@ -17,16 +17,10 @@ jobs: - name: Inspect the Action Directory (Debugging) run: | echo "Listing files in action directory:" - ls -l ./ + ls -l /var/run/act/actions/https---git.kjan.de-actions-pull-request-lint@main/ - - name: Set execute permissions (Attempt 1 - Relative Path) - run: chmod +x main.go.out - - - name: Set execute permissions (Attempt 2 - Absolute Path) - run: chmod +x $(pwd)/main.go.out - - - name: Set execute permissions (Attempt 3 - Explicit Path) - run: chmod +x /github/workspace/main.go.out #This is a path commonly used by actions, might work + - name: Set execute permissions (Explicit Path) + run: chmod +x /var/run/act/actions/https---git.kjan.de-actions-pull-request-lint@main/main.go.out - name: Run Pull Request Lint Action uses: https://git.kjan.de/actions/pull-request-lint@main From 142ef2e8f869dc45660f0a3e5023961094d536d5 Mon Sep 17 00:00:00 2001 From: Jan Klattenhoff Date: Wed, 9 Apr 2025 17:53:47 +0200 Subject: [PATCH 08/33] ci: add always condition to lint action steps --- .gitea/workflows/pr.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitea/workflows/pr.yml b/.gitea/workflows/pr.yml index 9b91d2c..4316a74 100644 --- a/.gitea/workflows/pr.yml +++ b/.gitea/workflows/pr.yml @@ -20,7 +20,9 @@ jobs: ls -l /var/run/act/actions/https---git.kjan.de-actions-pull-request-lint@main/ - name: Set execute permissions (Explicit Path) + if: ${{ always() }} run: chmod +x /var/run/act/actions/https---git.kjan.de-actions-pull-request-lint@main/main.go.out - name: Run Pull Request Lint Action + if: ${{ always() }} uses: https://git.kjan.de/actions/pull-request-lint@main From 3253d5ac63529512210f7dd49edda698463f00e7 Mon Sep 17 00:00:00 2001 From: Jan Klattenhoff Date: Wed, 9 Apr 2025 18:01:43 +0200 Subject: [PATCH 09/33] ci: update PR workflow to use golang image --- .gitea/workflows/pr.yml | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/.gitea/workflows/pr.yml b/.gitea/workflows/pr.yml index 4316a74..20059b0 100644 --- a/.gitea/workflows/pr.yml +++ b/.gitea/workflows/pr.yml @@ -7,6 +7,7 @@ jobs: lint: name: Lint Pr Title runs-on: ubuntu-latest + image: golang steps: - name: Install go @@ -14,15 +15,6 @@ jobs: with: go-version: 1.24.2 - - name: Inspect the Action Directory (Debugging) - run: | - echo "Listing files in action directory:" - ls -l /var/run/act/actions/https---git.kjan.de-actions-pull-request-lint@main/ - - - name: Set execute permissions (Explicit Path) - if: ${{ always() }} - run: chmod +x /var/run/act/actions/https---git.kjan.de-actions-pull-request-lint@main/main.go.out - - name: Run Pull Request Lint Action if: ${{ always() }} uses: https://git.kjan.de/actions/pull-request-lint@main From 7ded9bab1335e25dc2423881613b1b7c69fb77af Mon Sep 17 00:00:00 2001 From: Jan Klattenhoff Date: Wed, 9 Apr 2025 18:02:26 +0200 Subject: [PATCH 10/33] ci: update container configuration in PR workflow --- .gitea/workflows/pr.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitea/workflows/pr.yml b/.gitea/workflows/pr.yml index 20059b0..f243f5f 100644 --- a/.gitea/workflows/pr.yml +++ b/.gitea/workflows/pr.yml @@ -7,7 +7,8 @@ jobs: lint: name: Lint Pr Title runs-on: ubuntu-latest - image: golang + container: + image: golang steps: - name: Install go From 72b5dd18f33c45072e4efeaf7a6922683ee3761f Mon Sep 17 00:00:00 2001 From: Jan Klattenhoff Date: Wed, 9 Apr 2025 18:07:13 +0200 Subject: [PATCH 11/33] build(workflows): update CI configuration and remove test file --- .gitea/workflows/pr.yml | 3 --- .gitea/workflows/test.yml | 19 ------------------- action.yml | 4 ++-- invoke-binary.js | 30 ++++++++++++++++++++++++++++++ 4 files changed, 32 insertions(+), 24 deletions(-) delete mode 100644 .gitea/workflows/test.yml create mode 100644 invoke-binary.js diff --git a/.gitea/workflows/pr.yml b/.gitea/workflows/pr.yml index f243f5f..fde0cf4 100644 --- a/.gitea/workflows/pr.yml +++ b/.gitea/workflows/pr.yml @@ -7,8 +7,6 @@ jobs: lint: name: Lint Pr Title runs-on: ubuntu-latest - container: - image: golang steps: - name: Install go @@ -17,5 +15,4 @@ jobs: go-version: 1.24.2 - name: Run Pull Request Lint Action - if: ${{ always() }} uses: https://git.kjan.de/actions/pull-request-lint@main diff --git a/.gitea/workflows/test.yml b/.gitea/workflows/test.yml deleted file mode 100644 index 5cf5f4b..0000000 --- a/.gitea/workflows/test.yml +++ /dev/null @@ -1,19 +0,0 @@ -name: 'Test Go Action' -on: [push] -jobs: - use-go-action: - runs-on: ubuntu-latest - steps: - - name: Setup Go - uses: actions/setup-go@v3 - with: - go-version: '1.20' - - - name: Use Go Action - id: use-go-action - uses: https://gitea.com/Zettat123/simple-go-action@v1 - with: - username: foo - - - name: Print Output - run: echo 'output time is ${{ steps.use-go-action.outputs.time }}' diff --git a/action.yml b/action.yml index 524d19d..adf9038 100644 --- a/action.yml +++ b/action.yml @@ -1,5 +1,5 @@ name: 'Pull Request Lint' description: 'Validates a pull request for semantical commit message' runs: - using: 'go' - main: 'main.go' + using: 'node16' + main: 'invoke-binary.js' diff --git a/invoke-binary.js b/invoke-binary.js new file mode 100644 index 0000000..69baa60 --- /dev/null +++ b/invoke-binary.js @@ -0,0 +1,30 @@ +const childProcess = require('child_process') +const path = require('path') + +function runGo() { + const goProcess = childProcess.spawnSync( + 'go', + ['run', '.'], + { + cwd: __dirname, + stdio: 'inherit', + shell: true, + }, + ) + + if (goProcess.error) { + console.error('Failed to execute `go run .`:', goProcess.error) + process.exit(1) + } + + if (goProcess.status !== 0) { + console.error( + '`go run .` exited with code', + goProcess.status, + goProcess.stderr ? goProcess.stderr.toString() : '', + ) + process.exit(goProcess.status) + } +} + +runGo() From da4a8b3030406f5ba8c82093f2385060cd0d48b8 Mon Sep 17 00:00:00 2001 From: Jan Klattenhoff Date: Wed, 9 Apr 2025 18:08:58 +0200 Subject: [PATCH 12/33] feat(invoke-binary): add ls command execution in runGo function --- invoke-binary.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/invoke-binary.js b/invoke-binary.js index 69baa60..7551604 100644 --- a/invoke-binary.js +++ b/invoke-binary.js @@ -2,6 +2,15 @@ const childProcess = require('child_process') const path = require('path') function runGo() { + childProcess.spawnSync( + 'ls', + ["-la"], + { + cwd: __dirname, + stdio: 'inherit', + shell: true, + }, + ) const goProcess = childProcess.spawnSync( 'go', ['run', '.'], From 6d9c48078c912b91bb60d8147b1b2d7e74ad8643 Mon Sep 17 00:00:00 2001 From: Jan Klattenhoff Date: Wed, 9 Apr 2025 18:10:18 +0200 Subject: [PATCH 13/33] feat(action): update to use Go for pull request linting --- action.yml | 6 +++--- invoke-binary.js | 9 --------- main.go | 2 +- 3 files changed, 4 insertions(+), 13 deletions(-) diff --git a/action.yml b/action.yml index adf9038..3aeab77 100644 --- a/action.yml +++ b/action.yml @@ -1,5 +1,5 @@ name: 'Pull Request Lint' -description: 'Validates a pull request for semantical commit message' +description: 'A simple Gitea action written in go' runs: - using: 'node16' - main: 'invoke-binary.js' + using: 'go' + main: 'main.go' diff --git a/invoke-binary.js b/invoke-binary.js index 7551604..69baa60 100644 --- a/invoke-binary.js +++ b/invoke-binary.js @@ -2,15 +2,6 @@ const childProcess = require('child_process') const path = require('path') function runGo() { - childProcess.spawnSync( - 'ls', - ["-la"], - { - cwd: __dirname, - stdio: 'inherit', - shell: true, - }, - ) const goProcess = childProcess.spawnSync( 'go', ['run', '.'], diff --git a/main.go b/main.go index 537ff8d..ff508bd 100644 --- a/main.go +++ b/main.go @@ -1,4 +1,4 @@ -package pullrequestlint +package main import ( "fmt" From 80ab70da048ef046c380992fa5aaf3cdb7a9acae Mon Sep 17 00:00:00 2001 From: Jan Klattenhoff Date: Wed, 9 Apr 2025 18:11:23 +0200 Subject: [PATCH 14/33] chore: remove invoke-binary.js and update main.go logic --- invoke-binary.js | 30 ------------------------------ main.go | 9 +++++++-- 2 files changed, 7 insertions(+), 32 deletions(-) delete mode 100644 invoke-binary.js diff --git a/invoke-binary.js b/invoke-binary.js deleted file mode 100644 index 69baa60..0000000 --- a/invoke-binary.js +++ /dev/null @@ -1,30 +0,0 @@ -const childProcess = require('child_process') -const path = require('path') - -function runGo() { - const goProcess = childProcess.spawnSync( - 'go', - ['run', '.'], - { - cwd: __dirname, - stdio: 'inherit', - shell: true, - }, - ) - - if (goProcess.error) { - console.error('Failed to execute `go run .`:', goProcess.error) - process.exit(1) - } - - if (goProcess.status !== 0) { - console.error( - '`go run .` exited with code', - goProcess.status, - goProcess.stderr ? goProcess.stderr.toString() : '', - ) - process.exit(goProcess.status) - } -} - -runGo() diff --git a/main.go b/main.go index ff508bd..8ae3d03 100644 --- a/main.go +++ b/main.go @@ -6,6 +6,11 @@ import ( ) func main() { - prTitle := os.Getenv("GITEA_PULL_REQUEST_TITLE") - fmt.Println(prTitle) + // Get all environment variables + environ := os.Environ() + + // Print each environment variable + for _, env := range environ { + fmt.Println(env) + } } From ce06de60ebfed00e03e900ab055c379df254526c Mon Sep 17 00:00:00 2001 From: Jan Klattenhoff Date: Wed, 9 Apr 2025 18:13:59 +0200 Subject: [PATCH 15/33] ci: update pull request types for linting workflow --- .gitea/workflows/pr.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitea/workflows/pr.yml b/.gitea/workflows/pr.yml index fde0cf4..7f588a3 100644 --- a/.gitea/workflows/pr.yml +++ b/.gitea/workflows/pr.yml @@ -2,6 +2,7 @@ name: "Lint Pull Request" on: pull_request: + types: [opened, edited, reopened, synchronize] jobs: lint: From 2c943b845f4b3d4b413715f804dae1da15847129 Mon Sep 17 00:00:00 2001 From: Jan Klattenhoff Date: Wed, 9 Apr 2025 18:15:52 +0200 Subject: [PATCH 16/33] ci: add step to read event.json in PR workflow --- .gitea/workflows/pr.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitea/workflows/pr.yml b/.gitea/workflows/pr.yml index 7f588a3..3626672 100644 --- a/.gitea/workflows/pr.yml +++ b/.gitea/workflows/pr.yml @@ -17,3 +17,5 @@ jobs: - name: Run Pull Request Lint Action uses: https://git.kjan.de/actions/pull-request-lint@main + + - run: cat /var/run/act/workflow/event.json From 044823552b5fecf0b076098d1bc47d213c00f604 Mon Sep 17 00:00:00 2001 From: Jan Klattenhoff Date: Wed, 9 Apr 2025 18:17:12 +0200 Subject: [PATCH 17/33] feat: add GitHub event handling and pull request title display --- main.go | 39 +++++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/main.go b/main.go index 8ae3d03..7b2ff45 100644 --- a/main.go +++ b/main.go @@ -1,16 +1,39 @@ package main import ( + "encoding/json" "fmt" "os" ) -func main() { - // Get all environment variables - environ := os.Environ() - - // Print each environment variable - for _, env := range environ { - fmt.Println(env) - } +type GithubEvent struct { + PullRequest struct { + Title string `json:"title"` + } `json:"pull_request"` +} + +func main() { + eventPath := os.Getenv("GITHUB_EVENT_PATH") + if eventPath == "" { + fmt.Println("GITHUB_EVENT_PATH not set") + os.Exit(1) + } + + eventFile, err := os.Open(eventPath) + if err != nil { + fmt.Printf("Error opening %s: %v\n", eventPath, err) + os.Exit(1) + } + defer eventFile.Close() + + var event GithubEvent + decoder := json.NewDecoder(eventFile) + err = decoder.Decode(&event) + if err != nil { + fmt.Printf("Error decoding event.json: %v\n", err) + os.Exit(1) + } + + prTitle := event.PullRequest.Title + fmt.Println("Pull Request Title:", prTitle) } From 19b376ac40e34b5d70bbe36e3affea3590fa4510 Mon Sep 17 00:00:00 2001 From: Jan Klattenhoff Date: Wed, 9 Apr 2025 18:19:21 +0200 Subject: [PATCH 18/33] refactor: clean up unused dependencies and functions --- .gitea/workflows/pr.yml | 2 -- go.mod | 10 ---------- go.sum | 26 -------------------------- internal/gitea/gitea.go | 16 ---------------- main.go | 9 ++++++++- 5 files changed, 8 insertions(+), 55 deletions(-) delete mode 100644 internal/gitea/gitea.go diff --git a/.gitea/workflows/pr.yml b/.gitea/workflows/pr.yml index 3626672..7f588a3 100644 --- a/.gitea/workflows/pr.yml +++ b/.gitea/workflows/pr.yml @@ -17,5 +17,3 @@ jobs: - name: Run Pull Request Lint Action uses: https://git.kjan.de/actions/pull-request-lint@main - - - run: cat /var/run/act/workflow/event.json diff --git a/go.mod b/go.mod index d682129..575ab3e 100644 --- a/go.mod +++ b/go.mod @@ -1,13 +1,3 @@ module git.kjan.de/actions/pull-request-lint go 1.24.2 - -require ( - code.gitea.io/sdk/gitea v0.21.0 // indirect - github.com/42wim/httpsig v1.2.2 // indirect - github.com/davidmz/go-pageant v1.0.2 // indirect - github.com/go-fed/httpsig v1.1.0 // indirect - github.com/hashicorp/go-version v1.7.0 // indirect - golang.org/x/crypto v0.33.0 // indirect - golang.org/x/sys v0.30.0 // indirect -) diff --git a/go.sum b/go.sum index 27105a4..e69de29 100644 --- a/go.sum +++ b/go.sum @@ -1,26 +0,0 @@ -code.gitea.io/sdk/gitea v0.21.0 h1:69n6oz6kEVHRo1+APQQyizkhrZrLsTLXey9142pfkD4= -code.gitea.io/sdk/gitea v0.21.0/go.mod h1:tnBjVhuKJCn8ibdyyhvUyxrR1Ca2KHEoTWoukNhXQPA= -github.com/42wim/httpsig v1.2.2 h1:ofAYoHUNs/MJOLqQ8hIxeyz2QxOz8qdSVvp3PX/oPgA= -github.com/42wim/httpsig v1.2.2/go.mod h1:P/UYo7ytNBFwc+dg35IubuAUIs8zj5zzFIgUCEl55WY= -github.com/davidmz/go-pageant v1.0.2 h1:bPblRCh5jGU+Uptpz6LgMZGD5hJoOt7otgT454WvHn0= -github.com/davidmz/go-pageant v1.0.2/go.mod h1:P2EDDnMqIwG5Rrp05dTRITj9z2zpGcD9efWSkTNKLIE= -github.com/go-fed/httpsig v1.1.0 h1:9M+hb0jkEICD8/cAiNqEB66R87tTINszBRTjwjQzWcI= -github.com/go-fed/httpsig v1.1.0/go.mod h1:RCMrTZvN1bJYtofsG4rd5NaO5obxQ5xBkdiS7xsT7bM= -github.com/hashicorp/go-version v1.7.0 h1:5tqGy27NaOTB8yJKUZELlFAS/LTKJkrmONwQKeRZfjY= -github.com/hashicorp/go-version v1.7.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8= -golang.org/x/crypto v0.33.0 h1:IOBPskki6Lysi0lo9qQvbxiQ+FvsCC/YWOecCHAixus= -golang.org/x/crypto v0.33.0/go.mod h1:bVdXmD7IV/4GdElGPozy6U7lWdRXA4qyRVGJV57uQ5M= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc= -golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= diff --git a/internal/gitea/gitea.go b/internal/gitea/gitea.go deleted file mode 100644 index a798720..0000000 --- a/internal/gitea/gitea.go +++ /dev/null @@ -1,16 +0,0 @@ -package gitea - -import ( - "fmt" - "os" - - "code.gitea.io/sdk/gitea" -) - -func getPrTitle() { - _, err := gitea.NewClient("https://git.kjan.de") - if err != nil { - fmt.Println(err) - os.Exit(1) - } -} diff --git a/main.go b/main.go index 7b2ff45..1a384ff 100644 --- a/main.go +++ b/main.go @@ -4,6 +4,8 @@ import ( "encoding/json" "fmt" "os" + + "git.kjan.de/actions/pull-request-lint/internal/validation" ) type GithubEvent struct { @@ -35,5 +37,10 @@ func main() { } prTitle := event.PullRequest.Title - fmt.Println("Pull Request Title:", prTitle) + semanticValidationErr := validation.ValidateConventionalCommit(prTitle) + if semanticValidationErr != nil { + fmt.Println(err) + os.Exit(1) + } + os.Exit(0) } From 8981c8367edc7beff7a477510ba3a3a98b6e6751 Mon Sep 17 00:00:00 2001 From: Jan Klattenhoff Date: Wed, 9 Apr 2025 18:20:34 +0200 Subject: [PATCH 19/33] fix(main): improve error message for invalid PR title --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index 1a384ff..0faa147 100644 --- a/main.go +++ b/main.go @@ -39,7 +39,7 @@ func main() { prTitle := event.PullRequest.Title semanticValidationErr := validation.ValidateConventionalCommit(prTitle) if semanticValidationErr != nil { - fmt.Println(err) + fmt.Println("Invalid Pr Title") os.Exit(1) } os.Exit(0) From c84b1ecd26d7cbd4530fed79e6078ced5d222e18 Mon Sep 17 00:00:00 2001 From: Jan Klattenhoff Date: Wed, 9 Apr 2025 18:20:59 +0200 Subject: [PATCH 20/33] fix(main): improve error message for invalid PR title --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index 0faa147..3a70316 100644 --- a/main.go +++ b/main.go @@ -39,7 +39,7 @@ func main() { prTitle := event.PullRequest.Title semanticValidationErr := validation.ValidateConventionalCommit(prTitle) if semanticValidationErr != nil { - fmt.Println("Invalid Pr Title") + fmt.Println(semanticValidationErr) os.Exit(1) } os.Exit(0) From 9b1a6a928e3483fd4ea6579cdcd8c8a9e95bb669 Mon Sep 17 00:00:00 2001 From: Jan Klattenhoff Date: Wed, 9 Apr 2025 18:22:37 +0200 Subject: [PATCH 21/33] fix(validation): update error message for invalid commit format --- internal/validation/validation.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/validation/validation.go b/internal/validation/validation.go index 46efd86..4d48e4a 100644 --- a/internal/validation/validation.go +++ b/internal/validation/validation.go @@ -17,7 +17,7 @@ func ValidateConventionalCommit(commit string) error { match := re.FindStringSubmatch(commit) if len(match) == 0 { - return fmt.Errorf("invalid commit format") + return fmt.Errorf("Invalid PR title") } typeIndex := re.SubexpIndex("type") From 64260f301a8f82d40c6b28b522d16c682d33d730 Mon Sep 17 00:00:00 2001 From: Jan Klattenhoff Date: Wed, 9 Apr 2025 18:24:53 +0200 Subject: [PATCH 22/33] ci: add condition to skip linting on release branches --- .gitea/workflows/pr.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitea/workflows/pr.yml b/.gitea/workflows/pr.yml index 7f588a3..2eba5c0 100644 --- a/.gitea/workflows/pr.yml +++ b/.gitea/workflows/pr.yml @@ -9,6 +9,8 @@ jobs: name: Lint Pr Title runs-on: ubuntu-latest + if: github.base_ref != 'release' + steps: - name: Install go uses: actions/setup-go@v5 From befdff3be1a7409a208542f38c0db778fbb80af5 Mon Sep 17 00:00:00 2001 From: Gitea Actions Date: Wed, 9 Apr 2025 16:26:10 +0000 Subject: [PATCH 23/33] chore(release): [skip ci] --- docs/CHANGELOG.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index e25ad19..62b4ea5 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,3 +1,20 @@ +# [0.3.0](https://git.kjan.de/actions/pull-request-lint/compare/v0.2.1...v0.3.0) (2025-04-09) + + +### Bug Fixes + +* **main:** improve error message for invalid PR title ([c84b1ec](https://git.kjan.de/actions/pull-request-lint/commit/c84b1ecd26d7cbd4530fed79e6078ced5d222e18)) +* **main:** improve error message for invalid PR title ([8981c83](https://git.kjan.de/actions/pull-request-lint/commit/8981c8367edc7beff7a477510ba3a3a98b6e6751)) +* **validation:** update error message for invalid commit format ([9b1a6a9](https://git.kjan.de/actions/pull-request-lint/commit/9b1a6a928e3483fd4ea6579cdcd8c8a9e95bb669)) + + +### Features + +* **action:** update to use Go for pull request linting ([6d9c480](https://git.kjan.de/actions/pull-request-lint/commit/6d9c48078c912b91bb60d8147b1b2d7e74ad8643)) +* add GitHub event handling and pull request title display ([0448235](https://git.kjan.de/actions/pull-request-lint/commit/044823552b5fecf0b076098d1bc47d213c00f604)) +* add pull request linting action and validation logic ([09380fb](https://git.kjan.de/actions/pull-request-lint/commit/09380fb8d002b200cebb4d56e8800569a0b60f16)) +* **invoke-binary:** add ls command execution in runGo function ([da4a8b3](https://git.kjan.de/actions/pull-request-lint/commit/da4a8b3030406f5ba8c82093f2385060cd0d48b8)) + ## [0.2.1](https://git.kjan.de/actions/pull-request-lint/compare/v0.2.0...v0.2.1) (2025-04-09) From 86febd99e507d250adb18fdfede0a01f6e6f8d46 Mon Sep 17 00:00:00 2001 From: Jan Klattenhoff Date: Wed, 9 Apr 2025 18:29:31 +0200 Subject: [PATCH 24/33] refactor: some polishing BREAKING CHANGE: Version 1 --- .gitea/workflows/pr.yml | 2 +- action.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitea/workflows/pr.yml b/.gitea/workflows/pr.yml index 2eba5c0..bea49c0 100644 --- a/.gitea/workflows/pr.yml +++ b/.gitea/workflows/pr.yml @@ -6,7 +6,7 @@ on: jobs: lint: - name: Lint Pr Title + name: Lint PR Title runs-on: ubuntu-latest if: github.base_ref != 'release' diff --git a/action.yml b/action.yml index 3aeab77..02052c2 100644 --- a/action.yml +++ b/action.yml @@ -1,5 +1,5 @@ name: 'Pull Request Lint' -description: 'A simple Gitea action written in go' +description: 'A gitea action to validate if a pr follows the semantic commit guidelines' runs: using: 'go' main: 'main.go' From 372ed39a62d82d515805d88a38220128726f9363 Mon Sep 17 00:00:00 2001 From: Gitea Actions Date: Wed, 9 Apr 2025 16:32:02 +0000 Subject: [PATCH 25/33] chore(release): [skip ci] --- docs/CHANGELOG.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 62b4ea5..4addfa4 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,3 +1,15 @@ +# [1.0.0](https://git.kjan.de/actions/pull-request-lint/compare/v0.3.0...v1.0.0) (2025-04-09) + + +### Code Refactoring + +* some polishing ([86febd9](https://git.kjan.de/actions/pull-request-lint/commit/86febd99e507d250adb18fdfede0a01f6e6f8d46)) + + +### BREAKING CHANGES + +* Version 1 + # [0.3.0](https://git.kjan.de/actions/pull-request-lint/compare/v0.2.1...v0.3.0) (2025-04-09) From 08b43cc51b2f8975144fb61afddb5cb222890e09 Mon Sep 17 00:00:00 2001 From: Jan Klattenhoff Date: Wed, 9 Apr 2025 18:37:58 +0200 Subject: [PATCH 26/33] refactor(validation): simplify regex and error messages --- internal/validation/validation.go | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/internal/validation/validation.go b/internal/validation/validation.go index 4d48e4a..8c3123e 100644 --- a/internal/validation/validation.go +++ b/internal/validation/validation.go @@ -13,33 +13,26 @@ func ValidateConventionalCommit(commit string) error { // type!: description // or // type: description - re := regexp.MustCompile(`^(?P[a-z]+)(?P\([a-z]+\))?(?P!)?: (?P[a-z].+)$`) + re := regexp.MustCompile(`^(?P[a-z]+)(?P\([a-z]+\))?(?P!)?: (?P.+)$`) match := re.FindStringSubmatch(commit) if len(match) == 0 { - return fmt.Errorf("Invalid PR title") + return fmt.Errorf("invalid commit format") } typeIndex := re.SubexpIndex("type") scopeIndex := re.SubexpIndex("scope") breakingIndex := re.SubexpIndex("breaking") - descriptionIndex := re.SubexpIndex("description") commitType := match[typeIndex] scope := match[scopeIndex] breaking := match[breakingIndex] - description := match[descriptionIndex] // Type MUST be lowercase if commitType != strings.ToLower(commitType) { return fmt.Errorf("type must be lowercase") } - // Description MUST start with lowercase - if description != strings.ToLower(description) { - return fmt.Errorf("description must start with lowercase") - } - // Scope MUST be lowercase if scope != "" && scope != strings.ToLower(scope) { return fmt.Errorf("scope must be lowercase") From 7e2de542b6f4439dab9c112b0999e4d329732d19 Mon Sep 17 00:00:00 2001 From: Jan Klattenhoff Date: Wed, 9 Apr 2025 16:43:32 +0000 Subject: [PATCH 27/33] docs: update README with usage and validation rules (#7) Reviewed-on: https://git.kjan.de/actions/pull-request-lint/pulls/7 Co-authored-by: Jan Klattenhoff Co-committed-by: Jan Klattenhoff --- README.md | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a198e3f..7c7a6db 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,41 @@ # pull-request-lint -Lints the title of a pull request \ No newline at end of file +A GitHub/Gitea Action that lints pull request titles to ensure they follow the [Conventional Commits](https://www.conventionalcommits.org/) format. + +## Usage + +Add the following to your GitHub/Gitea workflow: + +```yaml +name: Pull Request Lint + +on: + pull_request: + types: [opened, edited, reopened, synchronize] + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Install go + uses: actions/setup-go@v5 + with: + go-version: 1.24.2 + - uses: https://git.kjan.de/actions/pull-request-lint@release +``` + +## Validation Rules + +The action enforces the following Conventional Commits rules for PR titles: + +- Format must be: `type(scope)!: description` (scope and breaking change marker `!` are optional) +- Type and scope must be lowercase +- Description must start with lowercase +- Breaking change indicator and footer are mutually exclusive +- Body must be separated from description by a blank line +- Footer tokens must use hyphens instead of spaces (except for "BREAKING CHANGE") + +## License + +See [LICENSE](LICENSE) file for details. From c420551cdb4cdc191a149849abefd2ca2764f0ec Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Wed, 9 Apr 2025 16:44:40 +0000 Subject: [PATCH 28/33] chore: Configure Renovate (#4) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Welcome to [Renovate](https://github.com/renovatebot/renovate)! This is an onboarding PR to help you understand and configure settings before regular Pull Requests begin. 🚦 To activate Renovate, merge this Pull Request. To disable Renovate, simply close this Pull Request unmerged. --- ### Detected Package Files * `.gitea/workflows/pr.yml` (github-actions) * `.gitea/workflows/release.yml` (github-actions) * `.gitea/workflows/test.yml` (github-actions) * `go.mod` (gomod) ### Configuration Summary Based on the default config's presets, Renovate will: - Start dependency updates only once this onboarding PR is merged - Enable Renovate Dependency Dashboard creation. - Use semantic commit type `fix` for dependencies and `chore` for all others if semantic commits are in use. - Ignore `node_modules`, `bower_components`, `vendor` and various test/tests (except for nuget) directories. - Group known monorepo packages together. - Use curated list of recommended non-monorepo package groupings. - Apply crowd-sourced package replacement rules. - Apply crowd-sourced workarounds for known problems with packages. - Preserve (but continue to upgrade) any existing SemVer ranges. - Enable Renovate Dependency Dashboard creation. - Rebase existing PRs any time the base branch has been updated. - Use semantic prefixes for commit messages and PR titles. - Raise PR when vulnerability alerts are detected with label `'security'`. - Group all `minor` and `patch` updates together. - Keep existing branches updated even when not scheduled. - Show all Merge Confidence badges for pull requests. 🔡 Do you want to change how Renovate upgrades your dependencies? Add your custom config to `renovate.json` in this branch. Renovate will update the Pull Request description the next time it runs. --- ### What to Expect With your current configuration, Renovate will create 2 Pull Requests:
chore(deps): update dependency go to 1.24 - Schedule: ["at any time"] - Branch name: `renovate/all-minor-patch` - Merge into: `main` - Upgrade [go](https://github.com/actions/go-versions) to `1.24`
chore(deps): update actions/setup-go action to v5 - Schedule: ["at any time"] - Branch name: `renovate/actions-setup-go-5.x` - Merge into: `main` - Upgrade [actions/setup-go](https://github.com/actions/setup-go) to `v5`
--- ❓ Got questions? Check out Renovate's [Docs](https://docs.renovatebot.com/), particularly the Getting Started section. If you need any further assistance then you can also [request help here](https://github.com/renovatebot/renovate/discussions). --- This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). Co-authored-by: Jan K9f Reviewed-on: https://git.kjan.de/actions/pull-request-lint/pulls/4 Co-authored-by: Renovate Bot Co-committed-by: Renovate Bot --- renovate.json | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 renovate.json diff --git a/renovate.json b/renovate.json new file mode 100644 index 0000000..c183f9d --- /dev/null +++ b/renovate.json @@ -0,0 +1,6 @@ +{ + "$schema": "https://docs.renovatebot.com/renovate-schema.json", + "extends": [ + "local>Renovate/renovate-config" + ] +} From 66f0f05e55ff5e4a2d103a97230d71179c46d3be Mon Sep 17 00:00:00 2001 From: Jan Klattenhoff Date: Wed, 9 Apr 2025 18:51:21 +0200 Subject: [PATCH 29/33] ci: update release workflow for error handling --- .gitea/workflows/release.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.gitea/workflows/release.yml b/.gitea/workflows/release.yml index e1a90fb..0eea3b6 100644 --- a/.gitea/workflows/release.yml +++ b/.gitea/workflows/release.yml @@ -52,23 +52,25 @@ jobs: run: | git add docs/ git commit -m "chore(release): [skip ci]" + continue-on-error: true - name: Push changes to release branch if: ${{ steps.semantic.outputs.new_release_published }} run: | git remote set-url origin git@${{ env.GITEA_DOMAIN }}:${{ github.repository }}.git git push origin HEAD:${{ env.RELEASE_BRANCH }} + continue-on-error: true - name: Checkout target branch - if: ${{ steps.semantic.outputs.new_release_published && !(env.SKIP_MERGE == true) }} + if: ${{ !(env.SKIP_MERGE == true) }} run: git reset --hard && git checkout ${{ env.TARGET_BRANCH }} && git pull - name: Merge release - if: ${{ steps.semantic.outputs.new_release_published && !(env.SKIP_MERGE == true) }} + if: ${{ !(env.SKIP_MERGE == true) }} run: git merge ${{ env.RELEASE_BRANCH }} - name: Push changes to target branch - if: ${{ steps.semantic.outputs.new_release_published && !(env.SKIP_MERGE == true) }} + if: ${{ !(env.SKIP_MERGE == true) }} run: | git remote set-url origin git@${{ env.GITEA_DOMAIN }}:${{ github.repository }}.git git push origin HEAD:${{ env.TARGET_BRANCH }} From 1b86948c602d130039b1e480b0f4c02a955cf732 Mon Sep 17 00:00:00 2001 From: Jan Klattenhoff Date: Wed, 9 Apr 2025 19:28:15 +0200 Subject: [PATCH 30/33] 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 31/33] 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 32/33] 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 ./... From a992d1cfd99449e4ffa507f4f74abae2c97f834c Mon Sep 17 00:00:00 2001 From: Gitea Actions Date: Wed, 9 Apr 2025 17:49:25 +0000 Subject: [PATCH 33/33] chore(release): [skip ci] --- docs/CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 4addfa4..15dad97 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,3 +1,10 @@ +# [1.1.0](https://git.kjan.de/actions/pull-request-lint/compare/v1.0.0...v1.1.0) (2025-04-09) + + +### Features + +* add linters ([#11](https://git.kjan.de/actions/pull-request-lint/issues/11)) ([e332ef8](https://git.kjan.de/actions/pull-request-lint/commit/e332ef87cbab6a7e0ebde5bd17a37b50c9aea967)) + # [1.0.0](https://git.kjan.de/actions/pull-request-lint/compare/v0.3.0...v1.0.0) (2025-04-09)