Skip to content

Commit

Permalink
move to GHA, change linter, tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
ripexz committed Jan 17, 2024
1 parent 0f17f00 commit c99f292
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ trim_trailing_whitespace = true
[*.{go,sh}]
indent_style = tab

[*.yaml]
[*.{yaml,yml}]
indent_size = 2
81 changes: 81 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: Go
on: [push]
jobs:

lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Lint
uses: golangci/golangci-lint-action@v3
with:
only-new-issues: true



test:
runs-on: ubuntu-latest
steps:

- uses: actions/setup-go@v5
with:
go-version: "1.20"

- uses: actions/checkout@v4
with:
path: gopath/src/github.com/teamwork/kommentaar

- name: Test & coverage
env:
GO111MODULE: "off"
GOPATH: ${{ github.workspace }}/gopath
run: |
cd $GOPATH/src/github.com/teamwork/kommentaar
go test -coverprofile=full_coverage -race ./...
awk 'FNR>1' *_coverage >> full.coverage
- name: Upload coverage
env:
COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GOPATH: ${{ github.workspace }}/gopath
run: |
export PATH="$GOPATH/bin:$PATH"
go install github.com/mattn/[email protected]
cd $GOPATH/src/github.com/teamwork/kommentaar
goveralls -coverprofile=full.coverage -service=github
build:
name: Build and push image
runs-on: ubuntu-latest
needs: [lint, test]
if: startsWith(github.event.ref, 'refs/tags/v')
steps:

- name: Check out the repo
uses: actions/checkout@v4

- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: teamwork/kommentaar

- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
/coverage.html
.DS_Store
.idea
full_coverage
*_coverage
Binary file added kommentaar
Binary file not shown.
9 changes: 4 additions & 5 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"flag"
"go/build"
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand All @@ -30,7 +29,7 @@ func TestStart(t *testing.T) {
}

func TestOpenAPI2(t *testing.T) {
tests, err := ioutil.ReadDir("./testdata/openapi2/src")
tests, err := os.ReadDir("./testdata/openapi2/src")
if err != nil {
t.Fatal(err)
}
Expand All @@ -39,19 +38,19 @@ func TestOpenAPI2(t *testing.T) {
t.Run(tt.Name(), func(t *testing.T) {
path := "./testdata/openapi2/src/" + tt.Name()

want, err := ioutil.ReadFile(path + "/want.yaml")
want, err := os.ReadFile(path + "/want.yaml")
if err != nil && !os.IsNotExist(err) {
t.Fatalf("could not read output: %v", err)
}
want = append(bytes.TrimSpace(want), '\n')

wantJSON, err := ioutil.ReadFile(path + "/want.json")
wantJSON, err := os.ReadFile(path + "/want.json")
if err != nil && !os.IsNotExist(err) {
t.Fatalf("could not read output: %v", err)
}
wantJSON = append(bytes.TrimSpace(wantJSON), '\n')

wantErr, err := ioutil.ReadFile(path + "/wantErr")
wantErr, err := os.ReadFile(path + "/wantErr")
if err != nil && !os.IsNotExist(err) {
t.Fatalf("could not read wantErr: %v", err)
}
Expand Down
3 changes: 1 addition & 2 deletions srvhttp/srvhttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"

Expand Down Expand Up @@ -105,7 +104,7 @@ func run(
) (string, error) {

if args.NoScan {
o, err := ioutil.ReadFile(file)
o, err := os.ReadFile(file)
return string(o), err
}

Expand Down
4 changes: 2 additions & 2 deletions srvhttp/srvhttp_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package srvhttp

import (
"io/ioutil"
"net/http/httptest"
"os"
"testing"

"github.com/teamwork/test/diff"
Expand Down Expand Up @@ -41,7 +41,7 @@ func TestFromFile(t *testing.T) {
YAMLFile: "../testdata/openapi2/src/blank-line/want.yaml",
}

want, err := ioutil.ReadFile("../testdata/openapi2/src/blank-line/want.yaml")
want, err := os.ReadFile("../testdata/openapi2/src/blank-line/want.yaml")
if err != nil {
t.Fatalf("could not read file: %v", err)
}
Expand Down

0 comments on commit c99f292

Please sign in to comment.