Skip to content

Commit

Permalink
move to use GH actions (#207)
Browse files Browse the repository at this point in the history
  • Loading branch information
helayoty committed Jun 29, 2022
1 parent 37b64f2 commit d2aa17e
Show file tree
Hide file tree
Showing 6 changed files with 221 additions and 45 deletions.
42 changes: 0 additions & 42 deletions .circleci/config.yml

This file was deleted.

70 changes: 70 additions & 0 deletions .github/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: Lint

on:
push:
branches:
- main
- release-*
workflow_dispatch: {}
pull_request:
branches:
- main
- release-*
paths-ignore: [docs/**, "**.md", "**.mdx", "**.png", "**.jpg"]

env:
# Common versions
GO_VERSION: '1.17'

jobs:

detect-noop:
runs-on: ubuntu-latest
outputs:
noop: ${{ steps.noop.outputs.should_skip }}
steps:
- name: Detect No-op Changes
id: noop
uses: fkirc/skip-duplicate-actions@v4.0.0
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
do_not_skip: '["workflow_dispatch", "schedule", "push"]'
concurrent_skipping: false

staticcheck:
runs-on: ubuntu-latest
needs: detect-noop
if: needs.detect-noop.outputs.noop != 'true'

steps:
- name: Setup Go
uses: actions/setup-go@v3
with:
go-version: ${{ env.GO_VERSION }}

- name: Checkout
uses: actions/checkout@v3
with:
submodules: true

- name: StaticCheck
run: GO111MODULE=auto make staticcheck

lint:
name: "Lint"
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: read

steps:
- name: Set up Go ${{ env.GO_VERSION }}
uses: actions/setup-go@v3
with:
go-version: ${{ env.GO_VERSION }}

- name: Check out code into the Go module directory
uses: actions/checkout@v3

- name: golangci-lint
run: make lint
55 changes: 55 additions & 0 deletions .github/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: azure-aci-test

on:
push:
branches:
- main
- release-*
workflow_dispatch: {}
pull_request:
branches:
- main
- release-*
paths-ignore: [docs/**, "**.md", "**.mdx", "**.png", "**.jpg"]


jobs:
detect-noop:
runs-on: ubuntu-latest
outputs:
noop: ${{ steps.noop.outputs.should_skip }}
steps:
- name: Detect No-op Changes
id: noop
uses: fkirc/skip-duplicate-actions@v4.0.0
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
do_not_skip: '["workflow_dispatch", "schedule", "push"]'
concurrent_skipping: false

unit-tests:
runs-on: ubuntu-latest
needs: detect-noop
if: needs.detect-noop.outputs.noop != 'true'
steps:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: ${{ env.GO_VERSION }}

- name: Check out code into the Go module directory
uses: actions/checkout@v3

- name: Run go vet
uses: make vet

- name: Run unit tests & Generate coverage
run: make testauth test

- name: Upload Codecov report
uses: codecov/codecov-action@v3
with:
## Repository upload token - get it from codecov.io. Required only for private repositories
token: ${{ secrets.CODECOV_TOKEN }}
## Comma-separated list of files to upload
files: ./coverage.xml
31 changes: 31 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
run:
deadline: 10m

linters:
disable-all: true
enable:
- deadcode
- errcheck
- errorlint
- goconst
- gocyclo
- gofmt
- goimports
- gosec
- gosimple
- govet
- ineffassign
- misspell
- nakedret
- nilerr
- prealloc
- revive
- staticcheck
- structcheck
- typecheck
- unconvert
- unused
- varcheck
- whitespace
# Run with --fast=false for more extensive checks
fast: true
24 changes: 21 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
LINTER_BIN ?= golangci-lint
GOLANGCI_LINT_VER := v1.41.1
GOLANGCI_LINT_BIN := golangci-lint
GOLANGCI_LINT := $(abspath $(TOOLS_BIN_DIR)/$(GOLANGCI_LINT_BIN)-$(GOLANGCI_LINT_VER))

GO111MODULE := on
export GO111MODULE
Expand All @@ -14,6 +16,14 @@ BUILDPLATFORM ?= linux/amd64
VERSION := $(shell git describe --tags --always --dirty="-dev")
IMG_TAG ?= $(VERSION)


## --------------------------------------
## Tooling Binaries
## --------------------------------------

$(GOLANGCI_LINT):
GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) github.com/golangci/golangci-lint/cmd/golangci-lint $(GOLANGCI_LINT_BIN) $(GOLANGCI_LINT_VER)

.PHONY: safebuild
# docker build
safebuild:
Expand Down Expand Up @@ -45,9 +55,17 @@ test:
vet:
@go vet ./... #$(packages)

## --------------------------------------
## Linting
## --------------------------------------

.PHONY: lint
lint:
@$(LINTER_BIN) run --skip-files "test.go" --new-from-rev "HEAD~$(git rev-list master.. --count)" ./... --timeout 5m0s
lint: $(GOLANGCI_LINT)
$(GOLANGCI_LINT) run -v

.PHONY: lint-full
lint-full: $(GOLANGCI_LINT) ## Run slower linters to detect possible issues
$(GOLANGCI_LINT) run -v --fast=false

.PHONY: check-mod
check-mod: # verifies that module changes for go.mod and go.sum are checked in
Expand Down
44 changes: 44 additions & 0 deletions hack/go-install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env bash
# https://github.com/kubernetes-sigs/cluster-api-provider-azure/blob/master/scripts/go_install.sh

set -o errexit
set -o nounset
set -o pipefail

if [[ -z "${1}" ]]; then
echo "must provide module as first parameter"
exit 1
fi

if [[ -z "${2}" ]]; then
echo "must provide binary name as second parameter"
exit 1
fi

if [[ -z "${3}" ]]; then
echo "must provide version as third parameter"
exit 1
fi

if [[ -z "${GOBIN}" ]]; then
echo "GOBIN is not set. Must set GOBIN to install the bin in a specified directory."
exit 1
fi

tmp_dir=$(mktemp -d -t goinstall_XXXXXXXXXX)
function clean {
rm -rf "${tmp_dir}"
}
trap clean EXIT

rm "${GOBIN}/${2}"* || true

cd "${tmp_dir}"

# create a new module in the tmp directory
go mod init fake/mod

# install the golang module specified as the first argument
go install "${1}@${3}"
mv "${GOBIN}/${2}" "${GOBIN}/${2}-${3}"
ln -sf "${GOBIN}/${2}-${3}" "${GOBIN}/${2}"

0 comments on commit d2aa17e

Please sign in to comment.