ci: new build pipeline
This commit is contained in:
parent
ceb7d04edd
commit
203438dc8c
3 changed files with 81 additions and 154 deletions
81
.forgejo/workflows/build.yml
Normal file
81
.forgejo/workflows/build.yml
Normal file
|
@ -0,0 +1,81 @@
|
||||||
|
name: Build
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
- beta
|
||||||
|
- develop
|
||||||
|
pull_request:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
checks:
|
||||||
|
name: Checks
|
||||||
|
runs-on: docker
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
- name: Setup Go
|
||||||
|
uses: actions/setup-go@v5
|
||||||
|
with:
|
||||||
|
go-version: '1.23.x'
|
||||||
|
check-latest: true
|
||||||
|
- name: Run go fmt and go vet
|
||||||
|
run: |
|
||||||
|
go fmt $(go list ./...)
|
||||||
|
go vet $(go list ./...)
|
||||||
|
|
||||||
|
code-coverage:
|
||||||
|
name: Code Coverage
|
||||||
|
runs-on: docker
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
- name: Setup Go
|
||||||
|
uses: actions/setup-go@v5
|
||||||
|
with:
|
||||||
|
go-version: '1.23.x'
|
||||||
|
check-latest: true
|
||||||
|
- name: Run tests and generate coverage report
|
||||||
|
run: |
|
||||||
|
go test -covermode=count -coverprofile coverage.cov $(go list ./...)
|
||||||
|
go tool cover -func=coverage.cov
|
||||||
|
go tool cover -html=coverage.cov -o coverage.html
|
||||||
|
- name: Upload coverage artifacts
|
||||||
|
uses: https://code.forgejo.org/forgejo/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: coverage-reports
|
||||||
|
path: |
|
||||||
|
coverage.cov
|
||||||
|
coverage.html
|
||||||
|
|
||||||
|
build:
|
||||||
|
name: Build
|
||||||
|
runs-on: docker
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
go:
|
||||||
|
- GOOS: darwin
|
||||||
|
GOARCH: amd64
|
||||||
|
- GOOS: darwin
|
||||||
|
GOARCH: arm64
|
||||||
|
- GOOS: linux
|
||||||
|
GOARCH: amd64
|
||||||
|
- GOOS: linux
|
||||||
|
GOARCH: arm64
|
||||||
|
- GOOS: windows
|
||||||
|
GOARCH: amd64
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
- name: Setup Go
|
||||||
|
uses: actions/setup-go@v5
|
||||||
|
with:
|
||||||
|
go-version: '1.23.x'
|
||||||
|
check-latest: true
|
||||||
|
- name: Set environment variables
|
||||||
|
run: |
|
||||||
|
echo "GOOS=${{ matrix.go.GOOS }}" >> $GITHUB_ENV
|
||||||
|
echo "GOARCH=${{ matrix.go.GOARCH }}" >> $GITHUB_ENV
|
||||||
|
- name: Build
|
||||||
|
run: go build .
|
135
.gitlab-ci.yml
135
.gitlab-ci.yml
|
@ -1,135 +0,0 @@
|
||||||
image: golang:1.19
|
|
||||||
|
|
||||||
stages:
|
|
||||||
- test
|
|
||||||
- build
|
|
||||||
- pre-release
|
|
||||||
|
|
||||||
checks:
|
|
||||||
stage: test
|
|
||||||
script:
|
|
||||||
- go fmt $(go list ./...)
|
|
||||||
- go vet $(go list ./...)
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
|
|
||||||
code coverage:
|
|
||||||
stage: test
|
|
||||||
script:
|
|
||||||
- go install honnef.co/go/tools/cmd/staticcheck@latest
|
|
||||||
- go fmt $(go list ./...)
|
|
||||||
- go vet $(go list ./...)
|
|
||||||
- staticcheck ./...
|
|
||||||
- go test -coverprofile coverage.cov -p 1 $(go list ./...)
|
|
||||||
- go tool cover -html=coverage.cov -o coverage.html
|
|
||||||
- go tool cover -func=coverage.cov
|
|
||||||
coverage: '/\(statements\)\W+\d+\.\d+%/'
|
|
||||||
artifacts:
|
|
||||||
paths:
|
|
||||||
- coverage.cov
|
|
||||||
- coverage.html
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
|
|
||||||
codecov.io:
|
|
||||||
stage: test
|
|
||||||
script:
|
|
||||||
- curl https://keybase.io/codecovsecurity/pgp_keys.asc | gpg --import
|
|
||||||
- curl -Os https://uploader.codecov.io/latest/linux/codecov
|
|
||||||
- curl -Os https://uploader.codecov.io/latest/linux/codecov.SHA256SUM
|
|
||||||
- curl -Os https://uploader.codecov.io/latest/linux/codecov.SHA256SUM.sig
|
|
||||||
- gpg --verify codecov.SHA256SUM.sig codecov.SHA256SUM
|
|
||||||
- shasum -a 256 -c codecov.SHA256SUM
|
|
||||||
- chmod +x codecov
|
|
||||||
- go test -race -coverprofile=coverage.out -covermode=atomic
|
|
||||||
- ./codecov -t ${CODECOV_TOKEN}
|
|
||||||
rules:
|
|
||||||
- if: $CODECOV_TOKEN
|
|
||||||
when: on_success
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
|
|
||||||
# stage "sonarcloud" is only needed because of this issue:
|
|
||||||
# https://gitlab.com/gitlab-org/gitlab/-/issues/30632
|
|
||||||
sonarcloud-check:
|
|
||||||
stage: test
|
|
||||||
needs:
|
|
||||||
- checks
|
|
||||||
image:
|
|
||||||
name: sonarsource/sonar-scanner-cli:latest
|
|
||||||
entrypoint: [""]
|
|
||||||
variables:
|
|
||||||
SONAR_USER_HOME: "${CI_PROJECT_DIR}/.sonar" # Defines the location of the analysis task cache
|
|
||||||
GIT_DEPTH: "0" # Tells git to fetch all the branches of the project, required by the analysis task
|
|
||||||
cache:
|
|
||||||
key: "${CI_JOB_NAME}"
|
|
||||||
paths:
|
|
||||||
- .sonar/cache
|
|
||||||
script:
|
|
||||||
- sonar-scanner
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
allow_failure: true
|
|
||||||
|
|
||||||
# build template
|
|
||||||
# execute the following command for all os/arch combinations: go tool dist list
|
|
||||||
.compile:
|
|
||||||
stage: build
|
|
||||||
# no dependencies -> no download of artifacts from previous jobs/stages
|
|
||||||
dependencies: []
|
|
||||||
script:
|
|
||||||
- go build .
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
|
|
||||||
darwin-amd64:
|
|
||||||
extends: .compile
|
|
||||||
variables:
|
|
||||||
GOOS: "darwin"
|
|
||||||
GOARCH: "amd64"
|
|
||||||
|
|
||||||
linux-amd64:
|
|
||||||
extends: .compile
|
|
||||||
variables:
|
|
||||||
GOOS: "linux"
|
|
||||||
GOARCH: "amd64"
|
|
||||||
|
|
||||||
linux-arm64:
|
|
||||||
extends: .compile
|
|
||||||
variables:
|
|
||||||
GOOS: "linux"
|
|
||||||
GOARCH: "arm64"
|
|
||||||
|
|
||||||
windows-amd64:
|
|
||||||
extends: .compile
|
|
||||||
variables:
|
|
||||||
GOOS: "windows"
|
|
||||||
GOARCH: "amd64"
|
|
||||||
|
|
||||||
.semantic-release:
|
|
||||||
stage: pre-release
|
|
||||||
image: node:20-buster-slim
|
|
||||||
dependencies: []
|
|
||||||
before_script:
|
|
||||||
- apt-get update && apt-get install -y --no-install-recommends git-core ca-certificates
|
|
||||||
- npm install -g semantic-release@23 @semantic-release/gitlab@13 conventional-changelog-conventionalcommits@7
|
|
||||||
script:
|
|
||||||
- semantic-release -d $DRY_RUN
|
|
||||||
variables:
|
|
||||||
GL_TOKEN: $SEMANTIC_RELEASE_TOKEN
|
|
||||||
DRY_RUN: "false"
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
|
|
||||||
semantic-release-dry-run:
|
|
||||||
extends: .semantic-release
|
|
||||||
variables:
|
|
||||||
DRY_RUN: "true"
|
|
||||||
rules:
|
|
||||||
- if: '$CI_COMMIT_BRANCH == "main" || $CI_COMMIT_BRANCH == "beta"'
|
|
||||||
|
|
||||||
semantic-release:
|
|
||||||
extends: .semantic-release
|
|
||||||
rules:
|
|
||||||
- if: '$CI_COMMIT_BRANCH == "main" || $CI_COMMIT_BRANCH == "beta"'
|
|
||||||
when: manual
|
|
|
@ -1,19 +0,0 @@
|
||||||
sonar.projectKey=martinr92_gohttprouter
|
|
||||||
sonar.organization=martinr92
|
|
||||||
|
|
||||||
# This is the name and version displayed in the SonarCloud UI.
|
|
||||||
#sonar.projectName=goHTTPRouter
|
|
||||||
#sonar.projectVersion=1.0
|
|
||||||
|
|
||||||
# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
|
|
||||||
sonar.sources=.
|
|
||||||
sonar.exclusions=**/*_test.go,coverage.cov,coverage.html
|
|
||||||
|
|
||||||
sonar.tests=.
|
|
||||||
sonar.test.inclusions=**/*_test.go
|
|
||||||
|
|
||||||
# Encoding of the source code. Default is default system encoding
|
|
||||||
#sonar.sourceEncoding=UTF-8
|
|
||||||
|
|
||||||
# Golang
|
|
||||||
sonar.go.coverage.reportPaths=coverage.cov
|
|
Loading…
Add table
Reference in a new issue