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

Add GitHub workflow #118

Merged
merged 8 commits into from
May 24, 2022
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
42 changes: 42 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: CI

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
schedule:
- cron: '0 */12 * * *'

jobs:

build-test:
name: "Build & Test"
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
go: [ '1.18', '1.17' ]

steps:
- uses: actions/checkout@v3

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

- name: Download Deps
run: go mod download

- name: Check go.mod
run: |
go mod tidy -v
git diff --name-only --exit-code go.mod || ( git diff && echo "Run go tidy to update go.mod" && false )

- name: Build All
run: make build

- name: Test All
run: make test
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ _testmain.go
*.out

# Builds
build/
/.build/
go-callvis
12 changes: 0 additions & 12 deletions .travis.yml

This file was deleted.

63 changes: 41 additions & 22 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,34 +1,56 @@
SHELL = /bin/bash
SHELL := /usr/bin/env bash -o pipefail

GIT_VERSION ?= $(shell git describe --always --tags --always --dirty)
GIT_VERSION ?= $(shell git describe --always --tags --match 'v*' --dirty)
COMMIT ?= $(shell git rev-parse HEAD)
BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD)
BUILD_DATE ?= $(shell date +%s)
BUILD_HOST ?= $(shell hostname)
BUILD_USER ?= $(shell id -un)

PROJECT := go-callvis
BUILD_DIR ?= .build

GOOS ?= $(shell go env GOOS)
GOARCH = amd64
PLATFORMS := linux-$(GOARCH) darwin-$(GOARCH)

BUILD_DIR ?= ./build
ORG := github.com/ofabry
PROJECT := go-callvis
REPOPATH ?= $(ORG)/$(PROJECT)
BUILD_PACKAGE = $(REPOPATH)

GO_BUILD_TAGS ?= ""
GO_LDFLAGS := "-X main.commit=$(GIT_VERSION)"
GO_FILES := $(shell go list -f '{{join .Deps "\n"}}' $(BUILD_PACKAGE) | grep $(ORG) | xargs go list -f '{{ range $$file := .GoFiles }} {{$$.Dir}}/{{$$file}}{{"\n"}}{{end}}')
GO_LDFLAGS := \
-X main.commit=$(GIT_VERSION)
GO_FILES := $(shell go list ./... | xargs go list -f '{{ range $$file := .GoFiles }} {{$$.Dir}}/{{$$file}}{{"\n"}}{{end}}')

ifeq ($(NOSTRIP),)
GO_LDFLAGS += -w -s
endif

ifeq ($(NOTRIM),)
GO_BUILD_ARGS += -trimpath
endif

ifeq ($(V),1)
GO_BUILD_ARGS += -v
endif

export GO111MODULE=on
export DOCKER_BUILDKIT=1

help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

install:
go install -tags $(GO_BUILD_TAGS) -ldflags $(GO_LDFLAGS)
build: ## Build go-callvis
go build -tags $(GO_BUILD_TAGS) -ldflags "$(GO_LDFLAGS)" $(GO_BUILD_ARGS)

all:
go build -tags $(GO_BUILD_TAGS) -ldflags $(GO_LDFLAGS)
test: ## Run unit tests
go test -tags $(GO_BUILD_TAGS) -ldflags "$(GO_LDFLAGS)" $(GO_BUILD_ARGS) -short -race ./...

install: ## Install go-callvis
go install -tags $(GO_BUILD_TAGS) -ldflags "$(GO_LDFLAGS)" $(GO_BUILD_ARGS)

$(BUILD_DIR)/$(PROJECT): $(BUILD_DIR)/$(PROJECT)-$(GOOS)-$(GOARCH)
cp $(BUILD_DIR)/$(PROJECT)-$(GOOS)-$(GOARCH) $@

$(BUILD_DIR)/$(PROJECT)-%-$(GOARCH): $(GO_FILES) $(BUILD_DIR)
GOOS=$* GOARCH=$(GOARCH) go build -tags $(GO_BUILD_TAGS) -ldflags $(GO_LDFLAGS) -o $@ $(BUILD_PACKAGE)
GOOS=$* GOARCH=$(GOARCH) go build -tags $(GO_BUILD_TAGS) -ldflags "$(GO_LDFLAGS)" -o $@ $(GO_BUILD_ARGS)

%.sha256: %
shasum -a 256 $< &> $@
Expand All @@ -40,13 +62,10 @@ $(BUILD_DIR):

cross: $(foreach platform, $(PLATFORMS), $(BUILD_DIR)/$(PROJECT)-$(platform).sha256)

release: cross
release: cross ## Release go-callvis
ls -hl $(BUILD_DIR)

test: $(BUILD_DIR)/$(PROJECT)
go test -v $(REPOPATH)

clean:
rm -rf $(BUILD_DIR)
clean: ## Clean build directory
rm -vrf $(BUILD_DIR)

.PHONY: cross release install test clean
.PHONY: help build test install cross release clean
Loading