Skip to content

Commit

Permalink
ci: enable cache to speed up jobs (#433)
Browse files Browse the repository at this point in the history
- Bump Go version {1.17 => 1.18}.
  - Ensure to fetch the latest version in 'build' and 'release'
    workflows to pull in the most up-to-date release so that security
    fixes can be included.
  - Bump the golangci-lint version {v1.42.1 => v1.50}. This is required
    to be able to lint source code with Go 1.18. Fails with 'undeclared
    name' errors otherwise.
- Do not run 'go mod tidy' as this can modify the mod file. Changes to
  dependencies should be explicitly committed where required.
- Modify release workflow as per
  https://goreleaser.com/ci/actions/#workflow.
- Bump action versions:
  - actions/setup-go@{v2 => v3}. Enable the 'cache' option for caching
    dependency files and build outputs.
  - actions/checkout@{v2 => v3}.
  - golangci/golangci-lint-action@{v2 => v3}. Caching is enabled by
    default. Bump golangci-lint version {v1.42.1 => v1.50}, needed for
    Go 1.18.
- Fix linting issues due to deprecation of ioutil package. Migrate to io
  and os packages instead.
- Consistent formatting:
  - Checkout code first in all jobs across workflows with the name
    'Checkout code'.
  - Setup Go after 'Checkout code' with the name 'Set up Go'.
  • Loading branch information
sudo-suhas authored Nov 7, 2022
1 parent 1c7f96e commit 6495614
Show file tree
Hide file tree
Showing 19 changed files with 75 additions and 62 deletions.
16 changes: 11 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,21 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
# See https://goreleaser.com/ci/actions/#fetch-depthness
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
fetch-depth: 0
- run: git fetch --force --tags
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: '1.18'
cache: true
check-latest: true
- name: Get release tag
id: get_version
uses: battila7/get-version-action@v2
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: '1.17'
- name: Run GoReleaser
uses: goreleaser/[email protected]
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build_dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Login to DockerHub
uses: docker/login-action@v1
with:
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ jobs:
documentation:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Checkout code
uses: actions/checkout@v3
- uses: actions/setup-node@v2
- name: Installation
uses: bahmutov/npm-install@v1
Expand Down
16 changes: 9 additions & 7 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@ jobs:
golangci:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v2
with:
go-version: '1.17'
- uses: actions/checkout@v2
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: '1.18'
# See https://github.com/golangci/golangci-lint-action#how-to-use
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
uses: golangci/golangci-lint-action@v3
with:
skip-go-installation: true
version: v1.42.1
version: v1.50
args: --timeout=5m
11 changes: 6 additions & 5 deletions .github/workflows/plugin_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.17
go-version: '1.18'
cache: true
- name: Install dependencies
run: sudo apt-get install build-essential
- name: Install packages
run: go mod tidy
- name: Run Test
run: make test-plugins
16 changes: 10 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,18 @@ jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: '^1.17'
- name: Checkout
uses: actions/checkout@v2
# See https://goreleaser.com/ci/actions/#fetch-depthness
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
- run: git fetch --force --tags
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: '^1.18'
cache: true
check-latest: true
- name: Login to DockerHub
uses: docker/login-action@v1
with:
Expand Down
13 changes: 7 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,20 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.17
go-version: '1.18'
cache: true
- name: Install dependencies
run: sudo apt-get install build-essential
- name: Install packages
run: go mod tidy
- name: Run Test
run: make test
- name: Install goveralls and send coverage
env:
COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
go get github.com/mattn/goveralls
go install github.com/mattn/goveralls@v0.0.11
goveralls -coverprofile=coverage.out -service=github
4 changes: 2 additions & 2 deletions plugins/extractors/redash/redash.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
_ "embed" // used to print the embedded assets
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"time"

Expand Down Expand Up @@ -160,7 +160,7 @@ func (e *Extractor) makeRequest(method, url string, payload interface{}, data in
if res.StatusCode < 200 || res.StatusCode >= 300 {
return fmt.Errorf("response failed with status code %d: %w", res.StatusCode, err)
}
b, err := ioutil.ReadAll(res.Body)
b, err := io.ReadAll(res.Body)
if err != nil {
return fmt.Errorf("failed to read response body: %w", err)
}
Expand Down
6 changes: 3 additions & 3 deletions plugins/extractors/superset/superset.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
_ "embed" // used to print the embedded assets
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"strconv"
"time"
Expand Down Expand Up @@ -167,7 +167,7 @@ func (e *Extractor) getChartsList(id int) (charts []*v1beta2.Chart, err error) {
return tempCharts, nil
}

//getAccessToken authenticate and get a JWT access token
// getAccessToken authenticate and get a JWT access token
func (e *Extractor) getAccessToken() (accessToken string, err error) {
payload := map[string]interface{}{
"username": e.config.Username,
Expand Down Expand Up @@ -220,7 +220,7 @@ func (e *Extractor) makeRequest(method, url string, payload interface{}, data in
if res.StatusCode < 200 || res.StatusCode >= 300 {
return errors.Wrapf(err, "response failed with status code: %d", res.StatusCode)
}
b, err := ioutil.ReadAll(res.Body)
b, err := io.ReadAll(res.Body)
if err != nil {
return errors.Wrap(err, "failed to read response body")
}
Expand Down
3 changes: 1 addition & 2 deletions plugins/extractors/superset/superset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"os"
Expand Down Expand Up @@ -253,7 +252,7 @@ func makeRequest(method, url string, payload interface{}, data interface{}) (err
bodyString := string(bodyBytes)
return fmt.Errorf("response failed with status code: %d and body: %s", res.StatusCode, bodyString)
}
b, err := ioutil.ReadAll(res.Body)
b, err := io.ReadAll(res.Body)
if err != nil {
return fmt.Errorf("failed to read response body: %w", err)
}
Expand Down
4 changes: 2 additions & 2 deletions plugins/extractors/tableau/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"strconv"
"time"
Expand Down Expand Up @@ -243,7 +243,7 @@ func (c *client) makeRequest(method, url string, payload interface{}, data inter
return fmt.Errorf("getting %d status code", res.StatusCode)
}

bytes, err := ioutil.ReadAll(res.Body)
bytes, err := io.ReadAll(res.Body)
if err != nil {
return errors.Wrap(err, "failed to read response body")
}
Expand Down
6 changes: 3 additions & 3 deletions plugins/extractors/tableau/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ package tableau
import (
"context"
"encoding/json"
"io/ioutil"
"net/http"
"os"
"testing"

"github.com/dnaeon/go-vcr/v2/recorder"
Expand Down Expand Up @@ -105,7 +105,7 @@ func TestGetWorkbooksByProjectName(t *testing.T) {
}

func testDataGetWorkbooksByProjectName(t *testing.T) (wbs []*Workbook, err error) {
byteString, err := ioutil.ReadFile("testdata/workbooks_by_project_response.json")
byteString, err := os.ReadFile("testdata/workbooks_by_project_response.json")
if err != nil {
t.Fatal(err)
}
Expand All @@ -120,7 +120,7 @@ func testDataGetWorkbooksByProjectName(t *testing.T) (wbs []*Workbook, err error
}

func testDataGetAllProjects(t *testing.T) (ps []*Project, err error) {
byteString, err := ioutil.ReadFile("testdata/projects_response.json")
byteString, err := os.ReadFile("testdata/projects_response.json")
if err != nil {
t.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions plugins/sinks/compass/sink.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
_ "embed"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"strings"

Expand Down Expand Up @@ -125,7 +125,7 @@ func (s *Sink) send(record RequestPayload) (err error) {
}

var bodyBytes []byte
bodyBytes, err = ioutil.ReadAll(res.Body)
bodyBytes, err = io.ReadAll(res.Body)
if err != nil {
return
}
Expand Down
6 changes: 3 additions & 3 deletions plugins/sinks/compass/sink_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"net/http"
"strings"
"testing"
Expand Down Expand Up @@ -573,7 +573,7 @@ func (m *mockHTTPClient) Do(req *http.Request) (res *http.Response, err error) {
Request: req,
Header: make(http.Header),
ContentLength: int64(len(m.ResponseJSON)),
Body: ioutil.NopCloser(bytes.NewBufferString(m.ResponseJSON)),
Body: io.NopCloser(bytes.NewBufferString(m.ResponseJSON)),
}

return
Expand All @@ -597,7 +597,7 @@ func (m *mockHTTPClient) Assert(t *testing.T) {
var bodyBytes = []byte("")
if m.req.Body != nil {
var err error
bodyBytes, err = ioutil.ReadAll(m.req.Body)
bodyBytes, err = io.ReadAll(m.req.Body)
if err != nil {
t.Error(err)
}
Expand Down
4 changes: 2 additions & 2 deletions plugins/sinks/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
_ "embed"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"strings"

Expand Down Expand Up @@ -114,7 +114,7 @@ func (s *Sink) send(payloadBytes []byte) (err error) {
}

var bodyBytes []byte
bodyBytes, err = ioutil.ReadAll(res.Body)
bodyBytes, err = io.ReadAll(res.Body)
if err != nil {
return
}
Expand Down
4 changes: 2 additions & 2 deletions plugins/sinks/stencil/stencil.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
_ "embed"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"strings"

Expand Down Expand Up @@ -173,7 +173,7 @@ func (s *Sink) send(tableURN string, record interface{}) (err error) {
}

var bodyBytes []byte
bodyBytes, err = ioutil.ReadAll(res.Body)
bodyBytes, err = io.ReadAll(res.Body)
if err != nil {
return
}
Expand Down
8 changes: 4 additions & 4 deletions plugins/sinks/stencil/stencil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/stretchr/testify/require"
"io/ioutil"
"io"
"net/http"
"testing"

"github.com/odpf/meteor/models"
v1beta2 "github.com/odpf/meteor/models/odpf/assets/v1beta2"
"github.com/odpf/meteor/plugins/sinks/stencil"
"github.com/stretchr/testify/require"
"google.golang.org/protobuf/types/known/anypb"

"github.com/odpf/meteor/plugins"
Expand Down Expand Up @@ -621,7 +621,7 @@ func (m *mockHTTPClient) Do(req *http.Request) (res *http.Response, err error) {
Request: req,
Header: make(http.Header),
ContentLength: int64(len(m.ResponseJSON)),
Body: ioutil.NopCloser(bytes.NewBufferString(m.ResponseJSON)),
Body: io.NopCloser(bytes.NewBufferString(m.ResponseJSON)),
}

return
Expand All @@ -640,7 +640,7 @@ func (m *mockHTTPClient) Assert(t *testing.T) {
var bodyBytes = []byte("")
if m.req.Body != nil {
var err error
bodyBytes, err = ioutil.ReadAll(m.req.Body)
bodyBytes, err = io.ReadAll(m.req.Body)
if err != nil {
t.Error(err)
}
Expand Down
Loading

0 comments on commit 6495614

Please sign in to comment.