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

Gitworkflows patch 1 #4

Merged
merged 4 commits into from
Sep 23, 2024
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
82 changes: 51 additions & 31 deletions .github/workflows/pipeline.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
name: 'app-pipeline'

on:
push:
pull_request:

jobs:
test:
strategy:
Expand All @@ -10,16 +12,17 @@ jobs:
platform: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.platform }}
steps:
- name: Checkout code
uses: actions/checkout@v2

- uses: actions/setup-go@v1
- name: Set up Go
uses: actions/setup-go@v2
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Consider using the latest version of actions/setup-go

While updating from v1 to v2 is good, consider using the latest version (v4 as of now) for potential improvements and bug fixes.

Suggested change
uses: actions/setup-go@v2
uses: actions/setup-go@v4

with:
go-version: ${{ matrix.go-version }}

- uses: actions/checkout@v1

- name: Cache go dependencies
id: unit-cache-go-dependencies
uses: actions/cache@v1
- name: Cache Go dependencies
id: cache-go-dependencies
uses: actions/cache@v2
with:
path: |
~/go/pkg/mod
Expand All @@ -28,11 +31,11 @@ jobs:
restore-keys: |
${{ runner.os }}-go-${{ matrix.go-version }}-

- name: Install go dependencies
if: steps.unit-cache-go-dependencies.outputs.cache-hit != 'true'
- name: Install Go dependencies
if: steps.cache-go-dependencies.outputs.cache-hit != 'true'
run: make bootstrap

- name: Run Static Analyses
- name: Run Static Analysis
run: make lint

- name: Run Tests
Expand All @@ -41,15 +44,17 @@ jobs:
build-artifacts:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v1
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: '1.18.x'

- uses: actions/checkout@v1

- name: Cache go dependencies
- name: Cache Go dependencies
id: package-cache-go-dependencies
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: |
~/go/pkg/mod
Expand All @@ -65,53 +70,68 @@ jobs:
- name: Build snapshot artifacts
run: make ci-build-snapshot-packages

- uses: actions/upload-artifact@master
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: artifacts
path: dist


test-linux-artifacts:
needs: [ build-artifacts ]
needs: build-artifacts
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: actions/download-artifact@master
- name: Checkout code
uses: actions/checkout@v2

- name: Download artifacts
uses: actions/download-artifact@v3
with:
name: artifacts
path: dist
- name: Test linux run

- name: Test Linux run
run: make ci-test-linux-run
- name: Test docker run

- name: Test Docker run
run: make ci-plugs-out-test

test-mac-artifacts:
needs: [ build-artifacts ]
needs: build-artifacts
runs-on: macos-latest
steps:
- uses: actions/checkout@master
- uses: actions/download-artifact@master
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: '1.20' # Specify the Go version you need

- name: Download artifacts
uses: actions/download-artifact@v3
with:
name: artifacts
path: dist
- name: Test darwin run

- name: Test Darwin run
run: make ci-test-mac-run

release:
needs: [ test, build-artifacts, test-linux-artifacts, test-mac-artifacts ]
needs: [test, build-artifacts, test-linux-artifacts, test-mac-artifacts]
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/v')
steps:
- name: Checkout code
uses: actions/checkout@v2

- uses: actions/setup-go@v1
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: '1.18.x'

- uses: actions/checkout@v1

- name: Cache go dependencies
- name: Cache Go dependencies
id: release-cache-go-dependencies
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: |
~/go/pkg/mod
Expand Down
33 changes: 10 additions & 23 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ TMP = ./.tmp
RESULTS = $(TMP)/results
ASSETS = assets
DBASSET = $(ASSETS)/licenses.db
# note: go tools requires an absolute path
BIN = $(abspath $(TMP)/bin)
COVER_REPORT = $(RESULTS)/cover.report
COVER_TOTAL = $(RESULTS)/cover.total
LINTCMD = $(BIN)/golangci-lint run --tests=false --config .golangci.yaml

BOLD := $(shell tput -T linux bold)
PURPLE := $(shell tput -T linux setaf 5)
GREEN := $(shell tput -T linux setaf 2)
Expand All @@ -15,7 +15,6 @@ RED := $(shell tput -T linux setaf 1)
RESET := $(shell tput -T linux sgr0)
TITLE := $(BOLD)$(PURPLE)
SUCCESS := $(BOLD)$(GREEN)
# the quality gate lower threshold for unit test total % coverage (by function statements)
COVERAGE_THRESHOLD := 34

