From e5721ab35bda4108887d63a853d741d1baf67c77 Mon Sep 17 00:00:00 2001 From: Euan Kemp Date: Wed, 24 Jul 2024 06:16:57 +0000 Subject: [PATCH] .github: update workflows to use flake.nix go version etc And also run lints. This is cribbed from the ngrok-go repo --- .envrc | 7 +++++++ .github/workflows/go.yml | 25 ------------------------- .github/workflows/lint.yml | 30 ++++++++++++++++++++++++++++++ .github/workflows/test.yml | 22 ++++++++++++++++++++++ .gitignore | 1 + dup_file.go | 1 + dup_file_legacy.go | 1 + 7 files changed, 62 insertions(+), 25 deletions(-) create mode 100644 .envrc delete mode 100644 .github/workflows/go.yml create mode 100644 .github/workflows/lint.yml create mode 100644 .github/workflows/test.yml create mode 100644 .gitignore diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..29601f8 --- /dev/null +++ b/.envrc @@ -0,0 +1,7 @@ +if ! has nix_direnv_version || ! nix_direnv_version 2.2.0; then + source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/2.2.0/direnvrc" "sha256-5EwyKnkJNQeXrRkYbwwRBcXbibosCJqyIUuz9Xq+LRc=" +fi +dotenv_if_exists +GOPATH=`pwd`/.direnv/go +PATH=${GOPATH}/bin:${PATH} +use flake diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml deleted file mode 100644 index ce0ad4a..0000000 --- a/.github/workflows/go.yml +++ /dev/null @@ -1,25 +0,0 @@ -name: Go - -on: - push: - branches: [ master ] - pull_request: - branches: [ master ] - -jobs: - - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - - name: Set up Go - uses: actions/setup-go@v2 - with: - go-version: 1.16 - - - name: Build - run: go build -v ./... - - - name: Test - run: go test -race -v ./... diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..c7e4a3b --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,30 @@ +name: lint +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] +permissions: + contents: read + # Optional: allow read access to pull request. Use with `only-new-issues` option. + # pull-requests: read +jobs: + lint: + name: lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 2 + - uses: cachix/install-nix-action@v18 + - uses: HatsuneMiku3939/direnv-action@v1 + - name: direnv allow + run: direnv allow . + - name: Run goimports + shell: bash + run: direnv exec . goimports -format-only -w -local github.com/ngrok/tableroll **/*.go + - name: Lint + run: direnv exec . golangci-lint run . + - name: Check diff + shell: bash + run: git diff --exit-code diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..7209c7f --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,22 @@ +name: Go +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] +jobs: + build-and-test: + runs-on: ubuntu-latest + env: + NGROK_TEST_ONLINE: 1 + NGROK_TEST_LONG: 1 + NGROK_TEST_FLAKEY: 1 + NGROK_AUTHTOKEN: ${{ secrets.NGROK_AUTHTOKEN }} + steps: + - uses: actions/checkout@v3 + - uses: cachix/install-nix-action@v18 + - uses: HatsuneMiku3939/direnv-action@v1 + - name: direnv allow + run: direnv allow . + - name: Test + run: direnv exec . go test -v ./... diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7ad6275 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/.direnv diff --git a/dup_file.go b/dup_file.go index c48e7d1..476c33a 100644 --- a/dup_file.go +++ b/dup_file.go @@ -1,3 +1,4 @@ +//go:build go1.12 // +build go1.12 package tableroll diff --git a/dup_file_legacy.go b/dup_file_legacy.go index 57ce1b8..06161e4 100644 --- a/dup_file_legacy.go +++ b/dup_file_legacy.go @@ -1,3 +1,4 @@ +//go:build !go1.12 // +build !go1.12 package tableroll