-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build the cli and package it with goreleaser (#168)
- Loading branch information
1 parent
6ae49db
commit 3b19f05
Showing
11 changed files
with
354 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
name: release | ||
|
||
on: | ||
push: | ||
tags: | ||
- '*' | ||
jobs: | ||
goreleaser: | ||
runs-on: ubuntu-latest | ||
steps: | ||
|
||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v3 | ||
with: | ||
go-version: '>=1.19.2' | ||
cache: true | ||
|
||
- name: Run GoReleaser | ||
uses: goreleaser/goreleaser-action@v3 | ||
with: | ||
distribution: goreleaser | ||
version: latest | ||
args: release --rm-dist | ||
workdir: go-starknet | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
HOMEBREW_TOKEN: ${{ secrets.HOMEBREW_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
name: Go | ||
name: test | ||
|
||
on: | ||
push: | ||
branches: | ||
- '**' | ||
tags-ignore: | ||
- '**' | ||
schedule: | ||
- cron: "42 2 * * *" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
dist/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
project_name: go-starknet | ||
# This is an example .goreleaser.yml file with some sensible defaults. | ||
# Make sure to check the documentation at https://goreleaser.com | ||
before: | ||
hooks: | ||
# You may remove this if you don't use go modules. | ||
- go mod tidy | ||
# you may remove this if you don't need go generate | ||
- go generate ./... | ||
builds: | ||
- env: | ||
- CGO_ENABLED=0 | ||
goos: | ||
- linux | ||
- darwin | ||
archives: | ||
- replacements: | ||
darwin: darwin | ||
linux: linux | ||
windows: windows | ||
386: i386 | ||
amd64: x86_64 | ||
brews: | ||
- name: go-starknet | ||
homepage: "https://github.com/dontpanicdao/caigo" | ||
tap: | ||
owner: dontpanicdao | ||
name: homebrew-dontpanicdao | ||
token: "{{ .Env.HOMEBREW_TOKEN }}" | ||
commit_author: | ||
name: gregoryguillou | ||
email: [email protected] | ||
|
||
checksum: | ||
name_template: 'checksums.txt' | ||
snapshot: | ||
name_template: "{{ incpatch .Version }}-next" | ||
changelog: | ||
sort: asc | ||
filters: | ||
exclude: | ||
- '^docs:' | ||
- '^test:' | ||
|
||
# modelines, 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# go-starknet | ||
|
||
`go-starknet` is a CLI written in Go for Starknet. To install it, you can | ||
simply: | ||
|
||
## if you have Go 1.18+ installed | ||
|
||
```shell | ||
cd | ||
go install github.com/dontpanicdao/caigo/go-starknet@latest | ||
go-starknet help | ||
``` | ||
|
||
## on MacOS with Homebrew | ||
|
||
```shell | ||
cd | ||
brew tap dontpanicdao/dontpanicdao | ||
brew install go-starknet | ||
go-starknet help | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"errors" | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
|
||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
const profileDirectory = ".go-starknet" | ||
const profileFilename = "profile.json" | ||
|
||
type Profile struct { | ||
DefaultFormat string `json:"defaultFormat,omitempty"` | ||
} | ||
|
||
var profileCommand = cli.Command{ | ||
Name: "profile", | ||
Aliases: []string{"p"}, | ||
Usage: "manage the user profile", | ||
Subcommands: []*cli.Command{ | ||
{ | ||
Name: "list", | ||
Usage: "go-starknet profile list", | ||
Action: profileList, | ||
}, | ||
{ | ||
Name: "set", | ||
Usage: "go-starknet profile set name=value", | ||
Action: profileSet, | ||
}, | ||
}, | ||
} | ||
|
||
func initOrLoadProfile() (*Profile, error) { | ||
home, err := os.UserHomeDir() | ||
if err != nil { | ||
return nil, err | ||
} | ||
profileFullDirectory := filepath.Join(home, profileDirectory) | ||
v, err := os.Stat(profileFullDirectory) | ||
if err != nil && errors.Is(err, os.ErrNotExist) { | ||
err = os.MkdirAll(profileFullDirectory, 0755) | ||
if err != nil { | ||
return nil, err | ||
} | ||
v, err = os.Stat(profileFullDirectory) | ||
} | ||
if err != nil { | ||
return nil, err | ||
} | ||
if !v.IsDir() { | ||
return nil, fmt.Errorf("%s not directory", v.Name()) | ||
} | ||
profileFullFilename := filepath.Join(profileFullDirectory, profileFilename) | ||
content, err := os.ReadFile(profileFullFilename) | ||
p := Profile{} | ||
if err != nil && errors.Is(err, os.ErrNotExist) { | ||
content, err = json.MarshalIndent(p, " ", " ") | ||
if err != nil { | ||
return nil, err | ||
} | ||
err = os.WriteFile(profileFullFilename, content, 0755) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &p, nil | ||
} | ||
if err != nil { | ||
return nil, err | ||
} | ||
err = json.Unmarshal(content, &p) | ||
return &p, err | ||
} | ||
|
||
func (p Profile) save() error { | ||
home, err := os.UserHomeDir() | ||
if err != nil { | ||
return err | ||
} | ||
profileFullFilename := filepath.Join(home, profileDirectory, profileFilename) | ||
content, err := json.MarshalIndent(p, " ", " ") | ||
if err != nil { | ||
return err | ||
} | ||
return os.WriteFile(profileFullFilename, content, 0755) | ||
} | ||
|
||
func or(a string, b string) string { | ||
if a != "" { | ||
return a | ||
} | ||
return b | ||
} | ||
|
||
func profileList(cCtx *cli.Context) error { | ||
p, err := initOrLoadProfile() | ||
if err != nil { | ||
return err | ||
} | ||
fmt.Printf("profile\n") | ||
fmt.Printf(" format: %s\n", or(p.DefaultFormat, "friendly")) | ||
return nil | ||
} | ||
|
||
func profileSet(cCtx *cli.Context) error { | ||
p, err := initOrLoadProfile() | ||
if err != nil { | ||
return err | ||
} | ||
values := cCtx.Args() | ||
if len(values.Slice()) != 1 { | ||
fmt.Printf("define a value %+v\n", values) | ||
os.Exit(1) | ||
} | ||
changed := false | ||
k, v, ok := strings.Cut(values.First(), "=") | ||
if ok && strings.ToLower(k) == "format" { | ||
p.DefaultFormat = v | ||
changed = true | ||
} | ||
if changed { | ||
p.save() | ||
} | ||
return nil | ||
} |
Oops, something went wrong.