From 5f294c66f8a010dd1cef90945f168ef9f8e8b2e7 Mon Sep 17 00:00:00 2001 From: idebeijer <71566757+idebeijer@users.noreply.github.com> Date: Sun, 11 Aug 2024 13:09:55 +0200 Subject: [PATCH] build: add goreleaser and github actions ci --- .github/workflows/build-test.yml | 47 +++++++++++++++++++++++++++ .github/workflows/release.yml | 47 +++++++++++++++++++++++++++ .gitignore | 6 ++++ .goreleaser.yaml | 56 ++++++++++++++++++++++++++++++++ go.mod | 2 -- scripts/completions.sh | 8 +++++ 6 files changed, 164 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/build-test.yml create mode 100644 .github/workflows/release.yml create mode 100644 .goreleaser.yaml create mode 100755 scripts/completions.sh diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml new file mode 100644 index 0000000..4d01b08 --- /dev/null +++ b/.github/workflows/build-test.yml @@ -0,0 +1,47 @@ +name: build and test + +on: + workflow_dispatch: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.22' + + - name: Build + run: go build -v ./... + + - name: Test + run: go test -v ./... + + goreleaser-build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.22' + + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v6 + with: + distribution: goreleaser + version: "~> v1" + args: release --clean --snapshot --skip=publish,validate + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..ebda381 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,47 @@ +name: goreleaser + +on: + push: + tags: + - "v*" + +permissions: + contents: write + +jobs: + check-pat: + runs-on: ubuntu-latest + steps: + - name: Check if homebrew tap token is valid + env: + HOMEBREW_TAP_GITHUB_TOKEN: ${{ secrets.HOMEBREW_TAP_GITHUB_TOKEN }} + run: | + response=$(curl -s -o /dev/null -w "%{http_code}" -H "Authorization: token $HOMEBREW_TAP_GITHUB_TOKEN" https://api.github.com/user) + if [ "$response" -ne 200 ]; then + echo "PAT is invalid or expired" + exit 1 + fi + echo "PAT is valid" + + goreleaser: + runs-on: ubuntu-latest + needs: check-pat + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: stable + + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v6 + with: + distribution: goreleaser + version: "~> v2" + args: release --clean + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore index c8affe9..78dd59a 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,9 @@ go.work # IntelliJ IDEA .idea + +# Exclude completion scripts +completions/ + +# Exclude Mac OS X system files +.DS_Store \ No newline at end of file diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..26cc630 --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,56 @@ +# yaml-language-server: $schema=https://goreleaser.com/static/schema.json +# vim: set ts=2 sw=2 tw=0 fo=cnqoj + +version: 2 + +before: + hooks: + - go mod tidy + - ./scripts/completions.sh + +builds: + - env: + - CGO_ENABLED=0 + goos: + - linux + - windows + - darwin + +archives: + - files: + - completions/* + +brews: + - repository: + owner: idebeijer + name: homebrew-tap + token: "{{ .Env.HOMEBREW_TAP_GITHUB_TOKEN }}" + directory: Formula + homepage: "https://github.com/idebeijer/kubert" + dependencies: + - name: fzf + type: optional + install: | + bin.install "kubert" + zsh_completion.install "completions/kubert.zsh" => "_kubert" + bash_completion.install "completions/kubert.bash" => "kubert" + fish_completion.install "completions/kubert.fish" + +changelog: + sort: asc + groups: + - title: "Breaking changes" + regexp: '^.*?(feat|fix|build|ci|chore|refactor|perf|test|revert)(\([a-zA-Z0-9_\-]+\))?!:\s?.+$' + order: 0 + - title: Features + regexp: '^.*?feat(\([a-zA-Z0-9_\-]+\))?(!)?:\s?.+$' + order: 1 + - title: "Bug fixes" + regexp: '^.*?fix(\([a-zA-Z0-9_\-]+\))?(!)?:\s?.+$' + order: 2 + - title: Others + order: 999 + filters: + exclude: + - '^.*?(docs|test|style)(\([a-zA-Z0-9_\-]+\))?!?:\s?.+$' + - 'initial commit' \ No newline at end of file diff --git a/go.mod b/go.mod index 55391eb..0a4e5b8 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,6 @@ require ( github.com/gofrs/flock v0.12.1 github.com/spf13/cobra v1.8.1 github.com/spf13/viper v1.19.0 - github.com/stretchr/testify v1.9.0 k8s.io/apimachinery v0.30.3 k8s.io/client-go v0.30.3 ) @@ -37,7 +36,6 @@ require ( github.com/modern-go/reflect2 v1.0.2 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/pelletier/go-toml/v2 v2.2.2 // indirect - github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/sagikazarmark/locafero v0.4.0 // indirect github.com/sagikazarmark/slog-shim v0.1.0 // indirect github.com/sourcegraph/conc v0.3.0 // indirect diff --git a/scripts/completions.sh b/scripts/completions.sh new file mode 100755 index 0000000..542844f --- /dev/null +++ b/scripts/completions.sh @@ -0,0 +1,8 @@ +#!/bin/sh +set -e +rm -rf completions +mkdir completions + +for sh in bash zsh fish; do + go run main.go completion "$sh" >"completions/kubert.$sh" +done \ No newline at end of file