Skip to content

Commit

Permalink
build: add goreleaser and github actions ci
Browse files Browse the repository at this point in the history
  • Loading branch information
idebeijer committed Aug 11, 2024
1 parent 68a08c9 commit 5f294c6
Show file tree
Hide file tree
Showing 6 changed files with 164 additions and 2 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
@@ -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 }}
47 changes: 47 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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 }}
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,9 @@ go.work

# IntelliJ IDEA
.idea

# Exclude completion scripts
completions/

# Exclude Mac OS X system files
.DS_Store
56 changes: 56 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -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'
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions scripts/completions.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 5f294c6

Please sign in to comment.