From 0cb848b937a3fd1b47f88a79802449c309559654 Mon Sep 17 00:00:00 2001 From: Jeremy Lewi Date: Sat, 6 Apr 2024 16:19:48 -0700 Subject: [PATCH] Create goreleaser config and GHA * Setup releases --- .github/workflows/releaser.yaml | 52 ++++++++++++++++++++++++++++++ app/.goreleaser.yaml | 57 +++++++++++++++++++++++++++++++++ 2 files changed, 109 insertions(+) create mode 100644 .github/workflows/releaser.yaml create mode 100644 app/.goreleaser.yaml diff --git a/.github/workflows/releaser.yaml b/.github/workflows/releaser.yaml new file mode 100644 index 00000000..8de8c0d5 --- /dev/null +++ b/.github/workflows/releaser.yaml @@ -0,0 +1,52 @@ +# 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. +# +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 }} \ No newline at end of file diff --git a/app/.goreleaser.yaml b/app/.goreleaser.yaml new file mode 100644 index 00000000..145b5855 --- /dev/null +++ b/app/.goreleaser.yaml @@ -0,0 +1,57 @@ +# Check the documentation at https://goreleaser.com +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/cmd.version={{.Version}} -X github.com/jlewi/foyle/cmd.commit={{.Commit}} -X github.com/jlewi/foyle/cmd.date={{.Date}} -X github.com/jlewi/foyle/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