Skip to content

fix: generate dynamic k8s client only once (#752) #535

fix: generate dynamic k8s client only once (#752)

fix: generate dynamic k8s client only once (#752) #535

Workflow file for this run

name: CI
on:
pull_request:
branches:
- master
push:
branches:
- master
env:
GOLANG_VERSION: 1.21
APPLICATION_NAME: redis-operator
DockerImagName: docker.io/opstree/redis-operator
BuildDocs: true
AppVersion: "v0.15.2"
DOCKERFILE_PATH: "**/Dockerfile"
jobs:
gofmt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: ${{ env.GOLANG_VERSION }}
- name: Check Go Fmt
run: |
gofmt_files=$(go fmt ./... | wc -l)
if [[ ${gofmt_files} > 0 ]]
then
echo "Please format golang files using:- go fmt ./..."
exit 1
else
echo "All files are formated using gofmt"
fi
govet:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: ${{ env.GOLANG_VERSION }}
- name: Run Go Vet
run: go vet ./...
gotest:
name: Go Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: ${{ env.GOLANG_VERSION }}
- name: Install integration test dependencies
run: make integration-test-setup
- name: Run Go Tests with coverage
run: go test ./... -coverprofile=coverage.txt -covermode=atomic
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
file: ./coverage.txt
fail_ci_if_error: false
verbose: true
code_quality_golang_ci_lint:
needs: [gofmt, govet]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: ${{ env.GOLANG_VERSION }}
- name: Download Go modules
run: go mod download
- name: Check disk space
run: df -h
- name: List Go module cache
run: ls -la $(go env GOPATH)/pkg/mod
- name: Run GolangCI-Lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.54.0
container_quality_dockerfile_lint:
needs: [gofmt, govet]
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Execute dockerlinter
uses: hadolint/[email protected]
with:
dockerfile: Dockerfile
ignore: DL3007,DL3018
build_go_binary:
needs: [code_quality_golang_ci_lint]
runs-on: ubuntu-latest
strategy:
matrix:
arch: ["amd64", "arm64"]
steps:
- name: Checkout Code
uses: actions/checkout@v2
- name: Setup Go Environment
uses: actions/setup-go@v4
with:
go-version: ${{ env.GOLANG_VERSION }}
- name: Set GOARCH
run: echo "GOARCH=${{ matrix.arch }}" >> $GITHUB_ENV
- name: Build Go Binary
run: go build -o ${{ github.workspace }}/${{ env.APPLICATION_NAME }}
- name: Archive Binary
run: |
mkdir -p ${{ github.workspace }}/compiled/${{ matrix.arch }}
zip ${{ github.workspace }}/compiled/${{ matrix.arch }}/${{ env.APPLICATION_NAME }}-${{ matrix.arch }}.zip ${{ github.workspace }}/${{ env.APPLICATION_NAME }}
build_scan_container_image:
needs: [container_quality_dockerfile_lint]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build multi-arch image
uses: docker/build-push-action@v2
with:
context: .
platforms: linux/arm64,linux/amd64
push: false
tags: ${{ env.DockerImagName }}:latest
gosec_scan:
needs: [build_go_binary]
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v2
- name: Gosec Scan
uses: securego/gosec@master
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GOSEC_OUTPUT: "junit-xml:/github/workspace/gosec-results.xml"