Skip to content

Commit

Permalink
Use the golangci-lint CI action
Browse files Browse the repository at this point in the history
Replace the action with the official one, and also fixes chore linter
issues like deprecated `ioutil` usages.
  • Loading branch information
olegbespalov committed Jan 23, 2023
1 parent 88e75f7 commit 94a7bde
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 14 deletions.
24 changes: 16 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,27 @@ jobs:
run: |
go test -v -coverprofile="cover-profile.out" -short -race ./...
# From https://github.com/reviewdog/action-golangci-lint
golangci-lint:
name: runner / golangci-lint
runs-on: ubuntu-latest
steps:
- name: Checkout code into the Go module directory
uses: actions/checkout@v2

- name: Run golangci-lint
uses: reviewdog/action-golangci-lint@v1
# uses: docker://reviewdog/action-golangci-lint:v1 # pre-build docker image
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Install Go
uses: actions/setup-go@v3
with:
go-version: 1.19.x
check-latest: true
- name: Retrieve golangci-lint version
run: |
echo "Version=$(head -n 1 "${GITHUB_WORKSPACE}/.golangci.yml" | tr -d '# ')" >> $GITHUB_OUTPUT
id: version
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
github_token: ${{ secrets.github_token }}
version: ${{ steps.version.outputs.Version }}

goreleaser-check:
runs-on: ubuntu-latest
Expand Down
2 changes: 2 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# v1.50.1
# Please don't remove the first line. It uses in CI to determine the golangci version
linters-settings:
errcheck:
ignore: fmt:.*,io/ioutil:^Read.*
Expand Down
5 changes: 2 additions & 3 deletions builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package xk6
import (
"context"
"fmt"
"io/ioutil"
"log"
"os"
"path"
Expand Down Expand Up @@ -109,7 +108,7 @@ func (b Builder) Build(ctx context.Context, outputFile string) error {
cmd := buildEnv.newCommand("go",
buildFlagsSlice...,
)
//dont add raceArg again if it already in place
// dont add raceArg again if it already in place
if b.RaceDetector && !strings.Contains(buildFlags, raceArg) {
cmd.Args = append(cmd.Args, raceArg)
}
Expand Down Expand Up @@ -213,7 +212,7 @@ func newTempFolder() (string, error) {
}
}
ts := time.Now().Format(yearMonthDayHourMin)
return ioutil.TempDir(parentDir, fmt.Sprintf("buildenv_%s.", ts))
return os.MkdirTemp(parentDir, fmt.Sprintf("buildenv_%s.", ts))
}

// versionedModulePath helps enforce Go Module's Semantic Import Versioning (SIV) by
Expand Down
5 changes: 2 additions & 3 deletions environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"context"
"fmt"
"html/template"
"io/ioutil"
"log"
"os"
"os/exec"
Expand Down Expand Up @@ -160,7 +159,7 @@ nextExt:
// we do this last so we get the needed versions from all the replacements and extensions instead of k6 if possible
mainPath := filepath.Join(tempFolder, "main.go")
log.Printf("[INFO] Writing main module: %s", mainPath)
err = ioutil.WriteFile(mainPath, buf.Bytes(), 0o600)
err = os.WriteFile(mainPath, buf.Bytes(), 0o600)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -210,7 +209,7 @@ func (env environment) writeExtensionImportFile(packagePath string) error {
import _ %q
`, packagePath)
filePath := filepath.Join(env.tempFolder, strings.ReplaceAll(packagePath, "/", "_")+".go")
return ioutil.WriteFile(filePath, []byte(fileContents), 0o600)
return os.WriteFile(filePath, []byte(fileContents), 0o600)
}

func (env environment) newCommand(command string, args ...string) *exec.Cmd {
Expand Down

0 comments on commit 94a7bde

Please sign in to comment.