Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tpl approach for plugin GoReleaser config #1165

Merged
merged 1 commit into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .github/workflows/pr-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,19 @@ jobs:
echo '✔ No issues detected. Have a nice day :-)'
fi

- name: Run generating Plugin GoReleaser file
run: make gen-plugins-goreleaser

- name: Detect git changes
run: |
if [[ $(git diff --stat) != '' ]]; then
echo -e '❌ \033[0;31mGenerated GoReleaser file is outdated. Run 'make gen-plugins-goreleaser'.\033[0m'
git diff --color
exit 1
else
echo '✔ No issues detected. Have a nice day :-)'
fi

integration-tests:
name: Integration tests
runs-on: ubuntu-latest
Expand Down
29 changes: 29 additions & 0 deletions .goreleaser.plugin.tpl.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# GoReleaser already creates Botkube artifacts in the ./dist folder.
# To not override them during release, we use a different folder
dist: plugin-dist

before:
hooks:
- go mod download

builds:
<range .>
- id: <.Name>
main: cmd/<.Type>/<.Name>/main.go
binary: <.Type>_<.Name>_{{ .Os }}_{{ .Arch }}

no_unique_dist_dir: true
env:
- CGO_ENABLED=0
goos:
- linux
- darwin
goarch:
- amd64
- arm64
goarm:
- 7
<end>

snapshot:
name_template: 'v{{ .Version }}'
187 changes: 122 additions & 65 deletions .goreleaser.plugin.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# The code has been automatically generated and should not be modified directly. To update, run 'make gen-plugins-goreleaser' from the root directory of this repository.

# GoReleaser already creates Botkube artifacts in the ./dist folder.
# To not override them during release, we use a different folder
dist: plugin-dist
Expand All @@ -7,112 +9,167 @@ before:
- go mod download

builds:

- id: doctor
main: cmd/executor/doctor/main.go
binary: executor_doctor_{{ .Os }}_{{ .Arch }}

no_unique_dist_dir: true
env:
- CGO_ENABLED=0
goos:
- linux
- darwin
goarch:
- amd64
- arm64
goarm:
- 7

- id: echo
main: cmd/executor/echo/main.go
binary: executor_echo_{{ .Os }}_{{ .Arch }}

no_unique_dist_dir: true
env: &env
env:
- CGO_ENABLED=0
goos: &goos
goos:
- linux
- darwin
goarch: &goarch
goarch:
- amd64
- arm64
goarm: &goarm
goarm:
- 7

- id: helm
main: cmd/executor/helm/main.go
binary: executor_helm_{{ .Os }}_{{ .Arch }}

no_unique_dist_dir: true
env: *env
goos: *goos
goarch: *goarch
goarm: *goarm


- id: exec
main: cmd/executor/exec/main.go
binary: executor_exec_{{ .Os }}_{{ .Arch }}

no_unique_dist_dir: true
env: *env
goos: *goos
goarch: *goarch
goarm: *goarm

env:
- CGO_ENABLED=0
goos:
- linux
- darwin
goarch:
- amd64
- arm64
goarm:
- 7

- id: gh
main: cmd/executor/gh/main.go
binary: executor_gh_{{ .Os }}_{{ .Arch }}

no_unique_dist_dir: true
env: *env
goos: *goos
goarch: *goarch
goarm: *goarm

env:
- CGO_ENABLED=0
goos:
- linux
- darwin
goarch:
- amd64
- arm64
goarm:
- 7

- id: helm
main: cmd/executor/helm/main.go
binary: executor_helm_{{ .Os }}_{{ .Arch }}

no_unique_dist_dir: true
env:
- CGO_ENABLED=0
goos:
- linux
- darwin
goarch:
- amd64
- arm64
goarm:
- 7

- id: kubectl
main: cmd/executor/kubectl/main.go
binary: executor_kubectl_{{ .Os }}_{{ .Arch }}

no_unique_dist_dir: true
env: *env
goos: *goos
goarch: *goarch
goarm: *goarm

- id: doctor
main: cmd/executor/doctor/main.go
binary: executor_doctor_{{ .Os }}_{{ .Arch }}

no_unique_dist_dir: true
env: *env
goos: *goos
goarch: *goarch
goarm: *goarm

env:
- CGO_ENABLED=0
goos:
- linux
- darwin
goarch:
- amd64
- arm64
goarm:
- 7

- id: cm-watcher
main: cmd/source/cm-watcher/main.go
binary: source_cm-watcher_{{ .Os }}_{{ .Arch }}

no_unique_dist_dir: true
env: *env
goos: *goos
goarch: *goarch
goarm: *goarm

