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

Add release-publishing workflow using GoReleaser #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
50 changes: 27 additions & 23 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
name: release

on:
release:
types: created
push:
tags:
- '*'

permissions:
contents: write # for publishing to github releases

jobs:
releases-matrix:
name: Release Go Binary
goreleaser:
runs-on: ubuntu-latest
strategy:
matrix:
# build and publish in parallel: linux/amd64, linux/arm64, windows/amd64, darwin/amd64, darwin/arm64
goos: [linux, windows, darwin]
goarch: [amd64, arm64]
exclude:
- goarch: arm64
goos: windows
steps:
- uses: actions/checkout@v3
- uses: wangyoucao577/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
goos: ${{ matrix.goos }}
goarch: ${{ matrix.goarch }}
extra_files: LICENSE README.md
compress_assets: "true"
md5sum: "false"
project_path: aws-whoami
binary_name: aws-whoami
- uses: actions/checkout@v3
with:
fetch-depth: 0

- run: git fetch --force --tags

- uses: actions/setup-go@v4
with:
go-version: stable

- uses: goreleaser/goreleaser-action@v4
with:
distribution: goreleaser
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GORELEASER_HOMEBREW_TAP_TOKEN: ${{ secrets.GORELEASER_HOMEBREW_TAP_TOKEN }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

dist/
57 changes: 57 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
project_name: aws-whoami
builds:
- env:
- CGO_ENABLED=0
goos:
- linux
- windows
- darwin
goarch:
- arm64
- amd64
main: ./aws-whoami
nfpms:
- package_name: aws-whoami
vendor: Ben Kehoe
homepage: https://github.com/benkehoe/aws-whoami-golang
maintainer: Ben Kehoe
description: A tool to show what AWS account and identity you're using.
formats: [ deb ]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have you ever tried to make an RPM easily available for installation on Amazon Linux? I'm not clear if that would have to involve getting it in a particular yum repo or what

brews:
- name: aws-whoami
tap:
owner: benkehoe
name: homebrew-tap
token: '{{ .Env.GORELEASER_HOMEBREW_TAP_TOKEN }}'
commit_author:
name: Ben Kehoe
email: [email protected]
homepage: https://github.com/benkehoe/aws-whoami-golang
description: A tool to show what AWS account and identity you're using.
archives:
- 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
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
4 changes: 2 additions & 2 deletions aws-whoami/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
"github.com/aws/smithy-go"
)

var Version string = "2.6"
var version string = "(unknown)" // this is set by goreleaser
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not export the version, if this is used as a module in a bigger program?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doing this also loses go install'd versioning. I've recently been using https://github.com/carlmjohnson/versioninfo/ which works for both goreleaser and go install, and should also work when imported as a library

var DisableAccountAliasEnvVarName = "AWS_WHOAMI_DISABLE_ACCOUNT_ALIAS"

type Whoami struct {
Expand Down Expand Up @@ -275,7 +275,7 @@ func main() {
flag.Parse()

if *showVersion {
fmt.Println(Version)
fmt.Println(version)
return
}

Expand Down