Skip to content

Commit

Permalink
goreleaser integration
Browse files Browse the repository at this point in the history
  • Loading branch information
philpennock committed Jul 18, 2023
1 parent f01d49e commit f0e0f7e
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 1 deletion.
56 changes: 56 additions & 0 deletions .github/workflows/release.yaml
@@ -0,0 +1,56 @@
name: smtpdane tool release
on:
push:
tags:
- 'v*'

permissions:
# Control the GITHUB_TOKEN permissions; GitHub's docs on which permission scopes control what are a little lacking.
# By having this block, all permissions not listed here are set to none.
#
# <https://goreleaser.com/ci/actions/> documents which scopes are needed for it.
# Uploading archives as release artifacts is bundled into the contents: permission key! (goreleaser documents as content: but it's contents:).
# packages: is for pushing docker images to github (ghcr.io)
# actions: is for uploading artifacts
contents: write
packages: write
actions: write

jobs:
goreleaser:
runs-on: ubuntu-latest

steps:

- name: Checkout
uses: actions/checkout@v3
with:
# NB: the `fetch-depth: 0` setting is documented by goreleaser
# as a requirement, for the changelog feature to work correctly.
fetch-depth: 0

# If we had something suitable for a Docker image, here we would setup QEMU and BuildX

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.20.x'
check-latest: true

- name: Basic Go integrity checks
run: |
go vet ./...
t="$(go list -m -retracted -f '{{if .Retracted}}::error file=go.mod::{{.Path}} is retracted{{end}}' all)"
if [ ".$t" != "." ]; then printf '%s\n' "$t"; exit 1; fi
- name: Run GoReleaser
id: goreleaser
uses: goreleaser/goreleaser-action@v4
with:
distribution: goreleaser
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}


3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -2,3 +2,6 @@ smtpdane

coverage.out
c.partial.out

# goreleaser
dist/
63 changes: 63 additions & 0 deletions .goreleaser.yaml
@@ -0,0 +1,63 @@

before:
hooks:
- go mod tidy

builds:
- env:
- CGO_ENABLED=0
goos:
- linux
- windows
- darwin
- freebsd
goarch:
- amd64
- arm64
ignore:
- goos: windows
goarch: arm64

# reproducible builds:
mod_timestamp: "{{ .CommitTimestamp }}"
flags:
- "-trimpath"
# ldflags: Default is `-s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}} -X main.builtBy=goreleaser`.
# We switch the .Date to .CommitDate per advice at bottom of <https://goreleaser.com/customization/build/> re reproducibility.
ldflags:
- "-s -w -X main.Version={{.Version}} -X main.Commit={{.Commit}} -X main.CompileDate={{.CommitDate}} -X main.BuiltBy=goreleaser"

archives:
- format: tar.gz
wrap_in_directory: true
format_overrides:
- goos: windows
format: zip

checksum:
name_template: 'SHA256SUMS'
algorithm: sha256

snapshot:
name_template: "{{ incpatch .Version }}-next"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'

nfpms:
- file_name_template: 'smtpdane-{{.Version}}-{{.Arch}}{{if .Arm}}{{.Arm}}{{end}}'
homepage: https://go.pennock.tech/smtpdane
description: SMTP DANE Tester
maintainer: Phil Pennock <phil@pennock-tech.com>
license: MIT
vendor: Pennock Tech, LLC
bindir: /usr/local/bin
formats:
- deb
- rpm

# yaml-language-server: $schema=https://goreleaser.com/static/schema-pro.json
# vim: set ts=2 sw=2 tw=0 fo=cnqoj
17 changes: 16 additions & 1 deletion version.go
Expand Up @@ -13,10 +13,25 @@ import (
const ProjectName = "smtpdane"

// may be updated by the linker on the link command-line when compiling
var Version string = "0.5.1-dev"
var (
Version string = "0.5.1-dev"
Commit = ""
CompileDate = ""
BuiltBy = ""
)

func version() {
fmt.Printf("%s version %s\n", ProjectName, Version)
if Commit != "" {
fmt.Printf("%s commit %s\n", ProjectName, Commit)
}
if CompileDate != "" {
fmt.Printf("%s compile-date: %s\n", ProjectName, CompileDate)
}
if BuiltBy != "" {
fmt.Printf("%s built-by: %s\n", ProjectName, BuiltBy)
}

fmt.Printf("%s: Golang: Runtime: %s\n", ProjectName, runtime.Version())

buildInfo, ok := debug.ReadBuildInfo()
Expand Down

0 comments on commit f0e0f7e

Please sign in to comment.