Skip to content

clean up ci, use go 1.24, apply best practices for ci and general clean up #107

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 16, 2025
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
12 changes: 9 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@ on:
- .gitignore
merge_group:

permissions: {}

jobs:
lint:
runs-on: ubuntu-latest

permissions:
contents: read

env:
GOPATH: /home/runner/go

Expand All @@ -22,20 +27,21 @@ jobs:
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
submodules: recursive
persist-credentials: false

- name: Setup Go
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
with:
go-version: '1.21'
go-version-file: './.go-version'
check-latest: true

- name: Format check
run: make fmt

- name: golangci-lint
uses: golangci/golangci-lint-action@aaa42aa0628b4ae2578232a66b541047968fac86 # v6.1.0
uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # v8.0.0
with:
version: v1.59
version: v2.2
args: --build-tags testonly

- name: Check generated code
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ on:
schedule:
- cron: '21 6 * * 6'


permissions: {}

jobs:
analyze:
name: Analyze (${{ matrix.language }})
Expand Down
12 changes: 10 additions & 2 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,22 @@ on:
- main
merge_group:


permissions: {}

jobs:
coverage:
runs-on: ubuntu-latest

permissions:
contents: read

strategy:
fail-fast: false
matrix:
go-version:
- '1.21'
- '1.22'
- '1.23'
- '1.24'

env:
GOPATH: /home/runner/go
Expand All @@ -31,6 +38,7 @@ jobs:
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
submodules: recursive
persist-credentials: false

- name: Setup Go
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/dco_merge_group.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ name: DCO
on:
merge_group:

permissions: {}

jobs:
DCO:
runs-on: ubuntu-latest
if: ${{ github.actor != 'dependabot[bot]' }}
steps:
- run: echo "dummy DCO workflow (it won't run any check actually) to trigger by merge_group in order to enable merge queue"
- run: echo "dummy DCO workflow (it won't run any check actually) to trigger by merge_group in order to enable merge queue"
1 change: 1 addition & 0 deletions .go-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.24.4
49 changes: 49 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
version: "2"
run:
issues-exit-code: 1
linters:
enable:
- asciicheck
- errorlint
- gocritic
- gosec
- importas
- misspell
- prealloc
# - revive # disabled due becasue ask to change some variables and functions that might break the api compatibility
- staticcheck
- tparallel
- unconvert
- unparam
- whitespace

exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
rules:
- linters:
- errcheck
- gosec
path: _test\.go
paths:
- third_party$
- builtin$
- examples$
issues:
max-issues-per-linter: 0
max-same-issues: 0
uniq-by-line: false
formatters:
enable:
- gofmt
- goimports
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$
15 changes: 7 additions & 8 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
version: 2

before:
hooks:
- go mod tidy

builds:
- env:
- CGO_ENABLED=0
goos:
- linux
- windows
- darwin
archives:
- replacements:
darwin: Darwin
linux: Linux
windows: Windows
386: i386
amd64: x86_64

checksum:
name_template: 'checksums.txt'

snapshot:
name_template: "{{ incpatch .Version }}-next"
version_template: "{{ incpatch .Version }}-next"

