Skip to content

Commit

Permalink
update ci
Browse files Browse the repository at this point in the history
  • Loading branch information
pjaudiomv committed Sep 22, 2023
1 parent f068e04 commit edff9b2
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 13 deletions.
11 changes: 5 additions & 6 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ on:

jobs:
lint-go:
runs-on: ubuntu-18.04
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
stable: 'false'
go-version: '1.18.2'
go-version: '1.19'
- name: Lint
run: |
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.42.1
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.54.2
golangci-lint run main.go
40 changes: 40 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: 'release'

on:
push:
tags: [ '*' ]

jobs:
lint-go:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version: '1.19'
- name: Lint
run: |
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.54.2
golangci-lint run main.go
release:
runs-on: ubuntu-22.04
needs: [ lint ]
steps:
- name: Check out code 🛒
uses: actions/checkout@v4

- name: Generate Release Notes 📝
if: github.ref_type == 'tag'
run: |
CHANGE=$(sed "/${GITHUB_REF_NAME%%-*}/,/##/!d;//d" CHANGELOG.md | awk 'NF')
echo "$CHANGE" > changelog.txt
RELEASE_TYPE=$(if [[ "$GITHUB_REF_NAME" =~ "beta" ]]; then echo "true"; else echo "false"; fi)
echo "RELEASE_TYPE=${RELEASE_TYPE}" >> $GITHUB_ENV
- name: Create Release 🎉
uses: ncipollo/release-action@v1.13.0
if: github.ref_type == 'tag'
with:
bodyFile: "changelog.txt"
prerelease: ${{ env.RELEASE_TYPE }}
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## 0.0.2 (May 27, 2022)
## v0.0.3 (September 22, 2023)
* Added additional error checking.

## v0.0.2 (May 27, 2022)
* Added ability to search AWS profiles. [#589] thanks @M1kep

## 0.0.1 (November 30, 2021)
## v0.0.1 (November 30, 2021)
* Initial Release
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module github.com/pjaudiomv/awsd

go 1.18
go 1.19

require github.com/manifoldco/promptui v0.9.0

require (
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e // indirect
golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b // indirect
github.com/chzyer/readline v1.5.1 // indirect
golang.org/x/sys v0.12.0 // indirect
)
9 changes: 9 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
github.com/chzyer/logex v1.1.10 h1:Swpa1K6QvQznwJRcfTfQJmTE72DqScAa40E+fbHEXEE=
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
github.com/chzyer/logex v1.2.1 h1:XHDu3E6q+gdHgsdTPH6ImJMIp436vR6MPtH8gP05QzM=
github.com/chzyer/logex v1.2.1/go.mod h1:JLbx6lG2kDbNRFnfkgvh4eRJRPX1QCoOIWomwysCBrQ=
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e h1:fY5BOSpyZCqRo5OhCuC+XN+r/bBCmeuuJtjz+bCNIf8=
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
github.com/chzyer/readline v1.5.1 h1:upd/6fQk4src78LMRzh5vItIt361/o4uq553V8B5sGI=
github.com/chzyer/readline v1.5.1/go.mod h1:Eh+b79XXUwfKfcPLepksvw2tcLE/Ct21YObkaSkeBlk=
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1 h1:q763qf9huN11kDQavWsoZXJNW3xEE4JJyHa5Q25/sd8=
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
github.com/chzyer/test v1.0.0 h1:p3BQDXSxOhOG0P9z6/hGnII4LGiEPOYBhs8asl/fC04=
github.com/chzyer/test v1.0.0/go.mod h1:2JlltgoNkt4TW/z9V/IzDdFaMTM2JPIi26O1pF38GC8=
github.com/manifoldco/promptui v0.9.0 h1:3V4HzJk1TtXW1MTZMP7mdlwbBpIinw3HztaIlYthEiA=
github.com/manifoldco/promptui v0.9.0/go.mod h1:ka04sppxSGFAtxX0qhlYQjISsg9mR4GWtQEhdbn6Pgg=
golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b h1:MQE+LT/ABUuuvEZ+YQAMSXindAdUh7slEmAkup74op4=
golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
24 changes: 22 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const (
CyanColor = "\033[0;36m%s\033[0m"
)

var version string = "v0.0.2"
var version string = "v0.0.3"

func newPromptUISearcher(items []string) list.Searcher {
return func(searchInput string, itemIndex int) bool {
Expand All @@ -34,6 +34,7 @@ func main() {
home := os.Getenv("HOME")
profileFileLocation := getenv("AWS_CONFIG_FILE", fmt.Sprintf("%s/.aws/config", home))
profiles := getProfiles(profileFileLocation)
touchFile(fmt.Sprintf("%s/.awsd", home))

fmt.Printf(NoticeColor, "AWS Profile Switcher\n")
prompt := promptui.Select{
Expand All @@ -55,7 +56,7 @@ func main() {
_, result, err := prompt.Run()

if err != nil {
fmt.Printf("Prompt failed %v\n", err)
checkError(err)
return
}
fmt.Printf(PromptColor, "Choose a profile")
Expand All @@ -65,6 +66,14 @@ func main() {
writeFile(result, home)
}

func touchFile(name string) error {
file, err := os.OpenFile(name, os.O_RDONLY|os.O_CREATE, 0644)
if err != nil {
return err
}
return file.Close()
}

func writeFile(profile, loc string) {
s := []byte("")
if profile != "default" {
Expand Down Expand Up @@ -118,6 +127,17 @@ func getenv(key, fallback string) string {
return value
}

func checkError(err error) {
if err.Error() == "^D" {
// https://github.com/manifoldco/promptui/issues/179
log.Fatalf("<Del> not supported")
} else if err.Error() == "^C" {
os.Exit(1)
} else {
log.Fatal(err)
}
}

type bellSkipper struct{}

func (bs *bellSkipper) Write(b []byte) (int, error) {
Expand Down

0 comments on commit edff9b2

Please sign in to comment.