Skip to content

Commit

Permalink
feat(ci): add github actions to run CI + minor linter fixes (#287)
Browse files Browse the repository at this point in the history
  • Loading branch information
prichrd authored Dec 13, 2022
1 parent 864a5be commit 6478a8f
Show file tree
Hide file tree
Showing 10 changed files with 118 additions and 31 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Go
on:
push:
tags:
branches:
- master
pull_request:

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Build
run: make build
- name: Test
run: make test
- name: Shellcheck
run: make shell
- name: Lint
run: make lint

27 changes: 27 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
run:
skip-files:
- ".*_test.go"

linters:
disable-all: true
enable:
- dupl
- goconst
- gocyclo
- gofmt
- gosec
- ineffassign
- misspell
- nakedret
- prealloc
- revive
- unconvert
- unparam
- unused
- vet
- gosec

issues:
exclude:
- G404
- G114
18 changes: 0 additions & 18 deletions .travis.yml

This file was deleted.

62 changes: 62 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
.DEFAULT_GOAL := ci

GOOS ?= linux
GOARCH ?= amd64

out := target
package_dir := $(out)/pkg
cache := $(out)/.cache
docker_dir := /home/do-agent
shellscripts := $(shell find -type f -iname '*.sh' ! -path './repos/*' ! -path './vendor/*' ! -path './.git/*')
go_version := $(shell sed -En 's/^go[[:space:]]+([[:digit:].]+)$$/\1/p' go.mod)
print = @printf "\n:::::::::::::::: [$(shell date -u)] $@ ::::::::::::::::\n"

go = \
docker run --rm -i \
-u "$(shell id -u):$(shell id -g)" \
-e "GOOS=$(GOOS)" \
-e "GOARCH=$(GOARCH)" \
-e "GO111MODULE=on" \
-e "GOFLAGS=-mod=vendor" \
-e "GOCACHE=$(docker_dir)/target/.cache/go" \
-v "$(CURDIR):$(docker_dir)" \
-w "$(docker_dir)" \
golang:$(go_version) \
go

shellcheck = \
docker run --rm -i \
-u "$(shell id -u):$(shell id -g)" \
-v "$(CURDIR):$(docker_dir)" \
-w "$(docker_dir)" \
koalaman/shellcheck:v0.6.0

linter = \
docker run --rm -i \
-w "$(docker_dir)" \
-e "GO111MODULE=on" \
-e "GOFLAGS=-mod=vendor" \
-v "$(CURDIR):$(docker_dir)" \
golangci/golangci-lint:v1.50.1

clean:
$(print)
rm -rf ./target

test:
$(print)
$(go) test -v ./...

build:
$(print)
$(go) build -v ./...

shell:
$(print)
$(shellcheck) $(shellscripts)

lint:
$(print)
$(linter) golangci-lint run ./...

ci: clean build test lint shell
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# DigitalOcean Agent

[![Build Status](https://travis-ci.org/digitalocean/do-agent.svg?branch=master)](https://travis-ci.org/digitalocean/do-agent)
[![Go Report Card](https://goreportcard.com/badge/github.com/digitalocean/do-agent)](https://goreportcard.com/report/github.com/digitalocean/do-agent)
[![Coverage Status](https://coveralls.io/repos/github/digitalocean/do-agent/badge.svg?branch=master)](https://coveralls.io/github/digitalocean/do-agent?branch=master)

Expand Down
3 changes: 1 addition & 2 deletions internal/process/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (

type processCollector struct {
collectFn func(chan<- prometheus.Metric)
cpuTotal *prometheus.Desc
rss *prometheus.Desc
}

Expand Down Expand Up @@ -58,7 +57,7 @@ func (c *processCollector) processCollect(ch chan<- prometheus.Metric) {
}

for _, proc := range procs {
stat, err := proc.NewStat()
stat, err := proc.Stat()
if err != nil {
return
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/clients/roundtrippers/bearer_token_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package roundtrippers

import (
"fmt"
"io/ioutil"
"net/http"
"os"
"strings"
)

Expand All @@ -14,7 +14,7 @@ type bearerTokenFileRoundTripper struct {

// RoundTrip implements http.RoundTripper's interface
func (rt *bearerTokenFileRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
t, err := ioutil.ReadFile(rt.tokenFile)
t, err := os.ReadFile(rt.tokenFile)
if err != nil {
return nil, fmt.Errorf("unable to read bearer token file %s: %s", rt.tokenFile, err)
}
Expand Down
4 changes: 1 addition & 3 deletions pkg/clients/roundtrippers/bearer_token_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ func Test_bearerTokenFileRoundTripper_RoundTrip_Happy_Path(t *testing.T) {
func Test_bearerTokenFileRoundTripper_RoundTrip_Missing_File(t *testing.T) {
rt := NewBearerTokenFile(invalidTokenPath, http.DefaultTransport)

ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
return
}))
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {}))
defer ts.Close()

_, err := rt.RoundTrip(httptest.NewRequest(http.MethodGet, ts.URL, nil))
Expand Down
6 changes: 2 additions & 4 deletions pkg/clients/tsclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ server.
Wharf responds with a rate-limit value which the client must wait that many seconds
or longer before submitting the next batch of metrics -- this is exposed via the WaitDuration()
method.
*/
package tsclient

Expand All @@ -19,7 +18,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"math/rand"
"net"
"net/http"
Expand Down Expand Up @@ -551,14 +549,14 @@ func (c *HTTPClient) httpGet(url, authToken string) (string, error) {
return "", &UnexpectedHTTPStatusError{StatusCode: resp.StatusCode}
}

body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
return "", err
}
return string(body), nil
}

//{"success":true,"frequency":60,"max_metrics":1000,"max_lfm":512}
// {"success":true,"frequency":60,"max_metrics":1000,"max_lfm":512}
type sonarResponse struct {
Success bool `json:"success"`
FrequencySeconds int32 `json:"frequency"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (s *Writer) WriteUint16PrefixedString(x string) {

// WriteUnixTime64UTC writes a time as unix epoch in UTC; sub-second accuracy is truncated
func (s *Writer) WriteUnixTime64UTC(x time.Time) {
s.Write(int64(x.UTC().Unix()))
s.Write(x.UTC().Unix())
}

// Error returns any errors the occurred since the writer was first constructed
Expand Down

0 comments on commit 6478a8f

Please sign in to comment.