Skip to content

Commit b570474

Browse files
darestemrajagopal
andauthored
Add Github actions (#8)
* Create go.yml * feat: add version and build * fix: inject build * fix * fix * fix * fix: remove folder from artifact tarball * fix: proper release tarball without folder --------- Co-authored-by: Madhu Rajagopal <[email protected]>
1 parent 639bfec commit b570474

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

.github/workflows/go-builder.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Build and Release
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
7+
jobs:
8+
9+
build:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
14+
- name: Set up Go
15+
uses: actions/setup-go@v4
16+
with:
17+
go-version: '1.21'
18+
19+
- name: Build
20+
run: |
21+
BUILD=$(git log --format='%H' -n 1)
22+
VERSION="dev"
23+
GOOS=linux GOARCH=amd64 go build -ldflags "-w -s -X github.com/nginxinc/nginx-k8s-supportpkg/pkg/version.Build=$BUILD\
24+
-X github.com/nginxinc/nginx-k8s-supportpkg/pkg/version.Version=$VERSION" -o release/kubectl-nic-supportpkg
25+
tar czvf release/kubectl-nic-supportpkg_${VERSION}_linux_amd64.tar.gz -C release kubectl-nic-supportpkg
26+
27+
GOOS=linux GOARCH=arm64 go build -ldflags "-w -s -X github.com/nginxinc/nginx-k8s-supportpkg/pkg/version.Build=$BUILD\
28+
-X github.com/nginxinc/nginx-k8s-supportpkg/pkg/version.Version=$VERSION" -o release/kubectl-nic-supportpkg
29+
tar czvf release/kubectl-nic-supportpkg_${VERSION}_linux_arm64.tar.gz -C release kubectl-nic-supportpkg
30+
31+
GOOS=darwin GOARCH=amd64 go build -ldflags "-w -s -X github.com/nginxinc/nginx-k8s-supportpkg/pkg/version.Build=$BUILD\
32+
-X github.com/nginxinc/nginx-k8s-supportpkg/pkg/version.Version=$VERSION" -o release/kubectl-nic-supportpkg
33+
tar czvf release/kubectl-nic-supportpkg_${VERSION}_darwin_amd64.tar.gz -C release kubectl-nic-supportpkg
34+
35+
GOOS=darwin GOARCH=arm64 go build -ldflags "-w -s -X github.com/nginxinc/nginx-k8s-supportpkg/pkg/version.Build=$BUILD\
36+
-X github.com/nginxinc/nginx-k8s-supportpkg/pkg/version.Version=$VERSION" -o release/kubectl-nic-supportpkg
37+
tar czvf release/kubectl-nic-supportpkg_${VERSION}_darwin_arm64.tar.gz -C release kubectl-nic-supportpkg
38+
39+
- name: Upload Artifacts
40+
uses: actions/upload-artifact@v4
41+
with:
42+
name: release-artifacts
43+
path: release/**/*.gz

cmd/nic-supportpkg.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"github.com/nginxinc/nginx-k8s-supportpkg/pkg/data_collector"
66
"github.com/nginxinc/nginx-k8s-supportpkg/pkg/jobs"
7+
"github.com/nginxinc/nginx-k8s-supportpkg/pkg/version"
78
"github.com/spf13/cobra"
89
"os"
910
)
@@ -24,6 +25,8 @@ func Execute() {
2425
os.Exit(1)
2526
}
2627

28+
collector.Logger.Printf("Starting kubectl-nic-suportpkg - version: %s - build: %s", version.Version, version.Build)
29+
2730
if collector.AllNamespacesExist() == true {
2831
for _, job := range jobs.JobList() {
2932
fmt.Printf("Running job %s...", job.Name)

pkg/version/version.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package version
2+
3+
// Version and Build are injected in the build process
4+
var Version = "dev"
5+
var Build = "dev"

0 commit comments

Comments
 (0)