RELEASE_CMD=$(BIN)/goreleaser --rm-dist
Expand Down Expand Up @@ -44,25 +43,18 @@ help:

bootstrap: ## Download and install all project dependencies (+ prep tooling in the ./.tmp dir)
$(call title,Downloading dependencies)
# prep temp dirs
mkdir -p $(TMP) || exit 1
mkdir -p $(RESULTS) || exit 1
mkdir -p $(BIN) || exit 1
# download install project dependencies + tooling
@mkdir -p $(TMP) $(RESULTS) $(BIN) || exit 1
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Standardize error handling across commands

Some commands use '|| exit 1' for error handling while others don't. Consider standardizing this across all commands for consistency and robust error handling.

	@mkdir -p $(TMP) $(RESULTS) $(BIN) || exit 1
	@go mod download || exit 1
	@cat tools.go | grep _ | awk -F'"' '{print $$2}' | xargs -tI % env GOBIN=$(BIN) go install % || exit 1

go mod download || exit 1
cat tools.go | grep _ | awk -F'"' '{print $$2}' | xargs -tI % env GOBIN=$(BIN) go install % || exit 1
# install golangci-lint
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(BIN) v1.50.1 || exit 1
# install pkger
cd $(TMP) && curl -sLO https://github.com/markbates/pkger/releases/download/v0.17.0/pkger_0.17.0_$(shell uname)_x86_64.tar.gz && \
tar -xzvf pkger_0.17.0_$(shell uname)_x86_64.tar.gz pkger && \
mv pkger $(BIN) || exit 1
# install goreleaser
GOBIN=$(BIN) go install github.com/goreleaser/goreleaser@v1.3.1 || exit 1

$(DBASSET):
$(call title,Building assets)
mkdir -p $(ASSETS) || exit 1
@mkdir -p $(ASSETS) || exit 1
$(BIN)/license_serializer -output $(ASSETS) || exit 1

pkged.go: $(DBASSET)
Expand All @@ -89,22 +81,19 @@ lint-fix: ## Auto-format all source code + run golangci-lint fixers
unit: ## Run unit tests (with coverage)
$(call title,Running unit tests)
go test -coverprofile $(COVER_REPORT) ./...
@go tool cover -func $(COVER_REPORT) | grep total | awk '{print substr($$3, 1, length($$3)-1)}' > $(COVER_TOTAL)
@go tool cover -func $(COVER_REPORT) | grep total | awk '{print substr($$3, 1, length($$3)-1)}' > $(COVER_TOTAL)
@echo "Coverage: $$(cat $(COVER_TOTAL))"
@if [ $$(echo "$$(cat $(COVER_TOTAL)) >= $(COVERAGE_THRESHOLD)" | bc -l) -ne 1 ]; then echo "$(RED)$(BOLD)Failed coverage quality gate (> $(COVERAGE_THRESHOLD)%)$(RESET)" && false; fi

# The following targets are all CI related
@if [ $$(echo "$$(cat $(COVER_TOTAL)) >= $(COVERAGE_THRESHOLD)" | bc -l) -ne 1 ]; then \
echo "$(RED)$(BOLD)Failed coverage quality gate (> $(COVERAGE_THRESHOLD)%)$(RESET)" && false; \
fi

ci-build-snapshot-packages: pkged.go
$(RELEASE_CMD) \
--snapshot \
--skip-publish
$(RELEASE_CMD) --snapshot --skip-publish

# note: since google's licenseclassifier requires the go tooling ('go list' from x/tools/go/packages) we need to use a golang image
ci-plugs-out-test:
docker run \
-v //var/run/docker.sock://var/run/docker.sock \
-v /${PWD}://src \
-v ${PWD}://src \
-w //src \
golang:latest \
/bin/bash -x -c "\
Expand Down Expand Up @@ -137,6 +126,4 @@ ci-release: pkged.go
$(BIN)/goreleaser --rm-dist

clean: ## Clean build artifacts
rm -rf dist
rm -rf .tmp
rm -rf $(RESULTS)
rm -rf dist .tmp $(RESULTS)
Loading