Skip to content
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

ci: add a continuous integration pipeline #1

Closed
wants to merge 2 commits into from
Closed
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
8 changes: 6 additions & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{
"image": "mcr.microsoft.com/devcontainers/go:1-bullseye"
"image": "mcr.microsoft.com/devcontainers/go:1-bullseye",
"features": {
"ghcr.io/devcontainers/features/docker-in-docker:2": {}
},

"postCreateCommand": "curl -L https://dl.dagger.io/dagger/install.sh | BIN_DIR=$HOME/.local/bin sh; sh -c \"$(curl --location https://taskfile.dev/install.sh)\" -- -d -b $HOME/.local/bin",
}

42 changes: 20 additions & 22 deletions .github/workflows/continuous-delivery.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,27 @@
name: Plugin PVC Backup CI
name: Continuous Integration

on:
push:
branches:
- main
pull_request:
branches:
- main
workflow_dispatch:
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: '>=1.19.0'
- run: make check
name: "Linters"

unit-tests:
jobs:
ci:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
- name: Checkout
uses: actions/checkout@v4
# We need the full history for the commitlint task
with:
go-version: '>=1.19.0'
- run: make test
name: "Unit tests"
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}
- name: Install Task
uses: arduino/setup-task@v2
- name: Install Dagger
env:
# renovate: datasource=github-tags depName=dagger/dagger versioning=semver
DAGGER_VERSION: 0.11.9
run: |
curl -L https://dl.dagger.io/dagger/install.sh | BIN_DIR=$HOME/.local/bin sh
- name: Run CI task
run: |
task ci
12 changes: 5 additions & 7 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
name: release-please

on:
push:
branches:
- main
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
name: release-please

jobs:
release-please:
runs-on: ubuntu-latest
steps:
- uses: google-github-actions/release-please-action@v3
- uses: google-github-actions/release-please-action@v4
id: release
with:
release-type: go
package-name: plugin_pvc_backup
token: ${{secrets.REPO_PAT}}
token: ${{ secrets.REPO_PAT }}
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
bin/
dist/
.env
.vscode/
.idea/
.task/
.vscode/
120 changes: 25 additions & 95 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,108 +8,38 @@ linters-settings:
- prefix(github.com/cloudnative-pg/cnpg-i-machinery)
- blank
- dot
nlreturn:
# Size of the block (including return statement that is still "OK")
# so no return split required.
# Default: 1
block-size: 3

linters:
# please, do not use `enable-all`: it's deprecated and will be removed soon.
# inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
disable-all: true
enable:
- asciicheck
- bodyclose
- dogsled
- dupl
- durationcheck
- errcheck
- exportloopref
- gci
- gocognit
- goconst
- gocritic
- gocyclo
- gofmt
- gofumpt
- goheader
- goimports
- gomoddirectives
- gomodguard
- goprintffuncname
- gosec
- gosimple
- govet
- importas
- ineffassign
- lll
- makezero
- misspell
- nakedret
- nestif
- prealloc
- predeclared
- revive
- rowserrcheck
- sqlclosecheck
- staticcheck
- stylecheck
- thelper
- tparallel
- typecheck
- unconvert
- unparam
- unused
- wastedassign
- whitespace

# to be checked:
# - errorlint
# - forbidigo
# - forcetypeassert
# - goerr113
# - ifshort
# - nilerr
# - nlreturn
# - noctx
# - nolintlint
# - paralleltest
# - promlinter
# - tagliatelle
# - wrapcheck

# don't enable:
# - cyclop
# - depguard
# - exhaustive
# - exhaustivestruct
# - funlen
# - gochecknoglobals
# - gochecknoinits
# - godot
# - godox
# - gomnd
# - testpackage
# - wsl

# deprecated:
# - deadcode
# - golint
# - interfacer
# - maligned
# - scopelint
# - structcheck
# - varcheck

run:
skip-files: "zz_generated.*"
enable-all: true
disable:
- depguard
- execinquery
- exhaustruct
- funlen
- gomnd
- wsl

issues:
exclude-rules:
# Allow dot imports for ginkgo and gomega
- source: ginkgo|gomega
linters:
- revive
text: "should not use dot imports"
# Exclude some linters from running on tests files.
- path: _test\.go
linters:
- goconst
# Exclude lll issues for lines with long annotations
- linters:
- lll
source: "//\\s*\\+"
# We have no control of this in zz_generated files and it looks like that excluding those files is not enough
# so we disable "ST1016: methods on the same type should have the same receiver name" in api directory
- linters:
- stylecheck
text: "ST1016:"
path: api/
exclude-use-default: false

run:
timeout: 5m
2 changes: 1 addition & 1 deletion .spellcheck.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
matrix:
- name: Python Source
- name: Source
sources:
- ./**/*.go
- ./**/*.md
Expand Down
3 changes: 1 addition & 2 deletions .wordlist.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
sidebarToggle
pvc
cnpg
11 changes: 0 additions & 11 deletions Makefile

