Skip to content

Commit

Permalink
Added release scripts based on goreleaser
Browse files Browse the repository at this point in the history
Signed-off-by: Juraci Paixão Kröhling <juraci@kroehling.de>
  • Loading branch information
jpkrohling committed Oct 14, 2020
1 parent feb5866 commit 8b1d54d
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 4 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: goreleaser

on:
push:
tags:
- 'v*'

jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
-
name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.15
-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
36 changes: 36 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

# Created by https://www.toptal.com/developers/gitignore/api/go,vscode
# Edit at https://www.toptal.com/developers/gitignore?templates=go,vscode

### Go ###
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/

### Go Patch ###
/vendor/
/Godeps/

### vscode ###
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
*.code-workspace

# End of https://www.toptal.com/developers/gitignore/api/go,vscode

/dist/
36 changes: 36 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
before:
hooks:
- go mod download
builds:
- flags:
- -trimpath
ldflags:
- -s -w -X github.com/observatorium/opentelemetry-collector-builder/cmd.version={{.Version}} -X github.com/observatorium/opentelemetry-collector-builder/cmd.date={{.Date}}
env:
- CGO_ENABLED=0
goos:
- linux
- windows
- darwin
goarch:
- amd64
- arm
- arm64
goarm:
- 6
- 7
archives:
- format: binary
replacements:
386: i386
amd64: x86_64
checksum:
name_template: "checksums.txt"
snapshot:
name_template: "{{ .Tag }}-next"
changelog:
sort: asc
filters:
exclude:
- "^docs:"
- "^test:"
15 changes: 12 additions & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package cmd

import (
"fmt"
"strings"

"github.com/spf13/cobra"
Expand All @@ -23,17 +24,23 @@ import (
"github.com/observatorium/opentelemetry-collector-builder/internal/builder"
)

var cfgFile string
var cfg = builder.DefaultConfig()
var (
version = "dev"
date = "unknown"

cfgFile string
cfg = builder.DefaultConfig()
)

// Execute is the main entrypoint for this application
func Execute() {
cobra.OnInitialize(initConfig)

cmd := &cobra.Command{
Use: "opentelemetry-collector-builder",
Long: "OpenTelemetry Collector distribution builder",
Long: fmt.Sprintf("OpenTelemetry Collector distribution builder (%s)", version),
RunE: func(cmd *cobra.Command, args []string) error {

if err := cfg.Validate(); err != nil {
cfg.Logger.Error(err, "invalid configuration: %w", err)
return nil
Expand Down Expand Up @@ -71,6 +78,8 @@ func Execute() {
}

func initConfig() {
cfg.Logger.Info("OpenTelemetry Collector distribution builder", "version", version, "date", date)

// a couple of Viper goodies, to make it easier to use env vars when flags are not desirable
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
viper.AutomaticEnv()
Expand Down
4 changes: 3 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@

package main

import "github.com/observatorium/opentelemetry-collector-builder/cmd"
import (
"github.com/observatorium/opentelemetry-collector-builder/cmd"
)

func main() {
cmd.Execute()
Expand Down

0 comments on commit 8b1d54d

Please sign in to comment.