Skip to content

Commit

Permalink
Restructure configure command under cmd, remove public APIs
Browse files Browse the repository at this point in the history
Signed-off-by: Bogdan Drutu <[email protected]>
  • Loading branch information
bogdandrutu committed Sep 21, 2022
1 parent 8db520d commit 4e835fb
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 1,321 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ build: go ocb
generate: generate-sources generate-goreleaser

generate-goreleaser: go
@${GO} run -tags releaser goreleaser/configure.go -d "${DISTRIBUTIONS}" > .goreleaser.yaml
@cd cmd/goreleaser && ${GO} run main.go -d "${DISTRIBUTIONS}" > .goreleaser.yaml

generate-sources: go ocb
@./scripts/build.sh -d "${DISTRIBUTIONS}" -s true -b ${OTELCOL_BUILDER} -g ${GO}
Expand Down
37 changes: 14 additions & 23 deletions goreleaser/configure.go → cmd/goreleaser/internal/configure.go
Original file line number Diff line number Diff line change
@@ -1,47 +1,38 @@
//go:build releaser
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package main
package internal

// This file is a script which generates the .goreleaser.yaml file for all
// supported OpenTelemetry Collector distributions.
//
// Run it with `make generate-goreleaser`.

import (
"flag"
"fmt"
"log"
"os"
"path"
"strings"

"github.com/goreleaser/goreleaser/pkg/config"
"github.com/goreleaser/nfpm/v2/files"
"gopkg.in/yaml.v2"
)

var (
ImagePrefixes = []string{"otel", "ghcr.io/open-telemetry/opentelemetry-collector-releases"}
Architectures = []string{"386", "amd64", "arm64", "ppc64le"}

distsFlag = flag.String("d", "", "Collector distributions(s) to build, comma-separated")
)

func main() {
flag.Parse()

if len(*distsFlag) == 0 {
log.Fatal("no distributions to build")
}
dists := strings.Split(*distsFlag, ",")

project := Generate(ImagePrefixes, dists)

if err := yaml.NewEncoder(os.Stdout).Encode(&project); err != nil {
log.Fatal(err)
}
}

func Generate(imagePrefixes []string, dists []string) config.Project {
return config.Project{
ProjectName: "opentelemetry-collector-releases",
Expand Down
43 changes: 43 additions & 0 deletions cmd/goreleaser/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package main

import (
"flag"
"log"
"os"
"strings"

"gopkg.in/yaml.v3"

"github.com/open-telemetry/opentelemetry-collector-releases/cmd/goreleaser/internal"
)

var distsFlag = flag.String("d", "", "Collector distributions(s) to build, comma-separated")

func main() {
flag.Parse()

if len(*distsFlag) == 0 {
log.Fatal("no distributions to build")
}
dists := strings.Split(*distsFlag, ",")

project := internal.Generate(internal.ImagePrefixes, dists)

if err := yaml.NewEncoder(os.Stdout).Encode(&project); err != nil {
log.Fatal(err)
}
}
5 changes: 2 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
module github.com/open-telemetry/opentelemetry-collector-releases

go 1.17
go 1.18

require (
github.com/goreleaser/goreleaser v1.11.4
github.com/goreleaser/nfpm/v2 v2.18.1
gopkg.in/yaml.v2 v2.4.0
gopkg.in/yaml.v3 v3.0.1
)

require (
Expand All @@ -25,5 +25,4 @@ require (
github.com/rivo/uniseg v0.4.2 // indirect
golang.org/x/sys v0.0.0-20220909162455-aba9fc2a8ff2 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit 4e835fb

Please sign in to comment.