Skip to content

Commit

Permalink
Create goreleaser config and GHA (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
jlewi authored Apr 6, 2024
1 parent 749faa2 commit af93946
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 0 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/releaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Documentation
# https://goreleaser.com/ci/actions/
#
# To test the workflow in a presubmit
# 1. Push to a branch and create a PR
# 2. Create a new release in GitHub
# * Mark it as a pre-release
# * Create the release from the branch you pushed
#
# Using the CLI something like
# gh release create v0.0.1-pre1 -p --target=jlewi/foyle --title="goreleaser test" --notes="goreleaser test"
#
# This will trigger a release from that branch.
#
# N.B. You also need a .goreleaser.yaml file to actually configure goreleaser.
name: goreleaser

# n.b. uncomment to debug in presubmit
on:
push:
# run only against tags
tags:
- '*'

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

jobs:
goreleaser:
# We can use macos-latest to run on macos but we shouldn't need to do this because
# Its pure go so we can cross-compile for mac on ubuntu.
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- run: git fetch --force --tags
- uses: actions/setup-go@v4
with:
go-version: stable
# More assembly might be required: Docker logins, GPG, etc. It all depends
# on your needs.
- uses: goreleaser/goreleaser-action@v4
with:
# either 'goreleaser' (default) or 'goreleaser-pro':
distribution: goreleaser
version: latest
args: release --clean
workdir: ./app
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
67 changes: 67 additions & 0 deletions app/.goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Check the documentation at https://goreleaser.com
#
# To verify LDFlags
# 1. Run a snapshot build
# goreleaser release --snapshot --clean
#
# 2. Check the version on the newly built binary
# ./dist/foyle_darwin_arm64/foyle version
#
# It should be something like
# foyle 0.0.1-next, commit 416e3d5610d5bc21f9dcd82bd1f17c58a13457ca, built at 2024-04-06T23:39:07Z by goreleaser
builds:
- binary: foyle
main: .
env:
- CGO_ENABLED=0
goos:
- linux
- windows
- darwin

goarch:
- amd64
- arm64

# Custom ldflags templates.
# Default is `-s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}} -X main.builtBy=goreleaser`.
ldflags:
- "-s -w -X github.com/jlewi/foyle/app/cmd.version={{.Version}} -X github.com/jlewi/foyle/app/cmd.commit={{.Commit}} -X github.com/jlewi/foyle/app/cmd.date={{.Date}} -X github.com/jlewi/foyle/app/cmd.builtBy=goreleaser"
archives:
# https://goreleaser.com/customization/archive/?h=archives
- id: "binary"
# Setting format to binary uploads the binaries directly rather than wrapping in an archive
# This is convenient because you can just download the binary rather than needing to do download and unpack the binary.
format: binary
- format: tar.gz
# this name template makes the OS and Arch compatible with the results of uname.
name_template: >-
{{ .ProjectName }}_
{{- title .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}{{ end }}
{{- if .Arm }}v{{ .Arm }}{{ end }}
# use zip for windows archives
format_overrides:
- goos: windows
format: zip
# https://goreleaser.com/customization/archive/?h=archives#packaging-only-the-binaries
# This is a trick to ensure only the binaries get packaged in the archive and not the readme.
files:
- none*
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ incpatch .Version }}-next"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'

# The lines beneath this are called `modelines`. See `:help modeline`
# Feel free to remove those if you don't want/use them.
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
# vim: set ts=2 sw=2 tw=0 fo=cnqoj

0 comments on commit af93946

Please sign in to comment.