From 26a40113f7d4ec32bd2a669bbefb27dede8dac31 Mon Sep 17 00:00:00 2001 From: fogfish Date: Mon, 19 Feb 2024 11:29:24 +0200 Subject: [PATCH] configure GitHub Actions (#1) Configure GitHub Actions - Enable testing and quality check of source code for each pull request. - Enable automated releasing --- .github/workflows/build.yml | 56 ++++++++++++++++++++++++++++++++ .github/workflows/check-code.yml | 27 +++++++++++++++ .github/workflows/check-test.yml | 31 ++++++++++++++++++ .gitignore | 24 ++++++++++++++ .goreleaser.yml | 49 ++++++++++++++++++++++++++++ .zappr.yaml | 9 +++++ README.md | 18 +++++++--- cmd/list.go | 2 +- cmd/root.go | 7 ++-- main.go | 11 ++++++- 10 files changed, 223 insertions(+), 11 deletions(-) create mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/check-code.yml create mode 100644 .github/workflows/check-test.yml create mode 100644 .gitignore create mode 100644 .goreleaser.yml create mode 100644 .zappr.yaml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..d976af8 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,56 @@ +## +## Build the main branch +## +name: build +on: + push: + branches: + - main + - /refs/heads/main + +jobs: + + build: + runs-on: ubuntu-latest + steps: + + ## actions/setup-go@v5 + - uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 + with: + go-version: "1.21" + + ## actions/checkout@v4.1.1 + - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 + with: + fetch-depth: 0 + + - name: go build + run: | + go build ./... + + - name: go test + run: | + go test -v ./... + + ## reecetech/version-increment@2023.10.2 + - uses: reecetech/version-increment@71036b212bbdc100b48aae069870f10953433346 + id: version + with: + scheme: semver + increment: patch + + - name: tag version + run: | + git config user.name "GitHub Actions" + git config user.email "github-actions@users.noreply.github.com" + git tag ${{ steps.version.outputs.v-version }} + git push origin -u ${{ steps.version.outputs.v-version }} + + ## goreleaser/goreleaser-action@v5 + - uses: goreleaser/goreleaser-action@7ec5c2b0c6cdda6e8bbb49444bc797dd33d74dd8 + with: + distribution: goreleaser + version: latest + args: release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/check-code.yml b/.github/workflows/check-code.yml new file mode 100644 index 0000000..5c93bd4 --- /dev/null +++ b/.github/workflows/check-code.yml @@ -0,0 +1,27 @@ +## +## Check quality of source code +## +name: check +on: + pull_request: + types: + - opened + - synchronize + +jobs: + code: + runs-on: ubuntu-latest + steps: + + ## actions/setup-go@v5 + - uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 + with: + go-version: "1.21" + + ## actions/checkout@v4.1.1 + - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 + + ## dominikh/staticcheck-action@v1.3.0 + - uses: dominikh/staticcheck-action@ba605356b4b29a60e87ab9404b712f3461e566dc + with: + install-go: false diff --git a/.github/workflows/check-test.yml b/.github/workflows/check-test.yml new file mode 100644 index 0000000..3618401 --- /dev/null +++ b/.github/workflows/check-test.yml @@ -0,0 +1,31 @@ +## +## Unit Tests & Coverage +## +name: test +on: + pull_request: + types: + - opened + - synchronize + +jobs: + + unit: + runs-on: ubuntu-latest + steps: + + ## actions/setup-go@v5 + - uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 + with: + go-version: "1.21" + + ## actions/checkout@v4.1.1 + - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 + + - name: go build + run: | + go build ./... + + - name: go test + run: | + go test -v $(go list ./... | grep -v /examples/) diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..365974b --- /dev/null +++ b/.gitignore @@ -0,0 +1,24 @@ +# If you prefer the allow list template instead of the deny list, see community template: +# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore +# +# 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 workspace file +go.work + +#Go Releaser output +dist/ diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..f34aace --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,49 @@ +project_name: rds-health + +release: + github: + owner: zalando + name: rds-health + +before: + hooks: + - go mod tidy + +builds: + - env: + - CGO_ENABLED=0 + goos: + - linux + - windows + - darwin + + ignore: + - goarch: 386 + +archives: + - format: binary + +checksum: + name_template: '{{ .ProjectName }}_{{ .Version }}_checksums.txt' + +snapshot: + name_template: "{{ .Tag }}-next" + +changelog: + sort: asc + filters: + exclude: + - '^docs:' + - '^test:' + +brews: + - repository: + owner: zalando + name: rds-health + folder: Formula + goarm: "7" + homepage: https://github.com/zalando/rds-health + description: rds-health discovers anomalies, performance issues and optimization within AWS RDS. + license: MIT + test: | + system "#{bin}/rds-health --version" diff --git a/.zappr.yaml b/.zappr.yaml new file mode 100644 index 0000000..42cde9b --- /dev/null +++ b/.zappr.yaml @@ -0,0 +1,9 @@ +approvals: + groups: + zalando: + minimum: 2 + from: + orgs: + - zalando +# one of [code, doc, config, tools, secrets] +X-Zalando-Type: code diff --git a/README.md b/README.md index 49914d3..cc105e4 100644 --- a/README.md +++ b/README.md @@ -12,11 +12,10 @@ - - --> @@ -41,7 +40,16 @@ Let's get your start with `rds-health`. These few simple steps explain how to ru ### Install -Easiest way to install the latest version of utility using binary release, which are available [here](https://github.com/zalando/rds-health/releases) for multiple platforms. +Easiest way to install the latest version of utility using binary release, which are available +either from [Homebrew](https://brew.sh/) taps or [GitHub](https://github.com/zalando/rds-health/releases) for multiple platforms. + +```bash +## Install using brew +brew tap zalando/rds-health https://github.com/zalando/rds-health +brew install -q rds-health + +## use `brew upgrade` to upgrade to latest version +``` Alternatively, you can install application from source code but it requires [Golang](https://go.dev/) to be installed. @@ -78,7 +86,7 @@ AZ ENGINE VSN INSTANCE CPU MEM STORAGE TYPE RO NAME 1b postgres 14.7 db.t3.medium 2x 4 GiB 40 GiB gp2 my-database-2 ... -(use "rds-health check -a" to check health status of instances) +(use "rds-health check" to check health status of instances) ``` @@ -148,4 +156,4 @@ The library is [MIT](./LICENSE.md) licensed and accepts contributions via GitHub ## License -[![See LICENSE](https://img.shields.io/github/license/zalando/rds-health.svg?style=for-the-badge)](LICENSE) \ No newline at end of file +[![See LICENSE](https://img.shields.io/github/license/zalando/rds-health.svg?style=for-the-badge)](./LICENSE.md) \ No newline at end of file diff --git a/cmd/list.go b/cmd/list.go index 56cd3bd..9956a18 100644 --- a/cmd/list.go +++ b/cmd/list.go @@ -60,6 +60,6 @@ func list(cmd *cobra.Command, args []string, api Service) error { func listPost(cmd *cobra.Command, args []string) { if !outJsonify { - stderr("\n(use \"rds-health check -a\" to check health status of instances)\n") + stderr("\n(use \"rds-health check\" to check health status of instances)\n") } } diff --git a/cmd/root.go b/cmd/root.go index 964d5be..fe2e165 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -23,7 +23,9 @@ import ( ) // Execute is entry point for cobra cli application -func Execute() { +func Execute(vsn string) { + rootCmd.Version = vsn + if err := rootCmd.Execute(); err != nil { e := err.Error() fmt.Println(strings.ToUpper(e[:1]) + e[1:]) @@ -51,8 +53,6 @@ func init() { } -var version = "v0.0.0-dev" - var rootCmd = &cobra.Command{ Use: "rds-health", Short: "command line interface to check health of AWS RDS", @@ -152,7 +152,6 @@ Examples: `, Run: root, PersistentPreRun: setup, - Version: version, } func root(cmd *cobra.Command, args []string) { diff --git a/main.go b/main.go index f6aa84e..49373f2 100644 --- a/main.go +++ b/main.go @@ -9,9 +9,18 @@ package main import ( + "fmt" + "github.com/zalando/rds-health/cmd" ) +var ( + // See https://goreleaser.com/cookbooks/using-main.version/ + version = "dev" + commit = "unknown" + date = "unknown" +) + func main() { - cmd.Execute() + cmd.Execute(fmt.Sprintf("rds-health/%s (%s), %s", version, commit[:7], date)) }