Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maintenance/GitHub actions #58

Merged
merged 5 commits into from
Feb 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 26 additions & 17 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,16 @@ jobs:

steps:
- name: Install Go
uses: actions/setup-go@v1
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}

- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Print Go version and environment
id: vars
shell: bash
run: |
printf "Using go at: $(which go)\n"
printf "Go version: $(go version)\n"
Expand All @@ -56,11 +57,11 @@ jobs:
printf "\n\nSystem environment:\n\n"
env
# Calculate the short SHA1 hash of the git commit
echo "::set-output name=short_sha::$(git rev-parse --short HEAD)"
echo "::set-output name=go_cache::$(go env GOCACHE)"
echo "short_sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
echo "go_cache=$(go env GOCACHE)" >> $GITHUB_OUTPUT

- name: Cache the build cache
uses: actions/cache@v1
uses: actions/cache@v3
with:
path: ${{ steps.vars.outputs.go_cache }}
key: ${{ runner.os }}-go-ci-${{ hashFiles('**/go.sum') }}
Expand All @@ -79,7 +80,7 @@ jobs:
go build -trimpath -ldflags="-w -s" -v

- name: Publish Build Artifact
uses: actions/upload-artifact@v1
uses: actions/upload-artifact@v3
with:
name: xk6_${{ runner.os }}_${{ steps.vars.outputs.short_sha }}
path: ${{ matrix.XK6_BIN_PATH }}
Expand All @@ -88,28 +89,36 @@ 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
steps:
- name: checkout
uses: actions/checkout@v2
- uses: goreleaser/goreleaser-action@v1
uses: actions/checkout@v3
- uses: goreleaser/goreleaser-action@v4
with:
version: latest
version: v1.13.1
args: check
env:
TAG: ${{ steps.vars.outputs.short_sha }}
15 changes: 8 additions & 7 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,32 @@ jobs:

steps:
- name: Install Go
uses: actions/setup-go@v1
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}

- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3

# So GoReleaser can generate the changelog properly
- name: Unshallowify the repo clone
run: git fetch --prune --unshallow

- name: Print Go version and environment
id: vars
shell: bash
run: |
printf "Using go at: $(which go)\n"
printf "Go version: $(go version)\n"
printf "\n\nGo environment:\n\n"
go env
printf "\n\nSystem environment:\n\n"
env
echo "::set-output name=short_sha::$(git rev-parse --short HEAD)"
echo "::set-output name=go_cache::$(go env GOCACHE)"
echo "short_sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
echo "go_cache=$(go env GOCACHE)" >> $GITHUB_OUTPUT

- name: Cache the build cache
uses: actions/cache@v1
uses: actions/cache@v3
with:
path: ${{ steps.vars.outputs.go_cache }}
key: ${{ runner.os }}-go-release-${{ hashFiles('**/go.sum') }}
Expand All @@ -49,9 +50,9 @@ jobs:

# GoReleaser will take care of publishing those artifacts into the release
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v1
uses: goreleaser/goreleaser-action@v4
with:
version: latest
version: v1.13.1
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
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
7 changes: 3 additions & 4 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 Expand Up @@ -260,7 +259,7 @@ func (env environment) runCommand(ctx context.Context, cmd *exec.Cmd, timeout ti
// to the child process, so wait for it to die
select {
case <-time.After(15 * time.Second):
cmd.Process.Kill()
_ = cmd.Process.Kill()
case <-cmdErrChan:
}
return ctx.Err()
Expand Down