From 7a98e76374ff082c06b2e0fa6b7672503218b3b3 Mon Sep 17 00:00:00 2001 From: Josh Komoroske Date: Sat, 1 Nov 2025 21:37:50 -0400 Subject: [PATCH] chore: update goreleaser and release workflow --- .github/workflows/build.yaml | 19 ++++++++-- .github/workflows/release.yaml | 34 +++++++++--------- .golangci.yaml | 1 + .goreleaser.yaml | 64 ++++++++++++++++----------------- cmd/command.go | 54 ++++------------------------ cmd/files/examples.txt | 20 +++++++++++ cmd/files/usage-template.tmpl | 5 +++ cmd/files/version-template.tmpl | 12 +++++++ cmd/version.go | 29 +++++++++++++++ go.mod | 2 +- go.sum | 4 +-- 11 files changed, 142 insertions(+), 102 deletions(-) create mode 100644 cmd/files/examples.txt create mode 100644 cmd/files/usage-template.tmpl create mode 100644 cmd/files/version-template.tmpl create mode 100644 cmd/version.go diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index eebe9d0..87d0e0c 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -13,12 +13,25 @@ jobs: steps: - uses: actions/checkout@v5 + with: + fetch-depth: 0 - uses: actions/setup-go@v5 with: go-version-file: go.mod + - uses: goreleaser/goreleaser-action@v6 + with: + # https://github.com/goreleaser/goreleaser/releases/tag/v2.12.7 + version: v2.12.7 + args: build --clean --snapshot + - shell: sh - run: |- - go build -o ./dist/aws-console . - ./dist/aws-console --version + run: ./dist/aws-console_linux_amd64_v1/aws-console --version + + - uses: actions/upload-artifact@v4 + continue-on-error: true + with: + name: artifacts + path: dist/ + retention-days: 1 diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index f9d3778..891ad54 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -1,31 +1,31 @@ -name: Release +name: release + on: push: - branches: - - "!*" tags: - "v*.*.*" jobs: - build: - name: Release - runs-on: ubuntu-22.04 + release: + name: release + runs-on: ubuntu-latest + environment: release + + permissions: + contents: write steps: - - name: Checkout code - uses: actions/checkout@v3 + - uses: actions/checkout@v5 - - name: Setup go - uses: actions/setup-go@v4 + - uses: actions/setup-go@v5 with: - go-version: "1.20" + go-version-file: go.mod - - name: Build and publish release artifacts - uses: goreleaser/goreleaser-action@v2 + - uses: goreleaser/goreleaser-action@v6 with: - # https://github.com/goreleaser/goreleaser/releases/tag/v1.17.2 - version: v1.17.2 - args: release + # https://github.com/goreleaser/goreleaser/releases/tag/v2.12.7 + version: v2.12.7 + args: release --clean env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - HOMEBREW_GITHUB_TOKEN: ${{ secrets.HOMEBREW_GITHUB_TOKEN }} + HOMEBREW_DEPLOY_KEY: ${{ secrets.HOMEBREW_DEPLOY_KEY }} diff --git a/.golangci.yaml b/.golangci.yaml index 3077817..5493244 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -22,6 +22,7 @@ linters: - depguard - err113 - exhaustruct + - gochecknoglobals - lll - noinlineerr - tagliatelle diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 7590210..e7a4daa 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -1,63 +1,63 @@ -project_name: aws-console +version: 2 builds: - - id: aws-console - binary: aws-console + - goos: + - darwin + - linux - targets: - - darwin_amd64 - - darwin_arm64 - - linux_amd64 + goarch: + - amd64 + - arm64 flags: - -buildvcs=false - -trimpath ldflags: - - -s -w + - -X github.com/joshdk/aws-console/cmd.revision={{ .FullCommit }} + - -X github.com/joshdk/aws-console/cmd.timestamp={{ .Date }} + - -X github.com/joshdk/aws-console/cmd.version={{ .Summary }} - -buildid= - - -X jdk.sh/meta.date={{ .Date }} - - -X jdk.sh/meta.sha={{ .Commit }} - - -X jdk.sh/meta.version={{ .Tag }} + - -s + - -w env: - CGO_ENABLED=0 archives: - - id: aws-console + - formats: [tar.gz] name_template: "{{ .ProjectName }}-{{ .Os }}-{{ .Arch }}" release: name_template: "{{ .Tag }} Release" prerelease: auto -checksum: - name_template: "checksums.txt" - changelog: - skip: true + disable: true -brews: - - name: aws-console - - tap: - owner: joshdk - name: homebrew-tap - token: "{{ .Env.HOMEBREW_GITHUB_TOKEN }}" +checksum: + disable: true - url_template: "https://github.com/joshdk/aws-console/releases/download/{{ .Tag }}/{{ .ArtifactName }}" +homebrew_casks: + - description: Generate a temporary login URL for the AWS Console + homepage: https://github.com/joshdk/aws-console + license: MIT - commit_msg_template: "feat: brew formula update for {{ .ProjectName }} {{ .Tag }}" commit_author: name: Josh Komoroske email: jdkomo@gmail.com - folder: Formula + hooks: + post: + install: | + if OS.mac? + system_command "/usr/bin/xattr", args: ["-dr", "com.apple.quarantine", "#{staged_path}/{{ .ProjectName }}"] + end - caveats: "Run aws-console --help for usage" - homepage: "https://github.com/joshdk/aws-console" - description: "Generate a temporary login URL for the AWS Console" - license: "MIT" + repository: + owner: joshdk + name: homebrew-tap - test: | - system "#{bin}/aws-console --version" + git: + url: git@github.com:joshdk/homebrew-tap.git + private_key: "{{ .Env.HOMEBREW_DEPLOY_KEY }}" diff --git a/cmd/command.go b/cmd/command.go index 274afe4..55a3f28 100644 --- a/cmd/command.go +++ b/cmd/command.go @@ -9,13 +9,14 @@ package cmd import ( "fmt" "os" + "strings" "time" "github.com/atotto/clipboard" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/joshdk/buildversion" "github.com/pkg/browser" "github.com/spf13/cobra" - "jdk.sh/meta" "github.com/joshdk/aws-console/console" "github.com/joshdk/aws-console/credentials" @@ -225,58 +226,17 @@ func Command() *cobra.Command { //nolint:cyclop,funlen // Define -A/--user-agent flag. cmd.Flags().StringVarP(&flags.userAgent, "user-agent", "A", - versionFmt("joshdk/aws-console", " %s (%s)", meta.Version(), meta.ShortSHA()), + buildversion.Template("joshdk/aws-console {{ .Version }}{{- if .ShortRevision }} ({{ .ShortRevision }}){{ end }}"), "user agent to use for http requests") - cmd.Example = ` Generate a login url for the default profile: - $ aws-console - - Generate a login url for the "production" profile: - $ aws-console production - - Generate a login url from the output of the aws cli: - $ aws sts assume-role … | aws-console - - - Open url with the default browser: - $ aws-console --browser - - Redirect to IAM service after logging in: - $ aws-console --location iam - - Display a QR code for the login url: - $ aws-console --qr - - Save QR code to a file: - $ aws-console --qr > qr.png` + // Set a custom list of examples. + cmd.Example = strings.TrimRight(exampleText, "\n") // Add a custom usage footer template. - cmd.SetUsageTemplate(cmd.UsageTemplate() + versionFmt( - "\nInfo:\n"+ - " https://github.com/joshdk/aws-console\n", - " %s (%s) built on %v\n", - meta.Version(), meta.ShortSHA(), meta.DateFormat(time.RFC3339), - )) + cmd.SetUsageTemplate(cmd.UsageTemplate() + "\n" + buildversion.Template(usageTemplate)) // Set a custom version template. - cmd.SetVersionTemplate(versionFmt( - "homepage: https://github.com/joshdk/aws-console\n"+ - "author: Josh Komoroske\n"+ - "license: MIT\n", - "version: %s\n"+ - "sha: %s\n"+ - "date: %s\n", - meta.Version(), meta.ShortSHA(), meta.DateFormat(time.RFC3339), - )) + cmd.SetVersionTemplate(buildversion.Template(versionTemplate)) return cmd } - -// versionFmt returns the given literal, as well as a formatted string if -// version metadata is set. -func versionFmt(literal, format string, a ...any) string { - if meta.Version() == "" { - return literal - } - - return literal + fmt.Sprintf(format, a...) -} diff --git a/cmd/files/examples.txt b/cmd/files/examples.txt new file mode 100644 index 000000000..c116079 --- /dev/null +++ b/cmd/files/examples.txt @@ -0,0 +1,20 @@ + Generate a login url for the default profile: + $ aws-console + + Generate a login url for the "production" profile: + $ aws-console production + + Generate a login url from the output of the aws cli: + $ aws sts assume-role … | aws-console - + + Open url with the default browser: + $ aws-console --browser + + Redirect to IAM service after logging in: + $ aws-console --location iam + + Display a QR code for the login url: + $ aws-console --qr + + Save QR code to a file: + $ aws-console --qr > qr.png diff --git a/cmd/files/usage-template.tmpl b/cmd/files/usage-template.tmpl new file mode 100644 index 000000000..75a9453 --- /dev/null +++ b/cmd/files/usage-template.tmpl @@ -0,0 +1,5 @@ +Info: + https://{{ .Path }} + {{ .Version }} + {{- if .ShortRevision }} ({{ .ShortRevision }}){{ end }} + {{- if .Timestamp }} built on {{ .Timestamp }}{{ end }} diff --git a/cmd/files/version-template.tmpl b/cmd/files/version-template.tmpl new file mode 100644 index 000000000..f69bc99 --- /dev/null +++ b/cmd/files/version-template.tmpl @@ -0,0 +1,12 @@ +homepage: https://{{ .Path }} +author: Josh Komoroske +license: MIT +version: {{ .Version }} +{{ if .ShortRevision -}} +revision: {{ .ShortRevision }} +{{ end -}} +{{ if .Timestamp -}} +date: {{ .Timestamp }} +{{ end -}} +platform: {{ .OS }}/{{ .Arch}} +runtime: {{ .Runtime }} diff --git a/cmd/version.go b/cmd/version.go new file mode 100644 index 000000000..3e95ac8 --- /dev/null +++ b/cmd/version.go @@ -0,0 +1,29 @@ +// Copyright Josh Komoroske. All rights reserved. +// Use of this source code is governed by the MIT license, +// a copy of which can be found in the LICENSE.txt file. +// SPDX-License-Identifier: MIT + +package cmd + +import ( + _ "embed" + + "github.com/joshdk/buildversion" +) + +var ( + version string + revision string + timestamp string + + _ = buildversion.Override(version, revision, timestamp) + + //go:embed files/usage-template.tmpl + usageTemplate string + + //go:embed files/version-template.tmpl + versionTemplate string + + //go:embed files/examples.txt + exampleText string +) diff --git a/go.mod b/go.mod index a48e44b..775e903 100644 --- a/go.mod +++ b/go.mod @@ -8,12 +8,12 @@ require ( github.com/aws/aws-sdk-go-v2/config v1.31.16 github.com/aws/aws-sdk-go-v2/credentials v1.18.20 github.com/aws/aws-sdk-go-v2/service/sts v1.39.0 + github.com/joshdk/buildversion v0.1.0 github.com/mattn/go-isatty v0.0.20 github.com/mattn/go-sixel v0.0.5 github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e github.com/spf13/cobra v1.10.1 - jdk.sh/meta v0.1.1-0.20211021015548-cff3b930ebd9 ) require ( diff --git a/go.sum b/go.sum index de57cb2..a269318 100644 --- a/go.sum +++ b/go.sum @@ -29,6 +29,8 @@ github.com/aws/smithy-go v1.23.1/go.mod h1:LEj2LM3rBRQJxPZTB4KuzZkaZYnZPnvgIhb4p github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= +github.com/joshdk/buildversion v0.1.0 h1:AeCFYqV2zZI6Q5pUDNi9YzX15Kmm7UnHKsC8yN2YIsk= +github.com/joshdk/buildversion v0.1.0/go.mod h1:M/dUoVcv7TeUJ72r8NdyccLHO/7aaKUT8CdKOSb6FfU= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-sixel v0.0.5 h1:55w2FR5ncuhKhXrM5ly1eiqMQfZsnAHIpYNGZX03Cv8= @@ -51,5 +53,3 @@ golang.org/x/sys v0.37.0 h1:fdNQudmxPjkdUTPnLn5mdQv7Zwvbvpaxqs831goi9kQ= golang.org/x/sys v0.37.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -jdk.sh/meta v0.1.1-0.20211021015548-cff3b930ebd9 h1:f9CEE/IWIjsG3jBxNc/rfJ17031Oe7ghTWkPg6JJ6Bo= -jdk.sh/meta v0.1.1-0.20211021015548-cff3b930ebd9/go.mod h1:c2+wWgMZejSQ2nXsbxNVKLLQgTLY4yrX7TH6NIaQle0=