diff --git a/.editorconfig b/.editorconfig index 576c5d0..b14f408 100644 --- a/.editorconfig +++ b/.editorconfig @@ -12,5 +12,5 @@ trim_trailing_whitespace = true [*.{go,sh}] indent_style = tab -[*.yaml] +[*.{yaml,yml}] indent_size = 2 diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml new file mode 100644 index 0000000..fde29df --- /dev/null +++ b/.github/workflows/go.yml @@ -0,0 +1,80 @@ +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 ./... + + - name: Upload coverage + env: + COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GOPATH: ${{ github.workspace }}/gopath + run: | + export PATH="$GOPATH/bin:$PATH" + go install github.com/mattn/goveralls@latest + 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 }} diff --git a/.gitignore b/.gitignore index ec14789..8a5f658 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ /coverage.html .DS_Store .idea +full_coverage +*_coverage diff --git a/kommentaar b/kommentaar new file mode 100755 index 0000000..0dfa88b Binary files /dev/null and b/kommentaar differ diff --git a/main_test.go b/main_test.go index 9694662..3498800 100644 --- a/main_test.go +++ b/main_test.go @@ -4,7 +4,6 @@ import ( "bytes" "flag" "go/build" - "io/ioutil" "os" "path/filepath" "strings" @@ -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) } @@ -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) } diff --git a/srvhttp/srvhttp.go b/srvhttp/srvhttp.go index bc5bbad..88a3b5d 100644 --- a/srvhttp/srvhttp.go +++ b/srvhttp/srvhttp.go @@ -5,7 +5,6 @@ import ( "bytes" "fmt" "io" - "io/ioutil" "net/http" "os" @@ -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 } diff --git a/srvhttp/srvhttp_test.go b/srvhttp/srvhttp_test.go index a4b86d5..34c3e65 100644 --- a/srvhttp/srvhttp_test.go +++ b/srvhttp/srvhttp_test.go @@ -1,8 +1,8 @@ package srvhttp import ( - "io/ioutil" "net/http/httptest" + "os" "testing" "github.com/teamwork/test/diff" @@ -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) }