Skip to content

Merge pull request #17 from amoniacou/release/v1.2.7 #86

Merge pull request #17 from amoniacou/release/v1.2.7

Merge pull request #17 from amoniacou/release/v1.2.7 #86

Workflow file for this run

name: Go
on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'
branches:
- main
pull_request:
repository_dispatch:
# set up environment variables to be used across all the jobs
env:
GOLANG_VERSION: "1.23.x"
GOLANGCI_LINT_VERSION: "v1.61"
KUBEBUILDER_VERSION: "4.2.0"
SONAR_SCANNER_VERSION: "4.8.0.2856"
permissions:
contents: read
pull-requests: read
defaults:
run:
# default failure handling for shell scripts in 'run' steps
shell: 'bash -Eeuo pipefail -x {0}'
jobs:
change-triage:
name: Check changed files
runs-on: ubuntu-latest
outputs:
docs-changed: ${{ steps.filter.outputs.docs-changed }}
operator-changed: ${{ steps.filter.outputs.operator-changed }}
test-changed: ${{ steps.filter.outputs.test-changed }}
shell-script-changed: ${{ steps.filter.outputs.shell-script-changed }}
go-code-changed: ${{ steps.filter.outputs.go-code-changed }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Check for changes
uses: dorny/paths-filter@v3
id: filter
# Remember to add new folders in the operator-changed filter if needed
with:
base: main
filters: |
operator-changed:
- 'api/**'
- 'cmd/**'
- 'config/**'
- 'internal/**'
- '.github/workflows/golang.yaml'
- 'Dockerfile'
- 'Makefile'
- 'go.mod'
- 'go.sum'
test-changed:
- 'hack/**'
shell-script-changed:
- '**/*.sh'
go-code-changed:
- '**/*.go'
- '.golangci.yml'
go-linters:
name: Run linters
needs:
- change-triage
# Run Go linter only if Go code has changed
if: needs.change-triage.outputs.go-code-changed == 'true'
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GOLANG_VERSION }}
# Check if there's any dirty change for go mod tidy
- name: Check go mod
run: |
make go-mod-check
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: ${{ env.GOLANGCI_LINT_VERSION }}
args: --timeout 4m
only-new-issues: true
generate-unit-tests-jobs:
name: Generate jobs for unit tests
needs:
- change-triage
# Generate unit tests jobs only if the operator or the Go codebase have changed
if: |
(
needs.change-triage.outputs.operator-changed == 'true' ||
needs.change-triage.outputs.go-code-changed == 'true'
)
runs-on: ubuntu-latest
outputs:
k8sMatrix: ${{ steps.get-k8s-versions.outputs.k8s_versions }}
latest_k8s_version: ${{ steps.get-k8s-versions.outputs.latest_k8s_version }}
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Get k8s versions for unit test
id: get-k8s-versions
shell: bash
run: |
k8s_versions=$(jq -c '
.unit_test.max as $max |
.unit_test.min as $min |
$min | [ while(. <= $max;
. | split(".") | .[1] |= (.|tonumber|.+1|tostring) | join(".")
)
] |
.[] |= .+".x"
' < .github/k8s_versions_scope.json)
echo "k8s_versions=${k8s_versions}" >> $GITHUB_OUTPUT
latest_k8s_version=$(jq -r '.|last' <<< $k8s_versions)
echo "latest_k8s_version=${latest_k8s_version}" >> $GITHUB_OUTPUT
tests:
name: Run unit tests
needs:
- change-triage
- generate-unit-tests-jobs
# Run unit tests only if the operator or the Go codebase have changed
if: |
(
needs.change-triage.outputs.operator-changed == 'true' ||
needs.change-triage.outputs.go-code-changed == 'true'
)
runs-on: ubuntu-latest
strategy:
matrix:
# The Unit test is performed per multiple supported k8s versions (each job for each k8s version) as below:
k8s-version: ${{ fromJSON(needs.generate-unit-tests-jobs.outputs.k8sMatrix) }}
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GOLANG_VERSION }}
- name: Run unit tests
env:
ENVTEST_K8S_VERSION: ${{ matrix.k8s-version }}
run: |
make test
- uses: actions/upload-artifact@v3
with:
name: cover
path: cover.out
crd:
name: Verify CRD is up to date
needs:
- change-triage
# Run make manifests if Go code have changed
if: needs.change-triage.outputs.go-code-changed == 'true'
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install Go
uses: actions/setup-go@v3
with:
go-version: ${{ env.GOLANG_VERSION }}
- name: Run make manifests
run: |
make manifests
- name: Check CRD manifests are up to date
run: |
crd_path='config/crd'
if git status --porcelain $crd_path | grep '^ M'; then
echo "The CRD manifests do not reflect the current API. Please run make manifests."
exit 1
fi