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

release: Goreleaser configuration and automation. #18

Merged
merged 7 commits into from
Mar 21, 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
30 changes: 30 additions & 0 deletions .github/workflows/goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: goreleaser

on:
push:
tags:
- 'v1.**'

permissions:
contents: write
# packages: write
# issues: write

jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- run: git fetch --force --tags
- uses: actions/setup-go@v3
with:
go-version-file: 'go.mod'
- uses: goreleaser/goreleaser-action@v4
with:
distribution: goreleaser
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
47 changes: 47 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
before:
hooks:
# You may remove this if you don't use go modules.
- go mod tidy
# you may remove this if you don't need go generate
- go generate ./...

# Build mac universal binary.
universal_binaries:
- replace: true

builds:
- main: cmd/conduit/main.go
env:
- CGO_ENABLED=0
goos:
- linux
- windows
- darwin
# skip 386 architecture.
goarch:
- amd64
- arm64
ldflags: >
-s -w
-X github.com/algorand/conduit/version.Hash={{.FullCommit}}
-X github.com/algorand/conduit/version.ShortHash={{.ShortCommit}}
-X github.com/algorand/conduit/version.CompileTime={{.Timestamp}}
-X github.com/algorand/conduit/version.ReleaseVersion={{.Version}}

archives:
- replacements:
darwin: Darwin
linux: Linux
windows: Windows
amd64: x86_64
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ incpatch .Version }}-next"
changelog:
sort: asc
filters:
exclude:
- '^chore:'
- '^docs:'
- '^test:'
12 changes: 5 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ SRCPATH := $(shell pwd)
export GOPATH := $(shell go env GOPATH)
GOPATH1 := $(firstword $(subst :, ,$(GOPATH)))

# TODO: ensure any additions here are mirrored in misc/release.py
GOLDFLAGS += -X github.com/algorand/indexer/version.Hash=$(shell git log -n 1 --pretty="%H")
GOLDFLAGS += -X github.com/algorand/indexer/version.Dirty=$(if $(filter $(strip $(shell git status --porcelain|wc -c)), "0"),,true)
GOLDFLAGS += -X github.com/algorand/indexer/version.CompileTime=$(shell date -u +%Y-%m-%dT%H:%M:%S%z)
GOLDFLAGS += -X github.com/algorand/indexer/version.GitDecorateBase64=$(shell git log -n 1 --pretty="%D"|base64|tr -d ' \n')
#GOLDFLAGS += -X github.com/algorand/indexer/version.ReleaseVersion=$(shell cat .version)
GOLDFLAGS += -X github.com/algorand/conduit/version.Hash=$(shell git log -n 1 --pretty="%H")
GOLDFLAGS += -X github.com/algorand/conduit/version.ShortHash=$(shell git log -n 1 --pretty="%h")
GOLDFLAGS += -X github.com/algorand/conduit/version.CompileTime=$(shell date -u +%Y-%m-%dT%H:%M:%S%z)
GOLDFLAGS += -X "github.com/algorand/conduit/version.ReleaseVersion=Dev Build"

COVERPKG := $(shell go list ./... | grep -v '/cmd/' | egrep -v '(testing|test|mocks)$$' | paste -s -d, - )

Expand All @@ -18,7 +16,7 @@ export GO_IMAGE = golang:$(shell go version | cut -d ' ' -f 3 | tail -c +3 )
all: conduit

conduit:
go generate ./... && cd cmd/conduit && go build -ldflags="${GOLDFLAGS}"
go generate ./... && cd cmd/conduit && go build -ldflags='${GOLDFLAGS}'

# check that all packages (except tests) compile
check:
Expand Down
5 changes: 2 additions & 3 deletions cmd/conduit/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/cobra/doc"

"github.com/algorand/indexer/version"

"github.com/algorand/conduit/cmd/conduit/internal/initialize"
"github.com/algorand/conduit/cmd/conduit/internal/list"
"github.com/algorand/conduit/conduit"
Expand All @@ -20,6 +18,7 @@ import (
_ "github.com/algorand/conduit/conduit/plugins/exporters/all"
_ "github.com/algorand/conduit/conduit/plugins/importers/all"
_ "github.com/algorand/conduit/conduit/plugins/processors/all"
"github.com/algorand/conduit/version"
)

var (
Expand Down Expand Up @@ -59,6 +58,7 @@ func runConduitCmdWithConfig(args *conduit.Args) error {
return fmt.Errorf("runConduitCmdWithConfig(): failed to create logger: %w", err)
}

logger.Infof("Starting Conduit %s", version.LongVersion())
logger.Infof("Using data directory: %s", args.ConduitDataDir)
logger.Info("Conduit configuration is valid")

Expand Down Expand Up @@ -109,7 +109,6 @@ func makeConduitCmd() *cobra.Command {
},
PersistentPreRun: func(cmd *cobra.Command, args []string) {
if vFlag {
fmt.Println("Conduit Pre-Release")
fmt.Printf("%s\n", version.LongVersion())
os.Exit(0)
}
Expand Down
42 changes: 42 additions & 0 deletions version/strings.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package version

import (
"fmt"
)

// These are targets for compiling in build information.
// They are set by the Makefile and .goreleaser.yml

var (
// Hash git commit hash.
Hash string

// ShortHash git commit short hash.
ShortHash string

// CompileTime of the binary.
CompileTime string

// ReleaseVersion based on release tag.
ReleaseVersion string
)

// UnknownVersion is used when the version is not known.
const UnknownVersion = "(unknown version)"

// Version the binary version.
func Version() string {
if ReleaseVersion == "" {
return UnknownVersion
}
return ReleaseVersion
}

// LongVersion the long form of the binary version.
func LongVersion() string {
if ReleaseVersion == "" || Hash == "" || CompileTime == "" {
return UnknownVersion
}

return fmt.Sprintf("Conduit %s (%s)", ReleaseVersion, ShortHash)
}