Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: add job dependencies and logic gates #9 #28

Merged
merged 6 commits into from
Jul 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 29 additions & 40 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
name: Build, Test and Release
name: Lint, Build, Test and Release

on:
push:
branches:
- main
pull_request:
branches: [main]
workflow_call:

jobs:
golangci:
lint:
strategy:
matrix:
go: ['1.19']
os: [ubuntu-latest, macos-latest, windows-latest]
os: [ubuntu-latest, macos-latest]
name: lint
runs-on: ${{ matrix.os }}
steps:
Expand All @@ -19,33 +19,21 @@ jobs:
with:
go-version: ${{ matrix.go }}
cache: false
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
# Require: The version of golangci-lint to use.
# When `install-mode` is `binary` (default) the value can be v1.2 or v1.2.3 or `latest` to use the latest version.
# When `install-mode` is `goinstall` the value can be v1.2.3, `latest`, or the hash of a commit.
version: v1.53

# Optional: working directory, useful for monorepos
# working-directory: somedir

# Optional: golangci-lint command line arguments.
#
# Note: by default the `.golangci.yml` file should be at the root of the repository.
# The location of the configuration file can be changed by using `--config=`
# args: --timeout=30m --config=/my/path/.golangci.yml --issues-exit-code=0

# Optional: show only new issues if it's a pull request. The default value is `false`.
# only-new-issues: true

# Optional:The mode to install golangci-lint. It can be 'binary' or 'goinstall'.
# install-mode: "goinstall"

make-build-checks:
runs-on: ubuntu-latest
steps:

- name: Make install-tools
run: make install-tools

- name: Make lint-all
run: make lint-all

build:
strategy:
matrix:
go: ['1.19']
os: [ubuntu-latest, macos-latest]
name: build
runs-on: ${{ matrix.os }}
steps:
- name: Check out code
uses: actions/checkout@v3
with:
Expand All @@ -57,13 +45,12 @@ jobs:
go-version: '1.19'
cache: false

- name: Build OpenTelemetry Collector
- name: Make cibuild
run: make cibuild

- name: Run Checks
run: make checks

go-semnatic-release:
go-semantic-release:
if: ${{ github.ref == 'refs/heads/main' }}
needs: [lint, build]
runs-on: ubuntu-latest
permissions:
contents: write
Expand All @@ -74,6 +61,8 @@ jobs:
github_token: ${{ secrets.GITHUB_TOKEN }}

goreleaser:
if: ${{ github.ref == 'refs/heads/main' }}
needs: [go-semantic-release]
runs-on: ubuntu-latest
permissions:
contents: write
Expand All @@ -82,15 +71,15 @@ jobs:
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Fetch all tags
run: git fetch --force --tags

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

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v4
with:
Expand Down
48 changes: 48 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
run:
timeout: 10m
allow-parallel-runners: true

linters-settings:
errcheck:
check-type-assertions: false
check-blank: true

gosimple:
go: "1.19"

maligned:
# print struct with more effective memory layout or not, false by default
suggest-new: true

unused:
go: "1.19"

lll:
# max line length, lines longer will be reported. Default is 120.
# '\t' is counted as 1 character by default, and can be changed with the tab-width option
line-length: 185
# tab width in spaces. Default to 1.
tab-width: 8

linters:
disable-all: true
enable:
- gofmt
- errcheck
- goimports
- misspell
- noctx
- lll
- govet
- ineffassign
- typecheck
- unused
- gosimple
- staticcheck
- gosec

issues:
# Maximum issues count per one linter. Set to 0 to disable. Default is 50.
max-issues-per-linter: 0
# Maximum count of issues with the same text. Set to 0 to disable. Default is 3.
max-same-issues: 0
12 changes: 8 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ OTEL_CONTRIB_REPO = https://github.com/open-telemetry/opentelemetry-collector-co
OS := $(shell uname | tr '[:upper:]' '[:lower:]')
ARCH := $(shell uname -m)
GORELEASER_VERSION = 1.19.2
GOLANGCI_LINT_VERSION ?= v1.53.2

# Arguments for getting directories & executing commands against them
PKG_RECEIVER_DIRS = $(shell find ./pkg/receiver/* -type f -name "go.mod" -print -exec dirname {} \; | sort | uniq)
# PKG_RECEIVER_DIRS = $(shell find ./pkg/receiver/* -type f -name "go.mod" -print -exec dirname {} \; | sort | uniq)
PKG_RECEIVER_DIRS = $(shell find ./pkg/receiver/* -type f -name '*go.mod*' | sed -r 's|/[^/]+$$||' |sort | uniq )

# set ARCH var based on output
ifeq ($(ARCH),x86_64)
Expand Down Expand Up @@ -57,9 +59,10 @@ install-tools:
go install honnef.co/go/tools/cmd/staticcheck@latest
go install github.com/securego/gosec/v2/cmd/gosec@latest
go install golang.org/x/tools/cmd/goimports@latest
go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)

.PHONY: checks $(PKG_RECEIVER_DIRS)
checks: $(PKG_RECEIVER_DIRS)
.PHONY: lint-all $(PKG_RECEIVER_DIRS)
lint-all: $(PKG_RECEIVER_DIRS)

$(PKG_RECEIVER_DIRS):
$(MAKE) -C $@ lint
Expand All @@ -69,7 +72,8 @@ $(PKG_RECEIVER_DIRS):
for-all:
@echo "running $${CMD} in root"
@$${CMD}
@set -e; for dir in $(NONROOT_MODS); do \
@set -e; for dir in $(PKG_RECEIVER_DIRS); do \
@echo "running $${CMD} in $${dir}"
(cd "$${dir}" && \
echo "running $${CMD} in $${dir}" && \
$${CMD} ); \
Expand Down
10 changes: 3 additions & 7 deletions Makefile.Common
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,9 @@ SRC_ROOT := $(shell git rev-parse --show-toplevel)

.PHONY: lint
lint:
@go fmt ./...
@go vet ./...
@staticcheck ./...
@gosec ./...
@goimports -w ./
golangci-lint run

.PHONY: tidy
tidy:
@rm go.sum
@go mod tidy -compat=1.19
rm go.sum
go mod tidy -compat=1.19
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ TODO: Add more details here, bit of a preamble...

1. `brew install go`
2. `brew install pre-commit`
3. `pre-commit install
3. `pre-commit install`
4. Create a PAT for GitHub with read access only
5. Run `export GH_USER=<user>` and `export GH_PAT=<pat>`
6. Run `make run`
Expand Down