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 ci #10

Merged
merged 3 commits into from
Nov 8, 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
13 changes: 13 additions & 0 deletions .bingo/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

# Ignore everything
*

# But not these files:
!.gitignore
!*.mod
!*.sum
!README.md
!Variables.mk
!variables.env

*tmp.mod
14 changes: 14 additions & 0 deletions .bingo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Project Development Dependencies.

This is directory which stores Go modules with pinned buildable package that is used within this repository, managed by https://github.com/bwplotka/bingo.

* Run `bingo get` to install all tools having each own module file in this directory.
* Run `bingo get <tool>` to install <tool> that have own module file in this directory.
* For Makefile: Make sure to put `include .bingo/Variables.mk` in your Makefile, then use $(<upper case tool name>) variable where <tool> is the .bingo/<tool>.mod.
* For shell: Run `source .bingo/variables.env` to source all environment variable for each tool.
* For go: Import `.bingo/variables.go` to for variable names.
* See https://github.com/bwplotka/bingo or -h on how to add, remove or change binaries dependencies.

## Requirements

* Go 1.14+
31 changes: 31 additions & 0 deletions .bingo/Variables.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Auto generated binary variables helper managed by https://github.com/bwplotka/bingo v0.8. DO NOT EDIT.
# All tools are designed to be build inside $GOBIN.
BINGO_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
GOPATH ?= $(shell go env GOPATH)
GOBIN ?= $(firstword $(subst :, ,${GOPATH}))/bin
GO ?= $(shell which go)

# Below generated variables ensure that every time a tool under each variable is invoked, the correct version
# will be used; reinstalling only if needed.
# For example for golangci-lint variable:
#
# In your main Makefile (for non array binaries):
#
#include .bingo/Variables.mk # Assuming -dir was set to .bingo .
#
#command: $(GOLANGCI_LINT)
# @echo "Running golangci-lint"
# @$(GOLANGCI_LINT) <flags/args..>
#
GOLANGCI_LINT := $(GOBIN)/golangci-lint-v1.55.2
$(GOLANGCI_LINT): $(BINGO_DIR)/golangci-lint.mod
@# Install binary/ries using Go 1.14+ build command. This is using bwplotka/bingo-controlled, separate go module with pinned dependencies.
@echo "(re)installing $(GOBIN)/golangci-lint-v1.55.2"
@cd $(BINGO_DIR) && GOWORK=off $(GO) build -mod=mod -modfile=golangci-lint.mod -o=$(GOBIN)/golangci-lint-v1.55.2 "github.com/golangci/golangci-lint/cmd/golangci-lint"

GORELEASER := $(GOBIN)/goreleaser-v1.22.0
$(GORELEASER): $(BINGO_DIR)/goreleaser.mod
@# Install binary/ries using Go 1.14+ build command. This is using bwplotka/bingo-controlled, separate go module with pinned dependencies.
@echo "(re)installing $(GOBIN)/goreleaser-v1.22.0"
@cd $(BINGO_DIR) && GOWORK=off $(GO) build -mod=mod -modfile=goreleaser.mod -o=$(GOBIN)/goreleaser-v1.22.0 "github.com/goreleaser/goreleaser"

1 change: 1 addition & 0 deletions .bingo/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module _ // Fake go.mod auto-created by 'bingo' for go -moddir compatibility with non-Go projects. Commit this file, together with other .mod files.
5 changes: 5 additions & 0 deletions .bingo/golangci-lint.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module _ // Auto generated by https://github.com/bwplotka/bingo. DO NOT EDIT

go 1.21.3

require github.com/golangci/golangci-lint v1.55.2 // cmd/golangci-lint
964 changes: 964 additions & 0 deletions .bingo/golangci-lint.sum

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions .bingo/goreleaser.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module _ // Auto generated by https://github.com/bwplotka/bingo. DO NOT EDIT

go 1.21.3

require github.com/goreleaser/goreleaser v1.22.0
1,149 changes: 1,149 additions & 0 deletions .bingo/goreleaser.sum

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions .bingo/variables.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Auto generated binary variables helper managed by https://github.com/bwplotka/bingo v0.8. DO NOT EDIT.
# All tools are designed to be build inside $GOBIN.
# Those variables will work only until 'bingo get' was invoked, or if tools were installed via Makefile's Variables.mk.
GOBIN=${GOBIN:=$(go env GOBIN)}

if [ -z "$GOBIN" ]; then
GOBIN="$(go env GOPATH)/bin"
fi


GOLANGCI_LINT="${GOBIN}/golangci-lint-v1.55.2"