changelog:
sort: asc
filters:
Expand Down
3 changes: 1 addition & 2 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ You must install these tools:
1. [`git`](https://help.github.com/articles/set-up-git/): For source control

1. [`go`](https://golang.org/doc/install): The language this SDK is built in.
> **Note** Golang [version v1.18](https://golang.org/dl/) or higher is required.
> **Note** Golang [version v1.23](https://golang.org/dl/) or higher is required.

1. [`make`](https://www.gnu.org/software/make/): not stricly required but handy to run
tests with a single command.
Expand Down Expand Up @@ -85,4 +85,3 @@ To run all targets, before creating a commit:
```shell
make all
```

6 changes: 3 additions & 3 deletions pkg/api/bindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
// Validate the event
err := Validate(event)
if err != nil {
return nil, fmt.Errorf("cannot validate CDEvent %v", err)
return nil, fmt.Errorf("cannot validate CDEvent %w", err)
}
ce := cloudevents.NewEvent()
ce.SetID(event.GetId())
Expand Down Expand Up @@ -149,10 +149,10 @@
var v interface{}
jsonString, err := AsJsonString(event)
if err != nil {
return fmt.Errorf("cannot render the event %s as json %s", event, err)
return fmt.Errorf("cannot render the event %s as json %w", event, err)

Check warning on line 152 in pkg/api/bindings.go

View check run for this annotation

Codecov / codecov/patch

pkg/api/bindings.go#L152

Added line #L152 was not covered by tests
}
if err := json.Unmarshal([]byte(jsonString), &v); err != nil {
return fmt.Errorf("cannot unmarshal event json: %v", err)
return fmt.Errorf("cannot unmarshal event json: %w", err)

Check warning on line 155 in pkg/api/bindings.go

View check run for this annotation

Codecov / codecov/patch

pkg/api/bindings.go#L155

Added line #L155 was not covered by tests
}
// Validate the "validate" tags
if err := validate.Struct(event); err != nil {
Expand Down
11 changes: 2 additions & 9 deletions pkg/api/bindings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func setContext(event api.CDEventWriter, subjectId string) {
event.SetSubjectId(subjectId)
}

func setContextV04(event api.CDEventWriterV04, chainId, schemaUri bool) {
func setContextV04(event api.CDEventWriterV04, chainId, schemaUri bool) { //nolint: unparam
if chainId {
event.SetChainId(testChainId)
}
Expand Down Expand Up @@ -239,7 +239,6 @@ func init() {
// TestAsCloudEvent produces a CloudEvent from a CDEvent using `AsCloudEvent`
// and then attempts to parse the CloudEvent payload back into a specific CDEvent
func TestAsCloudEvent(t *testing.T) {

tests := []struct {
name string
event api.CDEventReader
Expand Down Expand Up @@ -309,7 +308,6 @@ func TestAsCloudEvent(t *testing.T) {
}

func TestAsCloudEventInvalid(t *testing.T) {

tests := []struct {
name string
event api.CDEventReader
Expand Down Expand Up @@ -353,7 +351,6 @@ func TestAsCloudEventInvalid(t *testing.T) {
// rendered JSON depends on a number of factors, and is not deterministic
// so we must compare events unmarshalled to an interface
func TestAsJsonBytes(t *testing.T) {

tests := []struct {
name string
event api.CDEvent
Expand Down Expand Up @@ -393,7 +390,7 @@ func TestAsJsonBytes(t *testing.T) {
if err != nil {
t.Fatalf("didn't expected it to fail, but it did: %v", err)
}
err = json.Unmarshal([]byte(obtainedJsonString), &obtainedInteface)
err = json.Unmarshal(obtainedJsonString, &obtainedInteface)
if err != nil {
t.Fatalf("didn't expected it to fail, but it did: %v", err)
}
Expand All @@ -409,7 +406,6 @@ func TestAsJsonBytes(t *testing.T) {
}

func TestInvalidEvent(t *testing.T) {

// mandatory source missing
eventNoSource, _ := testapi.NewFooSubjectBarPredicateEvent()
eventNoSource.SetSubjectId(testSubjectId)
Expand Down Expand Up @@ -506,7 +502,6 @@ func TestAsJsonStringEmpty(t *testing.T) {
}

func TestNewFromJsonString(t *testing.T) {

tests := []struct {
name string
event api.CDEventV04
Expand Down Expand Up @@ -582,7 +577,6 @@ func TestNewFromJsonString(t *testing.T) {
}

func TestParseType(t *testing.T) {

tests := []struct {
name string
eventType string
Expand Down Expand Up @@ -668,7 +662,6 @@ func testEventWithVersion(eventVersion string, specVersion string) *testapi.FooS
}

func TestNewFromJsonBytes(t *testing.T) {

minorVersion := testEventWithVersion("2.999.1", testapi.SpecVersion)
patchVersion := testEventWithVersion("2.2.999", testapi.SpecVersion)
pastPatchVersion := testEventWithVersion("2.2.0", testapi.SpecVersion)
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
var timeNow = time.Now
var uuidNewRandom = uuid.NewRandom

func initCDEvent(e CDEvent) (CDEvent, error) {
func initCDEvent(e CDEvent) (CDEvent, error) { //nolint: unparam
eventUUID, err := uuidNewRandom()
if err != nil {
return nil, err
Expand Down
9 changes: 5 additions & 4 deletions pkg/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,28 +290,29 @@
if err != nil {
return err
}
if m.LinkType == LinkTypeEnd {
switch m.LinkType {
case LinkTypeEnd:
var e embeddedLinkEnd
err = json.Unmarshal(*rawEmbeddedLink, &e)
if err != nil {
return err
}
receiver[index] = &e
} else if m.LinkType == LinkTypePath {
case LinkTypePath:
var e embeddedLinkPath
err = json.Unmarshal(*rawEmbeddedLink, &e)
if err != nil {
return err
}
receiver[index] = &e
} else if m.LinkType == LinkTypeRelation {
case LinkTypeRelation:
var e embeddedLinkRelation
err = json.Unmarshal(*rawEmbeddedLink, &e)
if err != nil {
return err
}
receiver[index] = &e
} else {
default:

Check warning on line 315 in pkg/api/types.go

View check run for this annotation

Codecov / codecov/patch

pkg/api/types.go#L315

Added line #L315 was not covered by tests
return fmt.Errorf("unsupported link type %s found", m.LinkType)
}
}
Expand Down
8 changes: 1 addition & 7 deletions pkg/api/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ type testWrongType struct {
}

func TestGetCustomDataAsNonJson(t *testing.T) {

receiver := &testType{}
expectedError := "cannot unmarshal content-type application/xml"

Expand All @@ -91,7 +90,6 @@ func TestGetCustomDataAsNonJson(t *testing.T) {
}

func TestGetCustomDataAsJson(t *testing.T) {

receiver := &testType{}
expectedValue := "testValue"

Expand Down Expand Up @@ -127,7 +125,6 @@ func TestGetCustomDataAsJson(t *testing.T) {
}

func TestGetCustomDataAsJsonInvalidReceiver(t *testing.T) {

receiver := &testWrongType{}
expectedReceiver := &testWrongType{}

Expand Down Expand Up @@ -163,7 +160,6 @@ func TestGetCustomDataAsJsonInvalidReceiver(t *testing.T) {
}

func TestSetCustomData(t *testing.T) {

tests := []struct {
name string
contentType string
Expand Down Expand Up @@ -215,7 +211,6 @@ func TestSetCustomDataInvalid(t *testing.T) {
}

func TestGetCustomData(t *testing.T) {

tests := []struct {
name string
contentType string
Expand Down Expand Up @@ -302,7 +297,6 @@ func TestGetCustomDataXmlNotBytes(t *testing.T) {
}

func TestGetCustomDataRaw(t *testing.T) {

tests := []struct {
name string
contentType string
Expand All @@ -327,7 +321,7 @@ func TestGetCustomDataRaw(t *testing.T) {
name: "json, interface",
contentType: "application/json",
data: testType{TestData: "testValue"},
expectedData: []byte(testJsonString),
expectedData: testJsonString,
}}

for _, tc := range tests {
Expand Down
Loading
Loading