Skip to content

Commit

Permalink
set version at build
Browse files Browse the repository at this point in the history
  • Loading branch information
dhollinger committed Oct 8, 2022
1 parent 3f83c2a commit 0fb3b78
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ archives:
format: zip
builds:
- id: webhook-go
ldflags: -s -w -X 'github.com/voxpupuli/webhook-go/cmd.version={{.Version}}'
env:
- CGO_ENABLED=0
goos:
Expand All @@ -30,7 +31,7 @@ release:
owner: voxpupuli
name: webhook-go
name_template: "Release v{{.Version}}"
prerelease: false
prerelease: auto
checksum:
name_template: 'checksums.txt'
snapshot:
Expand Down
43 changes: 43 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package cmd

import (
"fmt"
"os"

"github.com/spf13/cobra"
"github.com/voxpupuli/webhook-go/config"
)

var cfgFile string

var version = "0.0.0"

var rootCmd = &cobra.Command{
Use: "webhook-go",
Version: version,
Short: "API Server for providing r10k/g10k as a web service",
Long: `Provides an API service that parses git-based webhook
requests, executing r10k deployments based on the payload and
API endpoint.`,
}

func Execute() {
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
}

func init() {
cobra.OnInitialize(initConfig)

rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is ./webhook.yml)")
}

func initConfig() {
if cfgFile != "" {
config.Init(&cfgFile)
} else {
config.Init(nil)
}
}
36 changes: 36 additions & 0 deletions cmd/server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
Copyright © 2022 NAME HERE <EMAIL ADDRESS>
*/
package cmd

import (
"github.com/spf13/cobra"
"github.com/voxpupuli/webhook-go/server"
)

// serverCmd represents the server command
var serverCmd = &cobra.Command{
Use: "server",
Short: "Start the Webhook-go server",
Long: ``,
Run: startServer,
}

func init() {
rootCmd.AddCommand(serverCmd)

// Here you will define your flags and configuration settings.

// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// serverCmd.PersistentFlags().String("foo", "", "A help for foo")

// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// serverCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}

func startServer(cmd *cobra.Command, args []string) {
server.Init()
}

0 comments on commit 0fb3b78

Please sign in to comment.