From 483a48367a1555c007f9eea2d233366078d3597a Mon Sep 17 00:00:00 2001 From: Pawel Kosiec Date: Thu, 8 Feb 2024 11:36:02 +0100 Subject: [PATCH] Initialize repository with Readme, CI pipelines and others (#2) --- .github/CODEOWNERS | 4 + .github/ISSUE_TEMPLATE/bug_report.md | 28 +++ .github/ISSUE_TEMPLATE/feature_request.md | 22 +++ .github/PULL_REQUEST_TEMPLATE.md | 17 ++ .github/workflows/branch-pr-build.yml | 140 ++++++++++++++ .github/workflows/release.yml | 31 +++ .github/workflows/tag-build.yml | 61 ++++++ .gitignore | 19 ++ .golangci.yml | 41 ++++ .goreleaser.plugin.tpl.yaml | 34 ++++ .goreleaser.plugin.yaml | 223 ++++++++++++++++++++++ Makefile | 48 +++++ README.md | 26 +++ tools.go | 8 + 14 files changed, 702 insertions(+) create mode 100644 .github/CODEOWNERS create mode 100644 .github/ISSUE_TEMPLATE/bug_report.md create mode 100644 .github/ISSUE_TEMPLATE/feature_request.md create mode 100644 .github/PULL_REQUEST_TEMPLATE.md create mode 100644 .github/workflows/branch-pr-build.yml create mode 100644 .github/workflows/release.yml create mode 100644 .github/workflows/tag-build.yml create mode 100644 .gitignore create mode 100644 .golangci.yml create mode 100644 .goreleaser.plugin.tpl.yaml create mode 100644 .goreleaser.plugin.yaml create mode 100644 Makefile create mode 100644 README.md create mode 100644 tools.go diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 00000000..d354ef87 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1,4 @@ +# Botkube maintainers (email: dev-team@botkube.io) +# Maintainers are listed alphabetically + +* @kubeshop/botkube-dev diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 00000000..00e22521 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,28 @@ +--- +name: Bug +about: Report a bug in the project +labels: bug +--- + + + +## Description + + + +## Expected behavior + + + +## Actual behavior + + + +## Steps to reproduce + + diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 00000000..4139fd13 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,22 @@ +--- +name: Feature request +about: Suggest how we can improve +labels: enhancement +--- + + + +## Overview + + + +## Acceptance Criteria + + + +## Reason + + diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 00000000..8a3b780e --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,17 @@ + + +## Description + +Changes proposed in this pull request: + +- ... + +## Related issue(s) + + diff --git a/.github/workflows/branch-pr-build.yml b/.github/workflows/branch-pr-build.yml new file mode 100644 index 00000000..ea321bc5 --- /dev/null +++ b/.github/workflows/branch-pr-build.yml @@ -0,0 +1,140 @@ +name: Branch and PR build +on: + push: + branches: + - main + pull_request: + branches: + - main + +concurrency: + group: ${{ github.workflow }}-${{ github.ref_name }}-${{ github.event.pull_request.number || 'branch' }} # scope to for the current workflow + cancel-in-progress: ${{ github.event_name == 'pull_request' }} # cancel only PR related jobs + +env: + GOLANGCI_LINT_TIMEOUT: 5m + GORELEASER_CURRENT_TAG: "v0.0.0-latest" + BUCKET_NAME: botkube-cloud-plugins-latest + +jobs: + lint: + name: Lint code + runs-on: ubuntu-latest + steps: + - name: "Checkout code" + uses: actions/checkout@v4 + + - name: "Set up Go" + uses: actions/setup-go@v5 + with: + go-version-file: 'go.mod' + # When the files to be extracted are already present, + # tar extraction in Golangci Lint fails with the "File exists" + # errors. These files appear to be present because of + # cache in setup-go, on disabling the cache we are no more seeing + # such error. Cache is to be enabled once the fix is available for + # this issue: + # https://github.com/golangci/golangci-lint-action/issues/807 + cache: false + + - name: "Check code quality" + uses: golangci/golangci-lint-action@v3 + with: + args: --timeout=${{ env.GOLANGCI_LINT_TIMEOUT }} + + test: + name: Test code + runs-on: ubuntu-latest + steps: + - name: "Checkout code" + uses: actions/checkout@v4 + + - name: "Set up Go" + uses: actions/setup-go@v5 + with: + go-version-file: 'go.mod' + cache: 'true' + + - name: "Run tests" + run: make test + + build-plugins: + name: Build plugins without publish + runs-on: ubuntu-latest + if: github.event_name == 'pull_request' + needs: [lint, test] + steps: + - name: "Checkout code" + uses: actions/checkout@v4 + + - name: "Set up Go" + uses: actions/setup-go@v5 + with: + go-version-file: 'go.mod' + cache: true + + - name: Install GoReleaser + uses: goreleaser/goreleaser-action@v5 + with: + install-only: true + version: latest + + - name: Build plugins and generate plugins index.yaml + env: + PLUGIN_DOWNLOAD_URL_BASE_PATH: "" + run: | + make build-plugins-archives + USE_ARCHIVE=true make gen-plugin-index + + release-latest-plugins: + if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main' + name: Build and release latest plugins + runs-on: ubuntu-latest + needs: [lint, test] + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: GCP auth + uses: 'google-github-actions/auth@v2' + with: + credentials_json: ${{ secrets.CLOUD_PLUGINS_LATEST_BUCKET_CREDS }} + + - name: 'Set up Cloud SDK' + uses: 'google-github-actions/setup-gcloud@v2' + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version-file: 'go.mod' + cache: true + + - name: Install GoReleaser + uses: goreleaser/goreleaser-action@v5 + with: + install-only: true + version: latest + + - name: Build plugins and generate plugins index.yaml + env: + PLUGIN_DOWNLOAD_URL_BASE_PATH: "" + run: | + make build-plugins-archives + USE_ARCHIVE=true make gen-plugin-index + + - name: Upload plugins to GCS + uses: google-github-actions/upload-cloud-storage@v2 + with: + path: 'dist' + destination: '${{ env.BUCKET_NAME }}/' + glob: '*.tar.gz' + parent: false + + - name: Upload plugin index to GCS + uses: google-github-actions/upload-cloud-storage@v2 + with: + path: 'plugins-index.yaml' + destination: '${{ env.BUCKET_NAME }}/' + + - name: 'Disable GCS caching' + run: 'gsutil -m setmeta -h "Cache-Control: no-cache, no-store" gs://${{ env.BUCKET_NAME }}/*' diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..6017ea9c --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,31 @@ +name: Trigger release + +on: + workflow_dispatch: + inputs: + version: + type: string + description: Version of the next release (e.g. v1.10.0) + required: true + +permissions: + contents: write + +jobs: + trigger-relase: + name: Trigger release + runs-on: ubuntu-latest + steps: + - name: Create tag + uses: actions/github-script@v7 + with: + # Unfortunately PAT is required to create a tag and in that way trigger other workflow. + # Read more here: https://docs.github.com/en/actions/using-workflows/triggering-a-workflow#triggering-a-workflow-from-a-workflow + github-token: ${{ secrets.RELEASE_GH_DEV_ACCOUNT_PAT }} + script: | + github.rest.git.createRef({ + owner: context.repo.owner, + repo: context.repo.repo, + ref: 'refs/tags/${{ inputs.version }}', + sha: context.sha + }) diff --git a/.github/workflows/tag-build.yml b/.github/workflows/tag-build.yml new file mode 100644 index 00000000..181cb2bb --- /dev/null +++ b/.github/workflows/tag-build.yml @@ -0,0 +1,61 @@ +name: Tag build + +on: + push: + tags: + - '*' + +env: + BUCKET_NAME: botkube-cloud-plugins + VERSION: "${{ github.ref_name }}" + +jobs: + release: + name: Release plugins + runs-on: ubuntu-latest + if: startsWith(github.ref, 'refs/tags/v') + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: GCP auth + uses: 'google-github-actions/auth@v2' + with: + credentials_json: ${{ secrets.CLOUD_PLUGINS_BUCKET_CREDS }} + + - name: 'Set up Cloud SDK' + uses: 'google-github-actions/setup-gcloud@v2' + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version-file: 'go.mod' + cache: true + + - name: Install GoReleaser + uses: goreleaser/goreleaser-action@v5 + with: + install-only: true + version: latest + + - name: Build plugins and generate plugins index.yaml + env: + PLUGIN_DOWNLOAD_URL_BASE_PATH: "${{ env.VERSION }}" + run: | + make build-plugins-archives + USE_ARCHIVE=true make gen-plugin-index + + - name: Upload plugins to GCS + uses: google-github-actions/upload-cloud-storage@v2 + with: + path: 'dist' + destination: '${{ env.BUCKET_NAME }}/${{ env.VERSION }}' + glob: '*.tar.gz' + parent: false + + - name: Upload plugin index to GCS + uses: google-github-actions/upload-cloud-storage@v2 + with: + path: 'plugins-index.yaml' + destination: '${{ env.BUCKET_NAME }}/${{ env.VERSION }}' diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..d97a0a65 --- /dev/null +++ b/.gitignore @@ -0,0 +1,19 @@ +# 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/ + +dist/ +plugins-index.yaml +/.idea/ diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 00000000..08dd4bce --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,41 @@ +run: + tests: true +issues: + exclude-use-default: false + exclude: + # EXC0001 errcheck: source: https://github.com/kubernetes-sigs/controller-runtime/blob/master/.golangci.yml#L94 + - Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*print(f|ln)?|os\.(Un)?Setenv). is not checked + # G505: Blocklisted import crypto/sha1: weak cryptographic primitive + # This is used just for hashing in ArgoCD plugin + - G505 +linters: + disable-all: true + enable: + - errcheck + - gosimple + - govet + - ineffassign + - staticcheck + - typecheck + - unused + - revive + - gofmt + - misspell + - gochecknoinits + - unparam + - exportloopref + - gosec + - goimports + - whitespace + - bodyclose + - gocyclo + + fast: false + +linters-settings: + revive: + rules: + # Disable warns about capitalized and ended with punctuation error messages + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#error-strings + - name: error-strings + disabled: true diff --git a/.goreleaser.plugin.tpl.yaml b/.goreleaser.plugin.tpl.yaml new file mode 100644 index 00000000..2f7e2459 --- /dev/null +++ b/.goreleaser.plugin.tpl.yaml @@ -0,0 +1,34 @@ +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 > + +archives: + + - builds: [<.Name>] + id: <.Name> + files: + - none* + name_template: "{{ .Binary }}" + + +snapshot: + name_template: 'v{{ .Version }}' diff --git a/.goreleaser.plugin.yaml b/.goreleaser.plugin.yaml new file mode 100644 index 00000000..66d3e680 --- /dev/null +++ b/.goreleaser.plugin.yaml @@ -0,0 +1,223 @@ +# 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. + +before: + hooks: + - 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: exec + main: cmd/executor/exec/main.go + binary: executor_exec_{{ .Os }}_{{ .Arch }} + + no_unique_dist_dir: true + env: + - CGO_ENABLED=0 + goos: + - linux + - darwin + goarch: + - amd64 + - arm64 + goarm: + - 7 + - id: flux + main: cmd/executor/flux/main.go + binary: executor_flux_{{ .Os }}_{{ .Arch }} + + no_unique_dist_dir: true + 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: + - 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: thread-mate + main: cmd/executor/thread-mate/main.go + binary: executor_thread-mate_{{ .Os }}_{{ .Arch }} + + no_unique_dist_dir: true + env: + - CGO_ENABLED=0 + goos: + - linux + - darwin + goarch: + - amd64 + - arm64 + goarm: + - 7 + - id: argocd + main: cmd/source/argocd/main.go + binary: source_argocd_{{ .Os }}_{{ .Arch }} + + no_unique_dist_dir: true + env: + - CGO_ENABLED=0 + goos: + - linux + - darwin + goarch: + - amd64 + - arm64 + goarm: + - 7 + - id: github-events + main: cmd/source/github-events/main.go + binary: source_github-events_{{ .Os }}_{{ .Arch }} + + no_unique_dist_dir: true + 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: + - 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: + - CGO_ENABLED=0 + goos: + - linux + - darwin + goarch: + - amd64 + - arm64 + goarm: + - 7 + +archives: + + - builds: [doctor] + id: doctor + files: + - none* + name_template: "{{ .Binary }}" + + - builds: [exec] + id: exec + files: + - none* + name_template: "{{ .Binary }}" + + - builds: [flux] + id: flux + files: + - none* + name_template: "{{ .Binary }}" + + - builds: [gh] + id: gh + files: + - none* + name_template: "{{ .Binary }}" + + - builds: [helm] + id: helm + files: + - none* + name_template: "{{ .Binary }}" + + - builds: [thread-mate] + id: thread-mate + files: + - none* + name_template: "{{ .Binary }}" + + - builds: [argocd] + id: argocd + files: + - none* + name_template: "{{ .Binary }}" + + - builds: [github-events] + id: github-events + files: + - none* + name_template: "{{ .Binary }}" + + - builds: [keptn] + id: keptn + files: + - none* + name_template: "{{ .Binary }}" + + - builds: [prometheus] + id: prometheus + files: + - none* + name_template: "{{ .Binary }}" + + +snapshot: + name_template: 'v{{ .Version }}' diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..bb3b3b4e --- /dev/null +++ b/Makefile @@ -0,0 +1,48 @@ +############ +# Building # +############ + +build-plugins: ## Builds all plugins for all defined platforms + goreleaser build -f .goreleaser.plugin.yaml --rm-dist --snapshot +.PHONY: build-plugins + +build-plugins-single: ## Builds all plugins only for current GOOS and GOARCH. + goreleaser build -f .goreleaser.plugin.yaml --rm-dist --single-target --snapshot +.PHONY: build-plugins-single + +build-plugins-archives: ## Builds all plugins for all defined platforms in form of arhcives + goreleaser release -f .goreleaser.plugin.yaml --rm-dist --snapshot +.PHONY: build-plugins + +############## +# Generating # +############## + +gen-plugin-index: ## Generate plugins YAML index file. + go run github.com/kubeshop/botkube/hack -binaries-path "./dist" -use-archive=$(USE_ARCHIVE) +.PHONY: gen-plugin-index + +gen-plugins-goreleaser: # Generate Goreleaser config for plugins + go run github.com/kubeshop/botkube/hack/target/gen-goreleaser + +############### +# Developing # +############### + +test: ## Run tests + go test -v -race ./... +.PHONY: test + +fix-lint-issues: ## Automatically fix lint issues + go mod tidy + go mod verify + golangci-lint run --fix "./..." +.PHONY: fix-lint-issues + +############# +# Others # +############# + +help: ## Show this help + @egrep -h '\s##\s' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' +.PHONY: help diff --git a/README.md b/README.md new file mode 100644 index 00000000..b0dc20e9 --- /dev/null +++ b/README.md @@ -0,0 +1,26 @@ +# Botkube Cloud Plugins + +This repository shows Botkube Cloud plugins. + +## Requirements + +- [Go](https://golang.org/doc/install) >= 1.21 +- [GoReleaser](https://goreleaser.com/) >= 1.21 +- [`golangci-lint`](https://golangci-lint.run/) >= 1.55 + +## Development + +1. Clone the repository. +2. Follow the [local testing guide](https://docs.botkube.io/plugin/local-testing). + +## Release + +The latest plugins from `main` are released automatically to the bucket `botkube-cloud-plugins-latest`. +To release a new version of the plugins: + +1. Navigate to the [`Trigger release` GitHub Actions workflow](https://github.com/kubeshop/botkube-cloud-plugins/actions/workflows/release.yml). +1. Provide the target version in the `version` input. Do not forget about the `v` prefix. + + For example, if you want to release version `1.2.3`, you should provide `version: v1.2.3`. + +1. Trigger the pipeline. diff --git a/tools.go b/tools.go new file mode 100644 index 00000000..d3b2d8a8 --- /dev/null +++ b/tools.go @@ -0,0 +1,8 @@ +//go:build tools +// +build tools + +package tools + +import ( + _ "github.com/kubeshop/botkube/hack" +)