Skip to content

Commit

Permalink
ci: go build with make targets
Browse files Browse the repository at this point in the history
Signed-off-by: Roy Golan <[email protected]>
  • Loading branch information
rgolangh committed Oct 23, 2024
1 parent 870b5c4 commit 5981227
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 8 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/go.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# This workflow will build a golang project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go

name: Go

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:

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

- name: extract args
run: |
make print-vars | grep GO_VERSION >> $GITHUB_ENV
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}

- name: extract args
run: |
make print-vars | grep GO_VERSION >> $GITHUB_ENV
- name: Build
run: make build
3 changes: 2 additions & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
name: goreleaser

on:
pull_request:
push:
# run only against tags
branches:
- main
tags:
- "v*"

Expand Down
27 changes: 21 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
SHELL: /bin/bash
SHELL := /bin/bash

GO_VERSION := $(shell awk '/^go / {print $$2}' go.mod)
GIT_VERSION := $(shell git describe --always --tags HEAD)
GIT_COMMIT := $(shell git rev-parse HEAD)
GIT_COMMIT_DATE := $(shell git log --pretty=%ct -1)
GIT_TREE_STATE := $(shell git diff --exit-code --quiet && echo clean || echo dirty)

# Print out only the variables declared in this makefile. Will be used
# by other tools like github workflows or any other build tool.
print-vars:
@$(foreach v,$(sort $(.VARIABLES)), \
$(if $(filter-out environment% default automatic, $(origin $v)), \
$(if $(filter-out .%,$(v)), \
echo $v=\'$($v)\';)))

install:
go install -ldflags="$(ldflags)" .
Expand All @@ -9,10 +23,11 @@ fmt:
vet:
go vet ./...

ldflags := -X github.com/rgolangh/pq/internal/version.Version=$(shell git describe --always --tags HEAD)
ldflags += -X github.com/rgolangh/pq/internal/version.Commit=$(shell git rev-parse HEAD)
ldflags += -X github.com/rgolangh/pq/internal/version.CommitDate=$(shell date --iso-8601=seconds)
ldflags += -X github.com/rgolangh/pq/internal/version.TreeState=$(shell git diff --exit-code --quiet && echo clean || echo dirty)
ldflags := -X github.com/rgolangh/pq/internal/version.Version=$(GIT_VERSION)
ldflags += -X github.com/rgolangh/pq/internal/version.Commit=$(GIT_COMMIT)
ldflags += -X github.com/rgolangh/pq/internal/version.CommitDate=$(GIT_COMMIT_DATE)
ldflags += -X github.com/rgolangh/pq/internal/version.TreeState=$(GIT_TREE_STATE)

build: fmt vet
go build -o bin/ -ldflags="$(ldflags)" ./...
go build -v -o bin/ -ldflags="$(ldflags)" ./...

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/rgolangh/pq

go 1.23
go 1.23.2

require (
github.com/spf13/cobra v1.8.0
Expand Down

0 comments on commit 5981227

Please sign in to comment.