chore: add goreleaser

This commit is contained in:
Kevin Franklin Kim 2023-01-04 17:21:41 +01:00
parent e38f94a716
commit 3491c2a095
10 changed files with 79 additions and 14 deletions

25
.github/workflows/release.yml vendored Normal file
View File

@ -0,0 +1,25 @@
name: release
on:
push:
tags:
- v*.*.*
jobs:
release:
runs-on: ubuntu-latest
env:
GOFLAGS: -mod=readonly
GOPROXY: https://proxy.golang.org
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version-file: go.mod
- uses: goreleaser/goreleaser-action@v3
with:
distribution: goreleaser
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.FOOMO_GITHUB_TOKEN }}

3
.gitignore vendored
View File

@ -7,6 +7,7 @@ tmp/
!.posh
!.github
!.gitignore
!.posh.yaml
!.editorconfig
!.goreleaser.yml
!.golangci.yml
!.posh.yml

33
.goreleaser.yml Normal file
View File

@ -0,0 +1,33 @@
# Build customization
builds:
- binary: posh
main: ./main.go
env:
- CGO_ENABLED=0
ldflags:
- -s -w -X internal/version/version.Version={{.Version}}
- -s -w -X internal/version/version.CommitHash={{.FullCommit}}
- -s -w -X internal/version/version.BuildTimestamp={{.Timestamp}}
goos:
- windows
- darwin
- linux
goarch:
- amd64
- arm64
# .goreleaser.yml
archives:
- format: tar.gz
format_overrides:
- goos: windows
format: zip
# Reporitory to push the tap to.
brews:
- tap:
owner: foomo
name: homebrew-foomo
caveats: "posh help"
homepage: "https://github.com/foomo/posh"
description: "Project Oriented SHELL"

View File

@ -20,7 +20,7 @@ $ cd your/project
$ posh init
```
This will generate the standard layout for posh which can be changed as required through `.posh.yaml`.
This will generate the standard layout for posh which can be changed as required through `.posh.yml`.
Once initialized you can start posh through:

View File

@ -5,7 +5,7 @@ import (
"path"
"github.com/foomo/posh/embed"
"github.com/foomo/posh/internal/util"
"github.com/foomo/posh/internal/git"
"github.com/foomo/posh/pkg/env"
"github.com/foomo/posh/pkg/scaffold"
"github.com/spf13/cobra"
@ -28,10 +28,11 @@ Posh init must be run inside of a go module (please run "go mod init <MODNAME> f
data := map[string]interface{}{}
// define module
if gitRemoteURL, err := util.GitRemoteURL(); err == nil {
data["module"] = gitRemoteURL
} else {
if value, err := git.OriginURL(); err != nil {
l.Debug("failed to retrieve git origin url:", err.Error())
data["module"] = path.Base(os.Getenv(env.ProjectRoot))
} else {
data["module"] = value
}
fs, err := embed.Scaffold("init")

View File

@ -60,7 +60,7 @@ func init() {
cobra.OnInitialize(initialize)
rootCmd.PersistentFlags().BoolVar(&flagNoColor, "no-color", false, "disabled colors (default is false)")
rootCmd.PersistentFlags().StringVar(&flagLevel, "level", "info", "set log level (default is warn)")
rootCmd.PersistentFlags().StringVar(&flagConfig, "config", "", "config file (default is $HOME/.posh.yaml)")
rootCmd.PersistentFlags().StringVar(&flagConfig, "config", "", "config file (default is $HOME/.posh.yml)")
}
// initialize reads in config file and ENV variables if set.

View File

@ -1,20 +1,18 @@
package cmd
import (
"fmt"
intversion "github.com/foomo/posh/internal/version"
"github.com/spf13/cobra"
)
const Version = "develop"
// versionCmd represents the version command
var versionCmd = &cobra.Command{
Use: "version",
Short: "Print the version",
Long: `If unsure which version of the CLI you are using, you can use this command to print the version of the CLI.`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println(Version)
l.Debugf("%s (%s)", intversion.CommitHash, intversion.BuildTimestamp)
l.Print(intversion.Version)
},
}

View File

@ -1,4 +1,4 @@
package util
package git
import (
"path"
@ -8,7 +8,7 @@ import (
giturls "github.com/whilp/git-urls"
)
func GitRemoteURL() (string, error) {
func OriginURL() (string, error) {
r, err := git.PlainOpen(".")
if err != nil {
return "", err

View File

@ -0,0 +1,7 @@
package version
var (
Version = "dev"
CommitHash = "n/a"
BuildTimestamp = "n/a"
)