GORELEASER="${GOBIN}/goreleaser-v1.22.0"

22 changes: 22 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: lint

on:
workflow_dispatch:
pull_request:
merge_group:
push:
branches:
- main

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-go@v4
with:
go-version-file: "go.mod"

- name: Run golangci linting checks
run: make lint GOLANGCI_LINT_ARGS="--out-format github-actions"
51 changes: 51 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: release

on:
workflow_dispatch:
merge_group:
push:
branches:
- 'main'
tags:
- 'v*'
pull_request:
branches:
- main

jobs:
goreleaser:
name: goreleaser
runs-on: ubuntu-latest
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Install Go
uses: actions/setup-go@v4
with:
go-version-file: "go.mod"

- name: Set the release related variables
run: |
if [[ $GITHUB_REF == refs/tags/* ]]; then
# Release tags.
echo IMAGE_TAG="${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
echo GORELEASER_ARGS="--clean" >> $GITHUB_ENV
echo ENABLE_RELEASE_PIPELINE=true >> $GITHUB_ENV
elif [[ $GITHUB_REF == refs/heads/* ]]; then
# Branch build.
echo IMAGE_TAG="$(echo "${GITHUB_REF#refs/heads/}" | sed -r 's|/+|-|g')" >> $GITHUB_ENV
echo GORELEASER_ARGS="--clean --skip-validate" >> $GITHUB_ENV
elif [[ $GITHUB_REF == refs/pull/* ]]; then
# PR build.
echo IMAGE_TAG="pr-$(echo "${GITHUB_REF}" | sed -E 's|refs/pull/([^/]+)/?.*|\1|')" >> $GITHUB_ENV
else
echo IMAGE_TAG="$(git describe --tags --always)" >> $GITHUB_ENV
fi

- name: Run goreleaser
run: make release
env:
GITHUB_TOKEN: ${{ github.token }}
22 changes: 22 additions & 0 deletions .github/workflows/unit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: unit

on:
workflow_dispatch:
pull_request:
merge_group:
push:
branches:
- main

jobs:
unit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-go@v4
with:
go-version-file: "go.mod"

- name: Run unit tests
run: make unit
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
buoy
buoy
dist/
25 changes: 25 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
before:
hooks:
- go mod tidy
- go mod download
builds:
- id: buoy
main: main.go
binary: buoy
asmflags: "{{ .Env.GO_BUILD_ASMFLAGS }}"
gcflags: "{{ .Env.GO_BUILD_GCFLAGS }}"
ldflags: "{{ .Env.GO_BUILD_LDFLAGS }}"
mod_timestamp: "{{ .CommitTimestamp }}"
goos:
- linux
- darwin
goarch:
- amd64
- arm64
- ppc64le
- s390x
release:
disable: '{{ ne .Env.ENABLE_RELEASE_PIPELINE "true" }}'
changelog:
use: github-native
skip: '{{ ne .Env.ENABLE_RELEASE_PIPELINE "true" }}'
29 changes: 28 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,29 @@
include .bingo/Variables.mk

export GIT_VERSION ?= $(shell git describe --tags --always --dirty)
export VERSION_PKG ?= $(shell go list -m)/internal/cli
export GO_BUILD_ASMFLAGS ?= all=-trimpath=${PWD}
export GO_BUILD_LDFLAGS ?= -s -w -X "$(VERSION_PKG).version=$(GIT_VERSION)"
export GO_BUILD_GCFLAGS ?= all=-trimpath=${PWD}

export IMAGE_REPO ?= docker.io/bpalmer/buoy
export IMAGE_TAG ?= devel

build:
go build -o buoy main.go
go build \
-asmflags '$(GO_BUILD_ASMFLAGS)' \
-ldflags '$(GO_BUILD_LDFLAGS)' \
-gcflags '$(GO_BUILD_GCFLAGS)' \
-o buoy main.go

export ENABLE_RELEASE_PIPELINE ?= false
export GORELEASER_ARGS ?= --snapshot --clean
release: $(GORELEASER)
$(GORELEASER) $(GORELEASER_ARGS)

GOLANGCI_LINT_ARGS ?=
lint: $(GOLANGCI_LINT)
$(GOLANGCI_LINT) run $(GOLANGCI_LINT_ARGS)
unit:
go test ./...

2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ require (
github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
github.com/evanphx/json-patch/v5 v5.6.0 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
Expand Down Expand Up @@ -52,7 +51,6 @@ require (
github.com/muesli/reflow v0.3.0 // indirect
github.com/muesli/termenv v0.15.1 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/net v0.13.0 // indirect
Expand Down
Loading