Skip to content

Commit

Permalink
Add github ci (#8)
Browse files Browse the repository at this point in the history
Signed-off-by: Arnob kumar saha <arnob@appscode.com>
  • Loading branch information
ArnobKumarSaha committed Feb 4, 2024
1 parent 5c0680b commit 7743f4f
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 1 deletion.
41 changes: 41 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

name: CI

on:
pull_request:
branches:
- "*"
push:
branches:
- master
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
cancel-in-progress: true


jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.21'

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Build
run: go build -v ./...

- name: Run checks
run: |
make ci
# - name: Test
# run: go test -v ./...
56 changes: 55 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,20 @@ BUILD_IMAGE ?= ghcr.io/appscode/golang-dev:$(GO_VERSION)
SRC_PKGS := pkg cmd handlers
SRC_DIRS := $(SRC_PKGS)

.PHONY: ci
ci: verify check-license # lint build

.PHONY: verify
verify: verify-gen verify-modules

.PHONY: verify-gen
verify-gen: gen fmt
@if !(git diff --exit-code HEAD); then \
echo "files are out of date, run make gen fmt"; exit 1; \
fi

gen:
@true

fmt: $(BUILD_DIRS)
@docker run \
Expand All @@ -43,10 +56,36 @@ fmt: $(BUILD_DIRS)
./hack/fmt.sh $(SRC_DIRS) \
"

ADDTL_LINTERS := gofmt,goimports,unparam

.PHONY: lint
lint: $(BUILD_DIRS)
@echo "running linter"
@docker run \
-i \
--rm \
-u $$(id -u):$$(id -g) \
-v $$(pwd):/src \
-w /src \
-v $$(pwd)/.go/bin/$(OS)_$(ARCH):/go/bin \
-v $$(pwd)/.go/bin/$(OS)_$(ARCH):/go/bin/$(OS)_$(ARCH) \
-v $$(pwd)/.go/cache:/.cache \
--env GO111MODULE=on \
--env GOFLAGS="-mod=vendor" \
$(BUILD_IMAGE) \
golangci-lint run --enable $(ADDTL_LINTERS) --timeout=10m --skip-files="generated.*\.go$\" --skip-dirs-use-default --skip-dirs=client,vendor

.PHONY: verify-modules
verify-modules:
GO111MODULE=on go mod tidy
GO111MODULE=on go mod vendor
@if !(git diff --exit-code HEAD); then \
echo "go module files are out of date"; exit 1; \
fi

DOCKER_REPO_ROOT := /go/src/$(GO_PKG)/$(REPO)

.PHONY: add-license
add-license:
@echo "Adding license header"
@docker run --rm \
Expand All @@ -55,4 +94,19 @@ add-license:
-v $$(pwd):$(DOCKER_REPO_ROOT) \
-w $(DOCKER_REPO_ROOT) \
$(BUILD_IMAGE) \
ltag -t "./hack/license" --excludes "vendor contrib third_party libbuild" -v
ltag -t "./hack/license" --excludes "vendor contrib third_party libbuild" -v

.PHONY: check-license
check-license:
@echo "Checking files for license header"
@docker run --rm \
-u $$(id -u):$$(id -g) \
-v /tmp:/.cache \
-v $$(pwd):$(DOCKER_REPO_ROOT) \
-w $(DOCKER_REPO_ROOT) \
$(BUILD_IMAGE) \
ltag -t "./hack/license" --excludes "vendor contrib third_party libbuild" --check -v

.PHONY: clean
clean:
rm -rf .go bin

0 comments on commit 7743f4f

Please sign in to comment.