From 14a2f3b25c76afd9c62ed71e2e59fdf0fc907099 Mon Sep 17 00:00:00 2001 From: Julien Fabre Date: Sun, 7 May 2023 21:34:50 -0600 Subject: [PATCH 1/5] Update to latest wasi-go --- .github/workflows/go-lint.yml | 39 ++++++++++++++++++++++++++++++++ .github/workflows/go-release.yml | 37 ++++++++++++++++++++++++++++++ .github/workflows/go-test.yml | 21 +++++++++++++++++ .golangci.yml | 38 +++++++++++++++++++++++++++++++ Dockerfile | 26 +++++++++++++++++++++ cmd/run.go | 8 +++---- go.mod | 2 +- go.sum | 4 ++-- 8 files changed, 168 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/go-lint.yml create mode 100644 .github/workflows/go-release.yml create mode 100644 .github/workflows/go-test.yml create mode 100644 .golangci.yml create mode 100644 Dockerfile diff --git a/.github/workflows/go-lint.yml b/.github/workflows/go-lint.yml new file mode 100644 index 00000000..e6ed1c77 --- /dev/null +++ b/.github/workflows/go-lint.yml @@ -0,0 +1,39 @@ +name: go-lint +on: + push: + tags: + - v* + branches: + - main + pull_request: + branches: + - main + +concurrency: + group: ${{ github.workflow }}-${{ github.event.number || github.ref }} + cancel-in-progress: true + +env: + # renovate: datasource=go depName=github.com/golangci/golangci-lint + GOLANGCI_LINT_VERSION: v1.52.2 + +jobs: + lint: + name: Go Lint + runs-on: ubuntu-latest + timeout-minutes: 30 + steps: + - uses: actions/checkout@v3 + + - name: Set up Go + uses: actions/setup-go@v3 + with: + go-version-file: .go-version + check-latest: true + cache: true + + - name: golangci-lint + uses: golangci/golangci-lint-action@v3 + with: + version: ${{ env.GOLANGCI_LINT_VERSION }} + args: --timeout 5m diff --git a/.github/workflows/go-release.yml b/.github/workflows/go-release.yml new file mode 100644 index 00000000..5545607e --- /dev/null +++ b/.github/workflows/go-release.yml @@ -0,0 +1,37 @@ +name: go-release + +on: + push: + # run only against tags + tags: + - 'v*' + +permissions: + contents: write + # packages: write + # issues: write + +jobs: + goreleaser: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - uses: actions/setup-go@v4 + with: + go-version-file: .go-version + # More assembly might be required: Docker logins, GPG, etc. It all depends + # on your needs. + - uses: goreleaser/goreleaser-action@v4 + with: + # either 'goreleaser' (default) or 'goreleaser-pro': + distribution: goreleaser + version: latest + args: release --clean + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # Your GoReleaser Pro key, if you are using the 'goreleaser-pro' + # distribution: + # GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }} diff --git a/.github/workflows/go-test.yml b/.github/workflows/go-test.yml new file mode 100644 index 00000000..fa749062 --- /dev/null +++ b/.github/workflows/go-test.yml @@ -0,0 +1,21 @@ +name: go-test + +on: + push: + branches: [ "main" ] + pull_request: + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Set up Go + uses: actions/setup-go@v3 + with: + go-version-file: .go-version + check-latest: true + + - name: Test + run: go test -v ./... diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 00000000..11b4c094 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,38 @@ +run: + deadline: 7m + timeout: 5m + go: '1.20' + +linters: + enable: + - depguard + - godot + - gofumpt + - goimports + - revive + - whitespace + +issues: + exclude-rules: + - path: _test.go + linters: + - errcheck + +linters-settings: + depguard: + list-type: blacklist + include-go-root: true + packages-with-error-message: [] + errcheck: + goimports: + local-prefixes: github.com/stealthrocket/wzprof + gofumpt: + extra-rules: true + misspell: + locale: US + revive: + rules: + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unexported-return + - name: unexported-return + severity: warning + disabled: true diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..13f0614b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,26 @@ +FROM golang:1.20-alpine as build + +RUN apk update && apk add make git gcc libc-dev curl + +WORKDIR /go/src/github.com/stealthrocket/timecraft +COPY . . + +ARG version +ARG tags +ARG gocache + +RUN go build -o timecraft + +# The last layer of the build, which determines what the final docker image +# will contain. +FROM alpine + +RUN apk update && apk add ca-certificates curl bind-tools tree + +ENV TIMECRAFT_BIND=:8080 + +EXPOSE 8080/tcp + +COPY --from=build /go/src/github.com/stealthrocket/timecraft/timecraft /usr/bin/timecraft + +ENTRYPOINT ["timecraft"] diff --git a/cmd/run.go b/cmd/run.go index 903a047c..a6bfa97e 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -10,9 +10,9 @@ import ( "time" "github.com/spf13/cobra" - "github.com/stealthrocket/wasi" - "github.com/stealthrocket/wasi/imports/wasi_snapshot_preview1" - "github.com/stealthrocket/wasi/wasiunix" + "github.com/stealthrocket/wasi-go" + "github.com/stealthrocket/wasi-go/imports/wasi_snapshot_preview1" + "github.com/stealthrocket/wasi-go/systems/unix" "github.com/stealthrocket/wazergo" "github.com/tetratelabs/wazero" "github.com/tetratelabs/wazero/sys" @@ -47,7 +47,7 @@ func run(ctx context.Context, args []string) error { environ = append(environ, "PWD="+wd) } - provider := &wasiunix.Provider{ + provider := &unix.System{ Args: append([]string{wasmName}, args[1:]...), Environ: environ, Realtime: realtime, diff --git a/go.mod b/go.mod index 3c780345..1aedcd92 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/google/go-cmp v0.5.9 github.com/klauspost/compress v1.16.5 github.com/spf13/cobra v1.7.0 - github.com/stealthrocket/wasi v0.0.0-20230504000138-9d2008307ac8 + github.com/stealthrocket/wasi-go v0.0.0-20230508014825-d291ccc8185a github.com/stealthrocket/wazergo v0.17.1 github.com/tetratelabs/wazero v1.1.0 ) diff --git a/go.sum b/go.sum index 9eda9dc7..c69ee61d 100644 --- a/go.sum +++ b/go.sum @@ -12,8 +12,8 @@ github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I= github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= -github.com/stealthrocket/wasi v0.0.0-20230504000138-9d2008307ac8 h1:WJVwrOL+OsVij6NM5vTb7iU5KoE3YgbPdD5rh4PfIm4= -github.com/stealthrocket/wasi v0.0.0-20230504000138-9d2008307ac8/go.mod h1:6GDKyiPuzLz3LJ91aGvrw9qca7XXAANIyiGMGRnujHo= +github.com/stealthrocket/wasi-go v0.0.0-20230508014825-d291ccc8185a h1:qf504FlX3/eGQgjDfCB9/uZtH/3i7w7lpx3B9bDWMfY= +github.com/stealthrocket/wasi-go v0.0.0-20230508014825-d291ccc8185a/go.mod h1:cSfmIlZZjwC6SoxMEsWVEcC2eSUQhfZQOdB99rKKAr8= github.com/stealthrocket/wazergo v0.17.1 h1:lXx4/Lg1A+9ATZWYI0J2E4oWfihhOLxWfnAT2Wy8iKQ= github.com/stealthrocket/wazergo v0.17.1/go.mod h1:riI0hxw4ndZA5e6z7PesHg2BtTftcZaMxRcoiGGipTs= github.com/tetratelabs/wazero v1.1.0 h1:EByoAhC+QcYpwSZJSs/aV0uokxPwBgKxfiokSUwAknQ= From c7c8c27ad291eac956b6a545c0d66fca5b122497 Mon Sep 17 00:00:00 2001 From: Julien Fabre Date: Mon, 8 May 2023 07:59:42 -0600 Subject: [PATCH 2/5] Add .go-version --- .go-version | 1 + 1 file changed, 1 insertion(+) create mode 100644 .go-version diff --git a/.go-version b/.go-version new file mode 100644 index 00000000..0bd54efd --- /dev/null +++ b/.go-version @@ -0,0 +1 @@ +1.20.4 From 6e4ee911a00df6c647006a0013d92661aefd4321 Mon Sep 17 00:00:00 2001 From: Julien Fabre Date: Wed, 10 May 2023 10:20:57 -0600 Subject: [PATCH 3/5] Use same build as wzprof --- .github/workflows/{go-lint.yml => build.yml} | 32 +++++++++++++++-- .github/workflows/go-release.yml | 37 -------------------- .github/workflows/go-test.yml | 21 ----------- 3 files changed, 30 insertions(+), 60 deletions(-) rename .github/workflows/{go-lint.yml => build.yml} (57%) delete mode 100644 .github/workflows/go-release.yml delete mode 100644 .github/workflows/go-test.yml diff --git a/.github/workflows/go-lint.yml b/.github/workflows/build.yml similarity index 57% rename from .github/workflows/go-lint.yml rename to .github/workflows/build.yml index e6ed1c77..ccc3afdf 100644 --- a/.github/workflows/go-lint.yml +++ b/.github/workflows/build.yml @@ -1,4 +1,4 @@ -name: go-lint +name: build on: push: tags: @@ -18,7 +18,20 @@ env: GOLANGCI_LINT_VERSION: v1.52.2 jobs: - lint: + spellcheck: + name: Spell Check + runs-on: ubuntu-latest + steps: + - name: Checkout Actions Repository + uses: actions/checkout@v2 + + - name: Check spelling of Go files + uses: crate-ci/typos@master + with: + files: '*.go' + write_changes: true + + golangci-lint: name: Go Lint runs-on: ubuntu-latest timeout-minutes: 30 @@ -37,3 +50,18 @@ jobs: with: version: ${{ env.GOLANGCI_LINT_VERSION }} args: --timeout 5m + + test: + name: Go Test + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Set up Go + uses: actions/setup-go@v3 + with: + go-version-file: .go-version + check-latest: true + + - name: Test + run: go test -v ./... diff --git a/.github/workflows/go-release.yml b/.github/workflows/go-release.yml deleted file mode 100644 index 5545607e..00000000 --- a/.github/workflows/go-release.yml +++ /dev/null @@ -1,37 +0,0 @@ -name: go-release - -on: - push: - # run only against tags - tags: - - 'v*' - -permissions: - contents: write - # packages: write - # issues: write - -jobs: - goreleaser: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - uses: actions/setup-go@v4 - with: - go-version-file: .go-version - # More assembly might be required: Docker logins, GPG, etc. It all depends - # on your needs. - - uses: goreleaser/goreleaser-action@v4 - with: - # either 'goreleaser' (default) or 'goreleaser-pro': - distribution: goreleaser - version: latest - args: release --clean - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - # Your GoReleaser Pro key, if you are using the 'goreleaser-pro' - # distribution: - # GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }} diff --git a/.github/workflows/go-test.yml b/.github/workflows/go-test.yml deleted file mode 100644 index fa749062..00000000 --- a/.github/workflows/go-test.yml +++ /dev/null @@ -1,21 +0,0 @@ -name: go-test - -on: - push: - branches: [ "main" ] - pull_request: - -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - - name: Set up Go - uses: actions/setup-go@v3 - with: - go-version-file: .go-version - check-latest: true - - - name: Test - run: go test -v ./... From 5c83878d3a876da6178d8c0fa05999166276fb67 Mon Sep 17 00:00:00 2001 From: Julien Fabre Date: Wed, 10 May 2023 11:00:16 -0600 Subject: [PATCH 4/5] allow fetching private repos --- .github/workflows/build.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ccc3afdf..7399bdac 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -38,6 +38,11 @@ jobs: steps: - uses: actions/checkout@v3 + - name: Configure git for private modules + env: + TOKEN: ${{ secrets.PAT }} + run: git config --global url."https://Pryz:${TOKEN}@github.com".insteadOf "https://github.com" + - name: Set up Go uses: actions/setup-go@v3 with: From 8a7be4644cb057e4153fba5b0042545da7e8da7c Mon Sep 17 00:00:00 2001 From: Julien Fabre Date: Wed, 10 May 2023 12:54:54 -0600 Subject: [PATCH 5/5] Use PAT for tests --- .github/workflows/build.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7399bdac..76ed5be3 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -62,6 +62,11 @@ jobs: steps: - uses: actions/checkout@v3 + - name: Configure git for private modules + env: + TOKEN: ${{ secrets.PAT }} + run: git config --global url."https://Pryz:${TOKEN}@github.com".insteadOf "https://github.com" + - name: Set up Go uses: actions/setup-go@v3 with: