Skip to content
Merged
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
19 changes: 16 additions & 3 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
34 changes: 17 additions & 17 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
1 change: 1 addition & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ linters:
- depguard
- err113
- exhaustruct
- gochecknoglobals
- lll
- noinlineerr
- tagliatelle
Expand Down
64 changes: 32 additions & 32 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -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 }}"
54 changes: 7 additions & 47 deletions cmd/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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...)
}
20 changes: 20 additions & 0 deletions cmd/files/examples.txt
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions cmd/files/usage-template.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Info:
https://{{ .Path }}
{{ .Version }}
{{- if .ShortRevision }} ({{ .ShortRevision }}){{ end }}
{{- if .Timestamp }} built on {{ .Timestamp }}{{ end }}
12 changes: 12 additions & 0 deletions cmd/files/version-template.tmpl
Original file line number Diff line number Diff line change
@@ -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 }}
29 changes: 29 additions & 0 deletions cmd/version.go
Original file line number Diff line number Diff line change
@@ -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
)
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand All @@ -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=