Skip to content

Commit

Permalink
👷 add ci build system
Browse files Browse the repository at this point in the history
  • Loading branch information
plusiv committed Jun 11, 2024
1 parent 748870b commit 64ef72e
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 18 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Build

on:
workflow_call:

jobs:
build-n-test:
runs-on: ubuntu-latest
strategy:
matrix:
go-version: [ '1.20', '1.21', '1.22' ]

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Setup Go ${{ matrix.go-version }}
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
cache-dependency-path: go.sum

- name: Install dependencies
run: |
# Install fieldalignment for fields aligment verfication in structs
go install golang.org/x/tools/go/analysis/passes/fieldalignment/cmd/fieldalignment@latest
go install honnef.co/go/tools/cmd/staticcheck@latest
- name: Build
run: make build
16 changes: 16 additions & 0 deletions .github/workflows/development.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Build and test for devices

on:
pull_request:
branches:
- main
paths:
- "**/*.go"
- "go.mod"
- "go.sum"
- "Makefile"
- ".github/workflows/build.yaml"
- ".github/workflows/development.yaml"
jobs:
call-build-workflow:
uses: "./build.yaml"
26 changes: 26 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
on:
release:
types: [created]

permissions:
contents: write
packages: write

jobs:
releases-matrix:
name: Release Go Binary
runs-on: ubuntu-latest
strategy:
matrix:
# build and publish in parallel: linux/386, linux/amd64, linux/arm64, windows/386, windows/amd64, darwin/amd64, darwin/arm64
goos: [linux, windows, darwin]
goarch: ["386", amd64, arm64]
steps:
- uses: actions/checkout@v4
- uses: wangyoucao577/go-release-action@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
goos: ${{ matrix.goos }}
goarch: ${{ matrix.goarch }}
goversion: "https://dl.google.com/go/go1.13.1.linux-amd64.tar.gz"
extra_files: LICENSE README.md
18 changes: 14 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,16 @@ GOBUILD=$(GOCMD) build
BINARY_NAME=kubectl-envsecret
MAIN_FILE=main.go

vet:
@echo "Vet the code"
$(GOCMD) vet ./...

fieldalignment-check:
@echo "Running fieldalignment"
$(FIELDALIGNMENT_CMD) ./...

fieldalignment:
@echo "Running fieldalignment to optimize struct sizes"
@echo "Running fieldalignment fix to optimize struct sizes"
$(FIELDALIGNMENT_CMD) -fix ./...

test:
Expand All @@ -16,14 +24,16 @@ format:
@echo "Formatting code..."
$(GOCMD) fmt ./...

build:
build: vet
@echo "Building..."
$(GOCMD) build -o $(BINARY_NAME) $(MAIN_FILE)

build-prod: test fieldalignment format build
fix: format fieldalignment

build-prod: test fieldalignment-check build

run: build
./$(BINARY_NAME) $(CMD) $(ARGS) $(FLAGS)


.PHONY: build build-prod run format
.PHONY: build build-prod run format vet fieldalignment-check fieldalignment test fix
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ module github.com/ogticrd/kubectl-envsecret

go 1.22.0

toolchain go1.22.1

require (
github.com/joho/godotenv v1.5.1
github.com/spf13/cobra v1.8.0
Expand Down Expand Up @@ -47,7 +49,6 @@ require (
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/stretchr/objx v0.5.2 // indirect
github.com/xlab/treeprint v1.2.0 // indirect
go.starlark.net v0.0.0-20230525235612-a134d8f9ddca // indirect
golang.org/x/net v0.23.0 // indirect
Expand Down
13 changes: 0 additions & 13 deletions internal/k8sapi/k8s_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import (

"github.com/ogticrd/kubectl-envsecret/internal/k8sapi"
"github.com/stretchr/testify/assert"
v1 "k8s.io/api/core/v1"
kerr "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes/fake"
)

Expand Down Expand Up @@ -36,14 +34,3 @@ func mockSecretData() map[string]string {
secret["bar"] = "line"
return secret
}

func mockSecret(secret map[string]string) *v1.Secret {
return &v1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: "test",
Namespace: "test",
OwnerReferences: []metav1.OwnerReference{},
},
StringData: secret,
}
}

0 comments on commit 64ef72e

Please sign in to comment.