Skip to content
Snippets Groups Projects
Commit 9055ab51 authored by Pierre Smeyers's avatar Pierre Smeyers
Browse files

feat: migrate to CI/CD component

:warning: requires GitLab 16.6 or later
parent 07f2b8eb
No related branches found
No related tags found
No related merge requests found
...@@ -10,7 +10,7 @@ include: ...@@ -10,7 +10,7 @@ include:
file: '/templates/validation.yml' file: '/templates/validation.yml'
- project: 'to-be-continuous/bash' - project: 'to-be-continuous/bash'
ref: '3.3' ref: '3.3'
file: 'templates/gitlab-ci-bash.yml' file: '/templates/gitlab-ci-bash.yml'
- project: 'to-be-continuous/semantic-release' - project: 'to-be-continuous/semantic-release'
ref: '3.7' ref: '3.7'
file: '/templates/gitlab-ci-semrel.yml' file: '/templates/gitlab-ci-semrel.yml'
......
...@@ -4,25 +4,48 @@ This project implements a GitLab CI/CD template to build, test and analyse your ...@@ -4,25 +4,48 @@ This project implements a GitLab CI/CD template to build, test and analyse your
## Usage ## Usage
In order to include this template in your project, add the following to your `gitlab-ci.yml`: This template can be used both as a [CI/CD component](https://docs.gitlab.com/ee/ci/components/#use-a-component-in-a-cicd-configuration)
or using the legacy [`include:project`](https://docs.gitlab.com/ee/ci/yaml/index.html#includeproject) syntax.
### Use as a CI/CD component
Add the following to your `gitlab-ci.yml`:
```yaml
include:
# 1: include the component
- component: gitlab.com/to-be-continuous/golang/gitlab-ci-golang@4.7.0
# 2: set/override component inputs
inputs:
image: "registry.hub.docker.com/library/golang:buster" # ⚠ this is only an example
```
### Use as a CI/CD template (legacy)
Add the following to your `gitlab-ci.yml`:
```yaml ```yaml
include: include:
# 1: include the template
- project: 'to-be-continuous/golang' - project: 'to-be-continuous/golang'
ref: '4.7.0' ref: '4.7.0'
file: '/templates/gitlab-ci-golang.yml' file: '/templates/gitlab-ci-golang.yml'
variables:
# 2: set/override template variables
GO_IMAGE: "registry.hub.docker.com/library/golang:buster" # ⚠ this is only an example
``` ```
## Global configuration ## Global configuration
The Go template uses some global configuration used throughout all jobs. The Go template uses some global configuration used throughout all jobs.
| Name | Description | Default value | | Input / Variable | Description | Default value |
|------------------|------------------------------------------------------------------------------------------------------------|-----------------| |------------------|------------------------------------------------------------------------------------------------------------|-----------------|
| `GO_IMAGE` | The Docker image used to run Go for `go-build` <br/>:warning: **set the version required by your project** | `registry.hub.docker.com/library/golang:buster` | | `image` / `GO_IMAGE` | The Docker image used to run Go for `go-build` <br/>:warning: **set the version required by your project** | `registry.hub.docker.com/library/golang:bookworm` |
| `GO_TEST_IMAGE` | The Docker image used to run Go for `go-test` <br/>:warning: **set the version required by your project** | _none_ | | `test-image` / `GO_TEST_IMAGE` | The Docker image used to run Go for `go-test` <br/>:warning: **set the version required by your project** | _none_ |
| `GO_PROJECT_DIR` | Go project root directory | `.` | | `project-dir` / `GO_PROJECT_DIR` | Go project root directory | `.` |
| `GOPROXY` | URL of Go module proxy | _none_ | | `goproxy` / `GOPROXY` | URL of Go module proxy | _none_ |
## Jobs ## Jobs
...@@ -68,18 +91,18 @@ go-build: ...@@ -68,18 +91,18 @@ go-build:
These jobs use the following variable: These jobs use the following variable:
| Name | Description | Default value | | Input / Variable | Description | Default value |
|-------------------------|-------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------| |-------------------------|-------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------|
| `GO_BUILD_MODE` | The template build mode (accepted values are `application`, `modules` and `auto`) | `auto` | | `build-mode` / `GO_BUILD_MODE` | The template build mode (accepted values are `application`, `modules` and `auto`) | `auto` |
| `GO_BUILD_FLAGS` | Flags used by the [go build command](https://pkg.go.dev/cmd/go#hdr-Compile_packages_and_dependencies) | `-mod=readonly` | | `build-flags` / `GO_BUILD_FLAGS` | Flags used by the [go build command](https://pkg.go.dev/cmd/go#hdr-Compile_packages_and_dependencies) | `-mod=readonly` |
| `GO_BUILD_LINKER_FLAGS` | Linker flags used by the [go build command](https://pkg.go.dev/cmd/go#hdr-Compile_packages_and_dependencies) `-ldflags` | `-s -w` | | `build-linker-flags` / `GO_BUILD_LINKER_FLAGS` | Linker flags used by the [go build command](https://pkg.go.dev/cmd/go#hdr-Compile_packages_and_dependencies) `-ldflags` | `-s -w` |
| `GO_BUILD_PACKAGES` | Packages to build with the [go build command](https://pkg.go.dev/cmd/go#hdr-Compile_packages_and_dependencies) | `./...` | | `build-packages` / `GO_BUILD_PACKAGES` | Packages to build with the [go build command](https://pkg.go.dev/cmd/go#hdr-Compile_packages_and_dependencies) | `./...` |
| `GO_TEST_FLAGS` | Flags used by the [go test command](https://pkg.go.dev/cmd/go#hdr-Test_packages) | `-mod=readonly -v -race` | | `test-flags` / `GO_TEST_FLAGS` | Flags used by the [go test command](https://pkg.go.dev/cmd/go#hdr-Test_packages) | `-mod=readonly -v -race` |
| `GO_TEST_PACKAGES` | Packages to test with the [go test command](https://pkg.go.dev/cmd/go#hdr-Test_packages) | `./...` | | `test-packages` / `GO_TEST_PACKAGES` | Packages to test with the [go test command](https://pkg.go.dev/cmd/go#hdr-Test_packages) | `./...` |
| `GO_LIST_ARGS` | Arguments used by the list command | `list -u -m -mod=readonly -json all` | | `list-args` / `GO_LIST_ARGS` | Arguments used by the list command | `list -u -m -mod=readonly -json all` |
| `GO_TARGET_OS` | The `GOOS` target [see available values](https://gist.github.com/asukakenji/f15ba7e588ac42795f421b48b8aede63) | _none_ (fallback to go docker image `GOOS`) | | `target-os` / `GO_TARGET_OS` | The `GOOS` target [see available values](https://gist.github.com/asukakenji/f15ba7e588ac42795f421b48b8aede63) | _none_ (fallback to go docker image `GOOS`) |
| `GO_TARGET_ARCH` | The `GOARCH` target [see available values](https://gist.github.com/asukakenji/f15ba7e588ac42795f421b48b8aede63) | _none_ (fallback to go docker image `GOARCH`) | | `target-arch` / `GO_TARGET_ARCH` | The `GOARCH` target [see available values](https://gist.github.com/asukakenji/f15ba7e588ac42795f421b48b8aede63) | _none_ (fallback to go docker image `GOARCH`) |
| `GO_COBERTURA_FLAGS` | The `GOFLAGS` to use with `gocover-cobertura` if needed | _none_ | | `cobertura-flags` / `GO_COBERTURA_FLAGS` | The `GOFLAGS` to use with `gocover-cobertura` if needed | _none_ |
In addition to a textual report in the console, the test jobs produce the following reports, kept for one day: In addition to a textual report in the console, the test jobs produce the following reports, kept for one day:
...@@ -97,11 +120,11 @@ This job enables a manual [GolangCI-Lint](https://github.com/golangci/golangci-l ...@@ -97,11 +120,11 @@ This job enables a manual [GolangCI-Lint](https://github.com/golangci/golangci-l
It is bound to the `build` stage, and uses the following variables: It is bound to the `build` stage, and uses the following variables:
| Name | Description | Default value | | Input / Variable | Description | Default value |
|-----------------------|----------------------------------------------------------------------------------------------------------|----------------------------------------| |-----------------------|----------------------------------------------------------------------------------------------------------|----------------------------------------|
| `GO_CI_LINT_IMAGE` | The Docker image used to run `golangci-lint` | `registry.hub.docker.com/golangci/golangci-lint:latest-alpine` | | `ci-lint-image` / `GO_CI_LINT_IMAGE` | The Docker image used to run `golangci-lint` | `registry.hub.docker.com/golangci/golangci-lint:latest-alpine` |
| `GO_CI_LINT_ARGS` | `golangci-lint` [command line arguments](https://github.com/golangci/golangci-lint#command-line-options) | `-E gosec,goimports ./...` | | `ci-lint-args` / `GO_CI_LINT_ARGS` | `golangci-lint` [command line arguments](https://github.com/golangci/golangci-lint#command-line-options) | `-E gosec,goimports ./...` |
| `GO_CI_LINT_DISABLED` | Set to `true` to disable this job | _none_(enabled) | | `ci-lint-disabled` / `GO_CI_LINT_DISABLED` | Set to `true` to disable this job | _none_(enabled) |
In addition to a textual report in the console, this job produces the following reports, kept for one day: In addition to a textual report in the console, this job produces the following reports, kept for one day:
...@@ -116,9 +139,9 @@ This job enables a manual [Go-mod-outdated](https://github.com/psampaz/go-mod-ou ...@@ -116,9 +139,9 @@ This job enables a manual [Go-mod-outdated](https://github.com/psampaz/go-mod-ou
It is bound to the `test` stage, and uses the following variables: It is bound to the `test` stage, and uses the following variables:
| Name | Description | Default value | | Input / Variable | Description | Default value |
|------------------------|-----------------------------------------------------------------------------------------------|-------------------| |------------------------|-----------------------------------------------------------------------------------------------|-------------------|
| `GO_MOD_OUTDATED_ARGS` | `god-mod-outdated` [command line arguments](https://github.com/psampaz/go-mod-outdated#usage) | `-update -direct` | | `mod-outdated-args` / `GO_MOD_OUTDATED_ARGS` | `god-mod-outdated` [command line arguments](https://github.com/psampaz/go-mod-outdated#usage) | `-update -direct` |
Checking outdated modules can be a long operation and therefore the job is configured to be ran **manually** by default (overridable). Checking outdated modules can be a long operation and therefore the job is configured to be ran **manually** by default (overridable).
...@@ -161,11 +184,11 @@ This job generates a [SBOM](https://cyclonedx.org/) file listing installed packa ...@@ -161,11 +184,11 @@ This job generates a [SBOM](https://cyclonedx.org/) file listing installed packa
It is bound to the `test` stage, and uses the following variables: It is bound to the `test` stage, and uses the following variables:
| Name | Description | Default value | | Input / Variable | Description | Default value |
| --------------------- | -------------------------------------- | ----------------- | | --------------------- | -------------------------------------- | ----------------- |
| `GO_SBOM_DISABLED` | Set to `true` to disable this job | _none_ | | `sbom-disabled` / `GO_SBOM_DISABLED` | Set to `true` to disable this job | _none_ |
| `GO_SBOM_IMAGE` | Image of cyclonedx-gomod used for SBOM analysis | `registry.hub.docker.com/cyclonedx/cyclonedx-gomod:latest` | | `sbom-image` / `GO_SBOM_IMAGE` | Image of cyclonedx-gomod used for SBOM analysis | `registry.hub.docker.com/cyclonedx/cyclonedx-gomod:latest` |
| `GO_SBOM_OPTS` | [@cyclonedx/cyclonedx-gomod options](https://github.com/CycloneDX/cyclonedx-gomod#usage) used for SBOM analysis | `-main .` | | `sbom-opts` / `GO_SBOM_OPTS` | [@cyclonedx/cyclonedx-gomod options](https://github.com/CycloneDX/cyclonedx-gomod#usage) used for SBOM analysis | `-main .` |
:warning: if you don't have your main class located at the root of your `GO_PROJECT_DIR`, then you will need to override the `-main` option in `GO_SBOM_OPTS` and define your real main class location. :warning: if you don't have your main class located at the root of your `GO_PROJECT_DIR`, then you will need to override the `-main` option in `GO_SBOM_OPTS` and define your real main class location.
...@@ -182,7 +205,7 @@ This job enables Vulnerability Management with [Govulncheck](https://go.dev/blog ...@@ -182,7 +205,7 @@ This job enables Vulnerability Management with [Govulncheck](https://go.dev/blog
It is bound to the `test` stage, and uses the following variables: It is bound to the `test` stage, and uses the following variables:
| Name | Description | Default value | | Input / Variable | Description | Default value |
| --------------------- | -------------------------------------- | ----------------- | | --------------------- | -------------------------------------- | ----------------- |
| `GO_VULNCHECK_DISABLED` | Set to `true` to disable this job | _none_ | `vulncheck-disabled` / `GO_VULNCHECK_DISABLED` | Set to `true` to disable this job | _none_
| `GO_VULNCHECK_ARGS` | `govulncheck` [command line arguments](https://pkg.go.dev/golang.org/x/vuln/cmd/govulncheck#hdr-Flags) | `./...` | | `vulncheck-args` / `GO_VULNCHECK_ARGS` | `govulncheck` [command line arguments](https://pkg.go.dev/golang.org/x/vuln/cmd/govulncheck#hdr-Flags) | `./...` |
\ No newline at end of file \ No newline at end of file
...@@ -27,13 +27,13 @@ if [[ "$curVer" ]]; then ...@@ -27,13 +27,13 @@ if [[ "$curVer" ]]; then
log_info "Bump version from \\e[33;1m${curVer}\\e[0m to \\e[33;1m${nextVer}\\e[0m (release type: $relType)..." log_info "Bump version from \\e[33;1m${curVer}\\e[0m to \\e[33;1m${nextVer}\\e[0m (release type: $relType)..."
# replace in README # replace in README
sed -e "s/ref: '$curVer'/ref: '$nextVer'/" README.md > README.md.next sed -e "s/ref: *'$curVer'/ref: '$nextVer'/" -e "s/ref: *\"$curVer\”/ref: \”$nextVer\”/" -e "s/component: *\(.*\)@$curVer/component: \1@$nextVer/" README.md > README.md.next
mv -f README.md.next README.md mv -f README.md.next README.md
# replace in template and variants # replace in template and variants
for tmpl in templates/*.yml for tmpl in templates/*.yml
do do
sed -e "s/\"$curVer\"/\"$nextVer\"/" "$tmpl" > "$tmpl.next" sed -e "s/command: *\[\"--service\", \"\(.*\)\", \"$curVer\"\]/command: [\"--service\", \"\1\", \"$nextVer\"]/" "$tmpl" > "$tmpl.next"
mv -f "$tmpl.next" "$tmpl" mv -f "$tmpl.next" "$tmpl"
done done
else else
......
...@@ -3,11 +3,13 @@ ...@@ -3,11 +3,13 @@
"description": "Build, test and analyse your [Go](https://golang.org/) projects", "description": "Build, test and analyse your [Go](https://golang.org/) projects",
"template_path": "templates/gitlab-ci-golang.yml", "template_path": "templates/gitlab-ci-golang.yml",
"kind": "build", "kind": "build",
"prefix": "go",
"is_component": true,
"variables": [ "variables": [
{ {
"name": "GO_IMAGE", "name": "GO_IMAGE",
"description": "The Docker image used to run Go (build+test or build only) - **set the version required by your project**", "description": "The Docker image used to run Go (build+test or build only) - **set the version required by your project**",
"default": "registry.hub.docker.com/library/golang:buster" "default": "registry.hub.docker.com/library/golang:bookworm"
}, },
{ {
"name": "GO_PROJECT_DIR", "name": "GO_PROJECT_DIR",
......
logo.png

15.5 KiB | W: | H:

logo.png

10.5 KiB | W: | H:

logo.png
logo.png
logo.png
logo.png
  • 2-up
  • Swipe
  • Onion skin
...@@ -14,6 +14,90 @@ ...@@ -14,6 +14,90 @@
# Floor, Boston, MA 02110-1301, USA. # Floor, Boston, MA 02110-1301, USA.
# ========================================================================================= # =========================================================================================
# default workflow rules: Merge Request pipelines # default workflow rules: Merge Request pipelines
spec:
inputs:
image:
description: The Docker image used to run Go (build+test or build only) - **set the version required by your project**
default: registry.hub.docker.com/library/golang:bookworm
project-dir:
description: Go project root directory
default: .
goproxy:
description: URL of Go module proxy (see [Go env](https://golang.org/cmd/go/#hdr-Environment_variables))
default: ''
test-image:
description: Specific Docker image used to run Go tests (as a separate job)
default: ''
build-flags:
description: Flags used by the [go build command](https://pkg.go.dev/cmd/go#hdr-Compile_packages_and_dependencies)
default: -mod=readonly
build-mode:
description: The template build mode (accepted values are `application`, `modules` and `auto`)
options:
- auto
- application
- modules
default: auto
build-linker-flags:
description: Linker flags used by the [go build command](https://pkg.go.dev/cmd/go#hdr-Compile_packages_and_dependencies) `-ldflags`
default: -s -w
build-packages:
description: Packages to build with the [go build command](https://pkg.go.dev/cmd/go#hdr-Compile_packages_and_dependencies)
default: ./...
target-os:
description: |-
The `$GOOS` target [see available values](https://gist.github.com/asukakenji/f15ba7e588ac42795f421b48b8aede63)
Fallbacks to default `$GOOS` from the Go Docker image
default: ''
target-arch:
description: |-
The `$GOARCH` target [see available values](https://gist.github.com/asukakenji/f15ba7e588ac42795f421b48b8aede63)
Fallbacks to default `$GOARCH` from the Go Docker image
default: ''
test-flags:
description: Flags used by the [go test command](https://pkg.go.dev/cmd/go#hdr-Test_packages)
default: -mod=readonly -v -race
test-packages:
description: Packages to test with the [go test command](https://pkg.go.dev/cmd/go#hdr-Test_packages)
default: ./...
list-args:
description: Arguments used by the list command
default: list -u -m -mod=readonly -json all
cobertura-flags:
description: Build flags to add to use gocover-cobertura, leave blank if not needed
default: ''
ci-lint-disabled:
description: Disable GolangCI-Lint
type: boolean
default: false
ci-lint-image:
description: The Docker image used to run `golangci-lint`
default: registry.hub.docker.com/golangci/golangci-lint:latest-alpine
ci-lint-args:
description: '`golangci-lint` [command line arguments](https://github.com/golangci/golangci-lint#command-line-options)'
default: -E gosec,goimports ./...
mod-outdated-args:
description: '`god-mod-outdated` [command line arguments](https://github.com/psampaz/go-mod-outdated#usage'
default: -update -direct
sbom-disabled:
description: Disable Software Bill of Materials
type: boolean
default: false
sbom-image:
default: registry.hub.docker.com/cyclonedx/cyclonedx-gomod:latest
sbom-opts:
description: '[@cyclonedx/cyclonedx-gomod options](https://github.com/CycloneDX/cyclonedx-gomod#usage) used for SBOM analysis'
default: -main .
vulncheck-disabled:
description: Disable Govulncheck
type: boolean
default: false
vulncheck-args:
description: '`govulncheck` [command line arguments](https://pkg.go.dev/golang.org/x/vuln/cmd/govulncheck#hdr-Flags)'
default: ./...
---
workflow: workflow:
rules: rules:
# prevent branch pipeline when an MR is open (prefer MR pipeline) # prevent branch pipeline when an MR is open (prefer MR pipeline)
...@@ -56,67 +140,66 @@ workflow: ...@@ -56,67 +140,66 @@ workflow:
variables: variables:
# variabilized tracking image # variabilized tracking image
TBC_TRACKING_IMAGE: "registry.gitlab.com/to-be-continuous/tools/tracking:master" TBC_TRACKING_IMAGE: registry.gitlab.com/to-be-continuous/tools/tracking:master
# Default Go project root directory # Default Go project root directory
GO_PROJECT_DIR: . GO_PROJECT_DIR: $[[ inputs.project-dir ]]
# Default Docker image (can be overridden) # Default Docker image (can be overridden)
GO_IMAGE: "registry.hub.docker.com/library/golang:bookworm" GO_IMAGE: $[[ inputs.image ]]
# Default flags for 'build' command # Default flags for 'build' command
GO_BUILD_FLAGS: >- GO_BUILD_FLAGS: $[[ inputs.build-flags ]]
-mod=readonly
# Default flags for go build linker # Default flags for go build linker
GO_BUILD_LINKER_FLAGS: "-s -w" GO_BUILD_LINKER_FLAGS: $[[ inputs.build-linker-flags ]]
# Default packages for 'build' command # Default packages for 'build' command
GO_BUILD_PACKAGES: >- GO_BUILD_PACKAGES: $[[ inputs.build-packages ]]
./... ./...
# Default build mode (application/modules/auto) # Default build mode (application/modules/auto)
GO_BUILD_MODE: auto GO_BUILD_MODE: $[[ inputs.build-mode ]]
# Default flags for 'test' command # Default flags for 'test' command
GO_TEST_FLAGS: >- GO_TEST_FLAGS: $[[ inputs.test-flags ]]
-mod=readonly
-v
-race
# Default packages for 'test' command # Default packages for 'test' command
GO_TEST_PACKAGES: >- GO_TEST_PACKAGES: $[[ inputs.test-packages ]]
./...
# Default arguments for 'list' command # Default arguments for 'list' command
GO_LIST_ARGS : >- GO_LIST_ARGS: $[[ inputs.list-args ]]
list
-u
-m
-mod=readonly
-json all
# Default arguments for go-mod-outdated command # Default arguments for go-mod-outdated command
GO_MOD_OUTDATED_ARGS: '-update -direct' GO_MOD_OUTDATED_ARGS: $[[ inputs.mod-outdated-args ]]
GO_VULNCHECK_ARGS: >- GO_VULNCHECK_ARGS: $[[ inputs.vulncheck-args ]]
./... ./...
# Default golangci-lint Docker image (can be overridden) # Default golangci-lint Docker image (can be overridden)
GO_CI_LINT_IMAGE: "registry.hub.docker.com/golangci/golangci-lint:latest-alpine" GO_CI_LINT_IMAGE: $[[ inputs.ci-lint-image ]]
# Default arguments for golangci-lint command # Default arguments for golangci-lint command
GO_CI_LINT_ARGS: '-E gosec,goimports ./...' GO_CI_LINT_ARGS: $[[ inputs.ci-lint-args ]]
GOPROXY: $[[ inputs.goproxy ]]
GO_TEST_IMAGE: $[[ inputs.test-image ]]
GO_TARGET_OS: $[[ inputs.target-os ]]
GO_TARGET_ARCH: $[[ inputs.target-arch ]]
GO_COBERTURA_FLAGS: $[[ inputs.cobertura-flags ]]
GO_CI_LINT_DISABLED: $[[ inputs.ci-lint-disabled ]]
GO_SBOM_DISABLED: $[[ inputs.sbom-disabled ]]
GO_VULNCHECK_DISABLED: $[[ inputs.vulncheck-disabled ]]
# Image of cyclonedx-gomod used for SBOM analysis # Image of cyclonedx-gomod used for SBOM analysis
GO_SBOM_IMAGE: "registry.hub.docker.com/cyclonedx/cyclonedx-gomod:latest" GO_SBOM_IMAGE: $[[ inputs.sbom-image ]]
# Options for cyclonedx-gomod used for SBOM analysis # Options for cyclonedx-gomod used for SBOM analysis
GO_SBOM_OPTS: "-main ." GO_SBOM_OPTS: $[[ inputs.sbom-opts ]]
# default production ref name (pattern) # default production ref name (pattern)
PROD_REF: '/^(master|main)$/' PROD_REF: /^(master|main)$/
# default integration ref name (pattern) # default integration ref name (pattern)
INTEG_REF: '/^develop$/' INTEG_REF: /^develop$/
stages: stages:
- build - build
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment