Skip to content

Commit

Permalink
Add CI checks
Browse files Browse the repository at this point in the history
  • Loading branch information
sam-at-luther committed Jun 30, 2023
1 parent da62bbb commit bcd0cd6
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 17 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/pushproxng-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: CI Test

on:
pull_request:
branches:
- main
jobs:
test:
runs-on: ubuntu-latest
container:
image: luthersystems/build-go:v0.0.68
steps:
- uses: actions/[email protected]
- name: Run CI
run: make citest
20 changes: 20 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
PROJECT_REL_DIR=./
include ${PROJECT_REL_DIR}/common.mk
DOCKER_PROJECT_DIR:=$(call DOCKER_DIR, ${PROJECT_REL_DIR})

.PHONY: default
default: all

.PHONY: all

.PHONY: static-checks
static-checks:
./scripts/static-checks.sh

.PHONY: go-test
go-test:
${GO_TEST_TIMEOUT_10} ./...

.PHONY: citest
citest: static-checks go-test
@
16 changes: 8 additions & 8 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"os"
"strings"
Expand All @@ -25,9 +25,9 @@ const (
func run() {
viper.SetEnvPrefix("pushproxng_client")
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
viper.BindEnv("proxy")
viper.BindEnv("fqdn")
viper.BindEnv("target")
_ = viper.BindEnv("proxy")
_ = viper.BindEnv("fqdn")
_ = viper.BindEnv("target")

proxy := viper.GetString("proxy")
fqdn := viper.GetString("fqdn")
Expand Down Expand Up @@ -58,7 +58,7 @@ func run() {
pause()
continue
}
respPollBytes, err := ioutil.ReadAll(respPoll.Body)
respPollBytes, err := io.ReadAll(respPoll.Body)
respPoll.Body.Close()
if err != nil {
log(err)
Expand Down Expand Up @@ -155,13 +155,13 @@ func init() {
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file")

rootCmd.Flags().String("proxy", "invalid", "Proxy address")
viper.BindPFlag("proxy", rootCmd.Flags().Lookup("proxy"))
_ = viper.BindPFlag("proxy", rootCmd.Flags().Lookup("proxy"))

rootCmd.Flags().String("fqdn", "invalid", "FQDN")
viper.BindPFlag("fqdn", rootCmd.Flags().Lookup("fqdn"))
_ = viper.BindPFlag("fqdn", rootCmd.Flags().Lookup("fqdn"))

rootCmd.Flags().String("target", "invalid", "Target address")
viper.BindPFlag("target", rootCmd.Flags().Lookup("target"))
_ = viper.BindPFlag("target", rootCmd.Flags().Lookup("target"))
}

func initConfig() {
Expand Down
63 changes: 63 additions & 0 deletions common.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
PROJECT=pushproxng
PROJECT_PATH=github.com/luthersystems/${PROJECT}

BUILDENV_TAG=v0.0.69
BUILD_IMAGE_GO=luthersystems/build-go:${BUILDENV_TAG}

TAG_SUFFIX ?= -amd64
GIT_TAG ?= $(shell git describe --tags --exact-match 2>/dev/null)
GIT_REVISION ?= $(shell git rev-parse --short HEAD)
VERSION ?= $(if $(strip $(GIT_TAG)),$(GIT_TAG),$(GIT_REVISION))
BUILD_VERSION ?= ${VERSION}${TAG_SUFFIX}

GO_PKG_VOLUME=${PROJECT}-build-gopath-pkg
GO_PKG_PATH=/go/pkg
GO_PKG_MOUNT=$(if $(CI),-v $(PWD)/build/pkg:${GO_PKG_PATH},--mount='type=volume,source=${GO_PKG_VOLUME},destination=${GO_PKG_PATH}')

GO_TEST_BASE=go test ${GO_TEST_FLAGS}
GO_TEST_TIMEOUT_10=${GO_TEST_BASE} -timeout 10m

DOCKER_IN_DOCKER_MOUNT?=-v /var/run/docker.sock:/var/run/docker.sock

ifeq ($(OS),Windows_NT)
IS_WINDOWS=1
endif

CP=cp
RM=rm
DOCKER=docker
DOCKER_SSH_OPTS?=$(shell pinata-ssh-mount || echo "-v $$SSH_AUTH_SOCK:/ssh-agent -v $$HOME/.ssh/known_hosts:/root/.ssh/known_hosts -e SSH_AUTH_SOCK=/ssh-agent")
DOCKER_RUN_OPTS=--rm
DOCKER_RUN=${DOCKER} run ${DOCKER_RUN_OPTS}
CHOWN=$(if $(CIRCLECI),sudo chown,chown)
CHOWN_USR=$(shell id -u)
DOCKER_USER=$(shell id -u):$(shell id -g)
CHOWN_GRP=$(if $(or $(IS_WINDOWS),$(CIRCLECI)),,$(shell id -g))
DOMAKE=cd $1 && $(MAKE) $2 # NOTE: this is not used for now as it does not work with -j for some versions of Make
MKDIR_P=mkdir -p
TOUCH=touch
GZIP=gzip
GUNZIP=gunzip
TIME_P=time -p
TAR=tar

# The Makefile determines whether to build a container or not by consulting a
# dummy file that is touched whenever the container is built. The function,
# IMAGE_DUMMY, computes the path to the dummy file.
DUMMY_TARGET=build/$(1)/$(2)/.dummy
IMAGE_DUMMY=$(call DUMMY_TARGET,image,$(1))
PUSH_DUMMY=$(call DUMMY_TARGET,push,$(1))
MANIFEST_DUMMY=$(call DUMMY_TARGET,manifest,$(1))
FQ_DOCKER_IMAGE ?= docker.io/$(1)

UNAME := $(shell uname)
GIT_LS_FILES=$(shell git ls-files $(1))

DOCKER_WIN_DIR=$(shell cygpath -wm $(realpath $(1)))
DOCKER_NIX_DIR=$(realpath $(1))
DOCKER_DIR=$(if $(IS_WINDOWS),$(call DOCKER_WIN_DIR, $(1)),$(call DOCKER_NIX_DIR, $(1)))

# print out make variables, e.g.:
# make echo:VERSION
echo\:%:
@echo $($*)
4 changes: 2 additions & 2 deletions embeddedclient/embeddedclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"time"
Expand Down Expand Up @@ -48,7 +48,7 @@ func Work(proxy string, fqdn string) {
pause()
continue
}
respPollBytes, err := ioutil.ReadAll(respPoll.Body)
respPollBytes, err := io.ReadAll(respPoll.Body)
respPoll.Body.Close()
if err != nil {
log(err)
Expand Down
12 changes: 6 additions & 6 deletions proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"os"
"strings"
Expand Down Expand Up @@ -202,7 +202,7 @@ func (s *State) InterlockMacroAwaitReply(ctx context.Context, fqdn string, id st
func run() {
viper.SetEnvPrefix("pushproxng_proxy")
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
viper.BindEnv("listen")
_ = viper.BindEnv("listen")

listenAddress := viper.GetString("listen")

Expand Down Expand Up @@ -251,7 +251,7 @@ func run() {

if err := http.ListenAndServe(listenAddress, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path == "/poll" {
jsonBytes, err := ioutil.ReadAll(r.Body)
jsonBytes, err := io.ReadAll(r.Body)
if err != nil {
log(err)
return
Expand Down Expand Up @@ -294,7 +294,7 @@ func run() {
return
}
} else if r.URL.Path == "/push" {
jsonBytes, err := ioutil.ReadAll(r.Body)
jsonBytes, err := io.ReadAll(r.Body)
if err != nil {
log(err)
return
Expand Down Expand Up @@ -373,7 +373,7 @@ func run() {
}
} else if r.URL.Path == "/probe" {
w.WriteHeader(http.StatusOK)
w.Write([]byte("+OK"))
_, _ = w.Write([]byte("+OK"))
} else {
fmt.Printf("http serve unknown: '%s'\n", r.URL.Path)
http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
Expand Down Expand Up @@ -407,7 +407,7 @@ func init() {
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file")

rootCmd.Flags().String("listen", ":8080", "Listen address")
viper.BindPFlag("listen", rootCmd.Flags().Lookup("listen"))
_ = viper.BindPFlag("listen", rootCmd.Flags().Lookup("listen"))
}

func initConfig() {
Expand Down
9 changes: 9 additions & 0 deletions scripts/static-checks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash
# Copyright © 2021 Luther Systems, Ltd. All right reserved.

# This script runs source code checking tools it can be called via a make
# target or can be run automatically during CI testing.

set -exuo pipefail

golangci-lint run --timeout=5m -v
2 changes: 1 addition & 1 deletion testmetric/testmetric.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ import (

func main() {
http.Handle("/metrics", promhttp.Handler())
http.ListenAndServe(":9100", nil)
_ = http.ListenAndServe(":9100", nil)
}

0 comments on commit bcd0cd6

Please sign in to comment.