Skip to content

Commit

Permalink
Add env
Browse files Browse the repository at this point in the history
Signed-off-by: mehabhalodiya <[email protected]>
  • Loading branch information
mehabhalodiya committed Jan 23, 2024
1 parent 4ec2bde commit 00ce705
Show file tree
Hide file tree
Showing 6 changed files with 183 additions and 107 deletions.
44 changes: 9 additions & 35 deletions .codecov.yml
Original file line number Diff line number Diff line change
@@ -1,36 +1,10 @@
# See http://docs.codecov.io/docs/coverage-configuration
coverage:
precision: 2 # 2 = xx.xx%, 0 = xx%
round: down
# For example: 20...60 would result in any coverage less than 20%
# would have a red background. The color would gradually change to
# green approaching 60%. Any coverage over 60% would result in a
# solid green color.
range: "20...60"

status:
# project will give us the diff in the total code coverage between a commit
# and its parent
project: yes
# Patch gives just the coverage of the patch
patch: yes
# changes tells us if there are unexpected code co verage changes in other files
# which were not changed by the diff
changes: yes

# See http://docs.codecov.io/docs/ignoring-paths
ignore:
- "build/*"
- "hack/*"
- "openshift-ci/*"
- "Makefile"
- ".travis.yml"

# See http://docs.codecov.io/docs/pull-request-comments-1
comment:
layout: "diff, files"
behavior: ""
# default = posts once then update, posts new if delete
# once = post once then updates
# new = delete old, post new
# spammy = post new
status:
# Allows coverage to drop by a 3% when compared against the base commit.
project:
default:
target: auto
threshold: 3%
patch:
default:
informational: true
21 changes: 21 additions & 0 deletions .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Code Coverage Report
on:
push:
branches:
- main
jobs:
build-and-deploy:
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v3
with:
persist-credentials: false
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: 1.19
- name: Run tests
run: make test
- name: Codecov
uses: codecov/codecov-action@v2
27 changes: 27 additions & 0 deletions .github/workflows/gosec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
name: Go Test on Pull Requests
on: # yamllint disable-line rule:truthy
pull_request:
types:
- opened
- synchronize
- reopened
paths:
- '**.go'
workflow_dispatch:
jobs:
gosec:
name: Check GO security
runs-on: ubuntu-20.04
steps:
- name: Check out code
uses: actions/checkout@v3
with:
fetch-depth: 1
ref: ${{ github.event.pull_request.head.sha }}
- name: Run Gosec Security Scanner
uses: securego/gosec@master
with:
args: -exclude-generated ./...
env:
GOROOT: ""
72 changes: 0 additions & 72 deletions .github/workflows/pr-checks.yml

This file was deleted.

117 changes: 117 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
name: Go Test on Pull Requests
on:
pull_request:
types:
- opened
- synchronize
- reopened
jobs:
go:
name: Check sources
runs-on: ubuntu-20.04
env:
OPERATOR_SDK_VERSION: v1.18.0
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: 1.19
- name: Check out code into the Go module directory
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Cache Operator SDK ${{ env.OPERATOR_SDK_VERSION }}
uses: actions/cache@v3
id: cache-operator-sdk
with:
path: ~/cache
key: operator-sdk-${{ env.OPERATOR_SDK_VERSION }}
- name: Download Operator SDK ${{ env.OPERATOR_SDK_VERSION }}
if: steps.cache-operator-sdk.outputs.cache-hit != 'true'
run: |
mkdir -p ~/cache
wget https://github.com/operator-framework/operator-sdk/releases/download/${OPERATOR_SDK_VERSION}/operator-sdk_linux_amd64 -O ~/cache/operator-sdk-${OPERATOR_SDK_VERSION} > /dev/null -O ~/cache/operator-sdk-${OPERATOR_SDK_VERSION} > /dev/null
chmod +x ~/cache/operator-sdk-${OPERATOR_SDK_VERSION}
- name: Install Operator SDK ${{ env.OPERATOR_SDK_VERSION }}
run: |
mkdir -p ~/bin
cp ~/cache/operator-sdk-${OPERATOR_SDK_VERSION} ~/bin/operator-sdk
echo "$HOME/bin" >> $GITHUB_PATH
- name: Regenerate executables with current environment packages
run: |
rm -f bin/kustomize bin/controller-gen
make kustomize controller-gen
- name: Cache go modules
id: cache-mod
uses: actions/cache@v3
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Download dependencies
run: go mod download
if: steps.cache-mod.outputs.cache-hit != 'true'
- name: Check go mod status
run: |
go mod tidy
if [[ ! -z $(git status ':(exclude)bin/kustomize' ':(exclude)bin/controller-gen' -s) ]]
then
echo "Go mod state is not clean:"
git --no-pager diff ':(exclude)bin/kustomize' ':(exclude)bin/controller-gen'
exit 1
fi
- name: Check format
run: |
make fmt
if [[ ! -z $(git status ':(exclude)bin/kustomize' ':(exclude)bin/controller-gen' -s) ]]
then
echo "Some files are not properly formatted."
echo "Please run `go fmt` and amend your commit."
git --no-pager diff ':(exclude)bin/kustomize' ':(exclude)bin/controller-gen'
exit 1
fi
- uses: dominikh/[email protected]
with:
version: "2023.1.3"
install-go: false
- name: Check manifests
run: |
make generate manifests
if [[ ! -z $(git status ':(exclude)bin/kustomize' ':(exclude)bin/controller-gen' -s) ]]
then
echo "generated sources are not up to date:"
git --no-pager diff ':(exclude)bin/kustomize' ':(exclude)bin/controller-gen'
exit 1
fi
- name: Run Go Tests
run: make test
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
- name: Ensure make build succeeds
run: make build
- name: Ensure make bundle succeeds
run: make bundle
docker:
name: Check docker build
runs-on: ubuntu-20.04
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Check if dockerimage build is working
run: docker build -f ./Dockerfile .
gitlint:
name: Run gitlint checks
runs-on: ubuntu-20.04
steps:
- name: Check out code
uses: actions/checkout@v2
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}
- name: Install gitlint into container
run: python -m pip install gitlint
- name: Run gitlint check
run: gitlint --commits origin/${{ github.event.pull_request.base.ref }}..HEAD
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ all: build
help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)

lint:
golangci-lint run

##@ Development

manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
Expand All @@ -90,6 +93,12 @@ fmt: ## Run go fmt against code.
vet: ## Run go vet against code.
go vet ./...

##@ Test

.PHONY: test
test: manifests generate fmt vet envtest ## Run tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./... -coverprofile cover.out

test-all: manifests generate fmt vet ## Run all tests.
go test -timeout 1h ./... -coverprofile cover.out

Expand Down

0 comments on commit 00ce705

Please sign in to comment.