This file was deleted.

75 changes: 75 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
version: '3'

tasks:
spellcheck:
desc: Run spellcheck
env:
# renovate: datasource=git-refs depName=spellcheck lookupName=https://github.com/cloudnative-pg/daggerverse currentValue=main
DAGGER_SPELLCHECK_SHA: 2b7d0f2bfe2c36ae415d34dcf6767a0cd831fc53
cmds:
- >
GITHUB_REF= dagger -s call -m github.com/cloudnative-pg/daggerverse/spellcheck@${DAGGER_SPELLCHECK_SHA}
spellcheck --source . stdout
sources:
- ./**

lint:
desc: Run golangci-lint
env:
# renovate: datasource=git-refs depName=golangci-lint lookupName=https://github.com/sagikazarmark/daggerverse currentValue=main
DAGGER_GOLANGCI_LINT_SHA: b249f27c0d6a2183cd368ae767fc912a09a1a40f
cmds:
- >
GITHUB_REF= dagger -s call -m github.com/sagikazarmark/daggerverse/golangci-lint@${DAGGER_GOLANGCI_LINT_SHA}
run --source . --config .golangci.yml stdout
sources:
- ./**/*.go
- .golangci.yml

commitlint:
desc: Check for conventional commits
env:
# renovate: datasource=git-refs depName=commitlint lookupName=https://github.com/cloudnative-pg/daggerverse currentValue=main
DAGGER_COMMITLINT_SHA: 2b7d0f2bfe2c36ae415d34dcf6767a0cd831fc53
cmds:
- GITHUB_REF= dagger -s call -m github.com/cloudnative-pg/daggerverse/commitlint@${DAGGER_COMMITLINT_SHA} lint --source . --args "--from=origin/main" stdout

uncommitted:
desc: Check for uncommitted changes
env:
# renovate: datasource=git-refs depName=uncommitted lookupName=https://github.com/cloudnative-pg/daggerverse currentValue=main
DAGGER_UNCOMMITTED_SHA: 2b7d0f2bfe2c36ae415d34dcf6767a0cd831fc53
cmds:
- >
GITHUB_REF= dagger -s call -m github.com/cloudnative-pg/daggerverse/uncommitted@${DAGGER_UNCOMMITTED_SHA}
check-uncommitted --source . stdout
sources:
- ./**

go-test:
desc: Run go test
env:
# TODO: configure renovate
GOLANG_IMAGE_VERSION: golang:1.22.4
# renovate: datasource=git-refs depName=gotest lookupName=https://github.com/Excoriate/daggerverse currentValue=main
DAGGER_GOTEST_SHA: f09d41cb90701db446048a9f20eb03495e50f727
cmds:
- >
GITHUB_REF= dagger -s call -m github.com/Excoriate/daggerverse/gotest@90a5d911a70510f9004544d4a25d39d917f1f668
base --image-url ${GOLANG_IMAGE_VERSION}
with-cgo-disabled
run-go-test --src .

ci:
desc: Run the CI pipeline
deps:
- commitlint
- uncommitted
- spellcheck
- lint
- go-test

clean:
desc: Remove autogenerated artifacts
cmds:
- rm -rf .task/
12 changes: 12 additions & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const Configuration= {
extends: ['@commitlint/config-conventional'],
formatter: '@commitlint/format',
rules: {
'body-empty': [1, 'never'],
'body-case': [2, 'always', 'sentence-case'],
'references-empty': [1, 'never'],
'signed-off-by': [2, 'always', 'Signed-off-by:'],
},
};

module.exports = Configuration;
7 changes: 4 additions & 3 deletions pkg/logging/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,20 @@ func newLogger(debug bool) logr.Logger {
}

result := zapr.NewLogger(zapLog)

return result
}

// IntoContext injects the logger into the passed context, returning
// a context having the logger embedded. The logger can be recovered
// with FromContext
// with FromContext.
func IntoContext(ctx context.Context, logger logr.Logger) context.Context {
return logr.NewContext(ctx, logger)
}

// NewIntoContext injects a new logger into the passed context, returning
// a context having the logger embedded. The logger can be recovered
// with FromContext
// with FromContext.
func NewIntoContext(ctx context.Context, debug bool) context.Context {
logger := newLogger(debug)
return IntoContext(ctx, logger)
Expand All @@ -62,11 +63,11 @@ func NewIntoContext(ctx context.Context, debug bool) context.Context {
//
// This should probably have a means of panicking if a logger is not found
// during development.
//
func FromContext(ctx context.Context) logr.Logger {
logger, err := logr.FromContext(ctx)
if err != nil {
return newLogger(false)
}

return logger
}
Loading