- id: prometheus
main: cmd/source/prometheus/main.go
binary: source_prometheus_{{ .Os }}_{{ .Arch }}
env:
- CGO_ENABLED=0
goos:
- linux
- darwin
goarch:
- amd64
- arm64
goarm:
- 7

- id: keptn
main: cmd/source/keptn/main.go
binary: source_keptn_{{ .Os }}_{{ .Arch }}

no_unique_dist_dir: true
env: *env
goos: *goos
goarch: *goarch
goarm: *goarm

env:
- CGO_ENABLED=0
goos:
- linux
- darwin
goarch:
- amd64
- arm64
goarm:
- 7

- id: kubernetes
main: cmd/source/kubernetes/main.go
binary: source_kubernetes_{{ .Os }}_{{ .Arch }}

no_unique_dist_dir: true
env: *env
goos: *goos
goarch: *goarch
goarm: *goarm

- id: keptn
main: cmd/source/keptn/main.go
binary: source_keptn_{{ .Os }}_{{ .Arch }}
env:
- CGO_ENABLED=0
goos:
- linux
- darwin
goarch:
- amd64
- arm64
goarm:
- 7

- id: prometheus
main: cmd/source/prometheus/main.go
binary: source_prometheus_{{ .Os }}_{{ .Arch }}

no_unique_dist_dir: true
env: *env
goos: *goos
goarch: *goarch
goarm: *goarm
env:
- CGO_ENABLED=0
goos:
- linux
- darwin
goarch:
- amd64
- arm64
goarm:
- 7


snapshot:
name_template: 'v{{ .Version }}'
10 changes: 6 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.DEFAULT_GOAL := build
.PHONY: container-image test test-integration-slack test-integration-discord build pre-build publish lint lint-fix go-import-fmt system-check save-images load-and-push-images gen-grpc-resources gen-plugins-index build-plugins build-plugins-single
.PHONY: container-image test test-integration-slack test-integration-discord build pre-build publish lint lint-fix go-import-fmt system-check save-images load-and-push-images gen-grpc-resources gen-plugins-index build-plugins build-plugins-single gen-docs-cli gen-plugins-goreleaser

# Show this help.
help:
Expand Down Expand Up @@ -32,13 +32,13 @@ build: pre-build
@echo "Build completed successfully"

# Build Botkube official plugins for all supported platforms.
build-plugins: pre-build
build-plugins: pre-build gen-plugins-goreleaser
@echo "Building plugins binaries"
@./hack/goreleaser.sh build_plugins
@echo "Build completed successfully"

# Build Botkube official plugins only for current GOOS and GOARCH.
build-plugins-single: pre-build
build-plugins-single: pre-build gen-plugins-goreleaser
@echo "Building single target plugins binaries"
@./hack/goreleaser.sh build_plugins_single
@echo "Build completed successfully"
Expand Down Expand Up @@ -94,7 +94,9 @@ gen-plugins-index: build-plugins
gen-docs-cli:
rm -f ./cmd/cli/docs/*
go run -ldflags="-X go.szostok.io/version.name=botkube" cmd/cli/main.go gen-usage-docs
.PHONY: gen-docs-cli

gen-plugins-goreleaser:
go run ./hack/target/gen-goreleaser/main.go

# Pre-build checks
pre-build: system-check
Expand Down
16 changes: 5 additions & 11 deletions hack/gen-plugin-index.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package main

import (
"flag"
"log"
"os"
"path/filepath"

"github.com/sirupsen/logrus"
"gopkg.in/yaml.v3"

"github.com/kubeshop/botkube/internal/loggerx"
"github.com/kubeshop/botkube/internal/plugin"
)

Expand All @@ -28,7 +28,7 @@ func main() {
idxBuilder := plugin.NewIndexBuilder(logger)

absBinsDir, err := filepath.Abs(*binsDir)
exitOnError("while resolving an absolute path of binaries folder", err)
loggerx.ExitOnError(err, "while resolving an absolute path of binaries folder")

log := logger.WithFields(logrus.Fields{
"binDir": absBinsDir,
Expand All @@ -38,18 +38,12 @@ func main() {

log.Info("Building index..")
idx, err := idxBuilder.Build(absBinsDir, *urlBasePath, *pluginNameFilter, false)
exitOnError("while building plugin index", err)
loggerx.ExitOnError(err, "while building plugin index")

raw, err := yaml.Marshal(idx)
exitOnError("while marshaling index into YAML format", err)
loggerx.ExitOnError(err, "while marshaling index into YAML format")

logger.WithField("output", *output).Info("Saving index file...")
err = os.WriteFile(*output, raw, filePerm)
exitOnError("while saving index file", err)
}

func exitOnError(context string, err error) {
if err != nil {
log.Fatalf("%s: %s", context, err)
}
loggerx.ExitOnError(err, "while saving index file")
}
Loading
Loading