Skip to content

Commit

Permalink
[Feature] Update dependencies & workflows (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
knight42 authored Aug 20, 2023
1 parent 7a5085f commit 3d8f08c
Show file tree
Hide file tree
Showing 14 changed files with 266 additions and 314 deletions.
65 changes: 0 additions & 65 deletions .github/workflows/build-and-release.yml

This file was deleted.

49 changes: 49 additions & 0 deletions .github/workflows/pr-presubmit-checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: '[PR] Presubmit Checks'
on:
pull_request:
types: [opened, synchronize, reopened]
push:
branches:
- main
paths:
- '**.go'

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }}
cancel-in-progress: true

env:
GO_VERSION: 'stable'

jobs:
lint:
runs-on: ubuntu-latest
env:
GOLANGCI_LINT_VERSION: v1.54.1
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: ${{ env.GO_VERSION }}
check-latest: true
- name: Lint
uses: golangci/golangci-lint-action@v3
with:
skip-pkg-cache: true
skip-build-cache: true
version: ${{ env.GOLANGCI_LINT_VERSION }}

test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: ${{ env.GO_VERSION }}
check-latest: true
- name: Test
run: make test
29 changes: 29 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: "[Release] Create GitHub Release and Update krew-index"
on:
push:
tags: ['*']
concurrency:
group: ci-${{ github.event_name }}-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: write
env:
GO_VERSION: stable
jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: ${{ env.GO_VERSION }}
check-latest: true
- uses: goreleaser/goreleaser-action@v4
with:
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Update new version in krew-index
uses: rajatjindal/krew-release-bot@v0.0.42
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
### Above combination will ignore all files without extension ###

.idea/
dist/

*.swp
*.[oa]
Expand Down
33 changes: 33 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
before:
hooks:
- go mod tidy
builds:
- env:
- CGO_ENABLED=0
main: ./cmd/client
binary: kubectl-relay
goos:
- windows
- darwin
- linux
goarch:
- amd64
- arm64
ignore:
- goos: windows
goarch: arm64
gcflags:
- all=-trimpath
archives:
-
name_template: 'kubectl-relay_v{{ .Version }}_{{ .Os }}-{{ .Arch }}'
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ incpatch .Version }}-next"
changelog:
use: github-native

# modelines, feel free to remove those if you don't want/use them:
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
# vim: set ts=2 sw=2 tw=0 fo=cnqoj
30 changes: 1 addition & 29 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ GOBUILD = CGO_ENABLED=0 go build -trimpath -ldflags $(GO_LDFLAGS)

.PHONY: server-image push-server-image
server-image:
docker build -t ghcr.io/knight42/krelay-server:$(IMAGE_TAG) -f manifests/Dockerfile .
docker build -t ghcr.io/knight42/krelay-server:$(IMAGE_TAG) -f manifests/Dockerfile-server .
push-server-image: server-image
docker push ghcr.io/knight42/krelay-server:$(IMAGE_TAG)

Expand All @@ -33,31 +33,3 @@ coverage:
clean:
rm -rf krelay*
rm -rf kubectl-relay*

# Release
PLATFORM_LIST = \
darwin-amd64 \
darwin-arm64 \
linux-amd64 \
linux-arm64 \
windows-amd64
darwin-%:
GOARCH=$* GOOS=darwin $(GOBUILD) -o $(NAME)_$(VERSION)_$@/$(NAME) ./cmd/client

linux-%:
GOARCH=$* GOOS=linux $(GOBUILD) -o $(NAME)_$(VERSION)_$@/$(NAME) ./cmd/client

windows-%:
GOARCH=$* GOOS=windows $(GOBUILD) -o $(NAME)_$(VERSION)_$@/$(NAME).exe ./cmd/client

gz_releases=$(addsuffix .tar.gz, $(PLATFORM_LIST))
$(gz_releases): %.tar.gz : %
case $@ in windows-*) \
tar czf $(NAME)_$(VERSION)_$@ -C $(NAME)_$(VERSION)_$</ ../LICENSE $(NAME).exe ;; \
*) \
tar czf $(NAME)_$(VERSION)_$@ -C $(NAME)_$(VERSION)_$</ ../LICENSE $(NAME) ;; \
esac
sha256sum $(NAME)_$(VERSION)_$@ > $(NAME)_$(VERSION)_$@.sha256

.PHONY: releases
releases: $(gz_releases)
8 changes: 8 additions & 0 deletions cmd/client/info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package main

// These variables are set by goreleaser
var (
version string
commit string
date string
)
28 changes: 14 additions & 14 deletions cmd/client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"context"
"encoding/json"
"errors"
"flag"
"fmt"
Expand Down Expand Up @@ -186,17 +187,6 @@ func (o *Options) Run(ctx context.Context, args []string) error {
return nil
}

func newSignalContext() context.Context {
ctx, cancel := context.WithCancel(context.Background())
sigCh := make(chan os.Signal, 1)
signal.Notify(sigCh, os.Interrupt)
go func() {
<-sigCh
cancel()
}()
return ctx
}

func main() {
klog.InitFlags(nil)
cf := genericclioptions.NewConfigFlags(true)
Expand All @@ -212,10 +202,20 @@ func main() {
service, ip and hostname rather than only pods.`,
RunE: func(cmd *cobra.Command, args []string) error {
if printVersion {
fmt.Printf("Client version: %s\n", constants.ClientVersion)
return nil
return json.NewEncoder(cmd.OutOrStdout()).Encode(struct {
Version string
BuildDate string
Commit string
}{
Version: version,
BuildDate: date,
Commit: commit,
})
}
return o.Run(newSignalContext(), args)

ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
defer cancel()
return o.Run(ctx, args)
},
SilenceUsage: true,
}
Expand Down
7 changes: 6 additions & 1 deletion cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import (
"flag"
"fmt"
"net"
"os"
"os/signal"
"syscall"
"time"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -80,7 +83,9 @@ func main() {
c := cobra.Command{
Use: constants.ServerName,
RunE: func(cmd *cobra.Command, args []string) (err error) {
return o.run(context.Background())
ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGTERM, os.Interrupt)
defer cancel()
return o.run(ctx)
},
SilenceUsage: true,
}
Expand Down
Loading

0 comments on commit 3d8f08c

Please sign in to comment.