Skip to content

Commit

Permalink
Introduce CI pipelines for plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
pkosiec committed Feb 7, 2024
1 parent 4ab3de0 commit 64c6ea7
Show file tree
Hide file tree
Showing 14 changed files with 689 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Botkube maintainers (email: [email protected])
# Maintainers are listed alphabetically

* @kubeshop/botkube-dev
28 changes: 28 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
name: Bug
about: Report a bug in the project
labels: bug
---

<!-- Thank you for your contribution. Before you submit the issue:
1. Search open and closed issues for duplicates.
2. Read the contributing guidelines (CONTRIBUTING.md file on root of the repository).
-->

## Description

<!-- Provide a clear and concise description of the problem.
Describe where it appears, when it occurred, and what it affects.
Provide all relevant technical details such as the Botkube version. -->

## Expected behavior

<!-- Describe what you expect to happen. -->

## Actual behavior

<!-- Describe what happens instead. -->

## Steps to reproduce

<!-- Steps to reproduce the issue. Attach all resources that can help us understand the bug, such as screenshots, links or files. -->
22 changes: 22 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
name: Feature request
about: Suggest how we can improve
labels: enhancement
---

<!-- Thank you for your contribution. Before you submit the issue:
1. Search open and closed issues for duplicates.
2. Read the contributing guidelines (CONTRIBUTING.md file on root of the repository).
-->

## Overview

<!-- Provide a clear and concise overview of the feature. -->

## Acceptance Criteria

<!-- Provide a list of conditions that must be satisfied to close this issue. -->

## Reason

<!-- Explain why we should add this feature. -->
17 changes: 17 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!-- Thank you for your contribution. Before you submit the pull request:
1. Follow contributing guidelines, templates, the recommended Git workflow, and any related documentation.
2. Test your changes and attach their results to the pull request.
3. Update the relevant documentation.
-->

## Description

Changes proposed in this pull request:

- ...

## Related issue(s)

<!-- If you refer to a particular issue, provide its number.
To close the issue after the pull request merge, use `Resolves #123` or `Fixes #123`.
Otherwise, use `See also #123` or just `#123`. -->
127 changes: 127 additions & 0 deletions .github/workflows/branch-pr-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
name: Branch and PR build
on:
push:
branches:
- main
pull_request:
branches:
- main
env:
GOLANGCI_LINT_TIMEOUT: 5m
GORELEASER_CURRENT_TAG: "v0.0.0-latest"
BUCKET_NAME: botkube-cloud-plugins-latest

jobs:
cancel-previous-workflows:
name: Cancel previous workflows
runs-on: ubuntu-latest
if: github.event.pull_request.draft == false
# https://github.com/styfle/cancel-workflow-action#advanced-token-permissions
permissions:
actions: write

steps:
- name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5
with:
access_token: ${{ github.token }}

lint-test:
name: Lint and test
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: "Check code quality"
uses: golangci/golangci-lint-action@v3
with:
args: --timeout=${{ env.GOLANGCI_LINT_TIMEOUT }}
- name: "Run tests"
run: make test

build-plugins:
if: github.event_name == 'pull_request'
name: Build plugins without publish
runs-on: ubuntu-latest
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 }}/*'
31 changes: 31 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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
})
61 changes: 61 additions & 0 deletions .github/workflows/tag-build.yml
Original file line number Diff line number Diff line change
@@ -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 }}'
19 changes: 19 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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/
41 changes: 41 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -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
34 changes: 34 additions & 0 deletions .goreleaser.plugin.tpl.yaml
Original file line number Diff line number Diff line change
@@ -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:
<range .>
- builds: [<.Name>]
id: <.Name>
files:
- none*
name_template: "{{ .Binary }}"
<end>

snapshot:
name_template: 'v{{ .Version }}'
Loading

0 comments on commit 64c6ea7

Please sign in to comment.