From 91eca407c502d18761bbfe2fd2a32f459aad3010 Mon Sep 17 00:00:00 2001 From: Toni Spets Date: Fri, 15 Dec 2023 21:36:37 +0200 Subject: [PATCH] Add pre-commit linting, test all PRs --- .github/CONTRIBUTING.md | 1 - .github/workflows/commit.yml | 38 ++++++++++++++++++++++++---- .github/workflows/release.docker.yml | 6 ++--- .github/workflows/release.linux.yml | 6 ++--- .pre-commit-config.yaml | 20 +++++++++++++++ LICENSE | 2 +- README.md | 1 - cmd/litestream/generations.go | 2 +- cmd/litestream/main_windows.go | 2 ++ cmd/litestream/replicate.go | 2 +- etc/litestream.wxs | 4 +-- etc/litestream.yml | 1 - 12 files changed, 66 insertions(+), 19 deletions(-) create mode 100644 .pre-commit-config.yaml diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index b1cf4525..17262da7 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -15,4 +15,3 @@ If you find mistakes in the documentation, please submit a fix to the [new-issue]: https://github.com/benbjohnson/litestream/issues/new [docs]: https://github.com/benbjohnson/litestream.io - diff --git a/.github/workflows/commit.yml b/.github/workflows/commit.yml index 4179b570..52f639c8 100644 --- a/.github/workflows/commit.yml +++ b/.github/workflows/commit.yml @@ -1,14 +1,42 @@ -on: push +on: + push: + pull_request: + types: + - opened + - synchronize + - reopened + +env: + GO_VERSION: "1.21" jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-go@v4 + with: + go-version: ${{ env.GO_VERSION }} + cache: true + + - run: | + go install golang.org/x/tools/cmd/goimports@latest + go install honnef.co/go/tools/cmd/staticcheck@latest + export PATH="$HOME/go/bin:$PATH" + + - uses: pre-commit/action@v3.0.0 + build: name: Build & Unit Test runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions/setup-go@v2 + - uses: actions/checkout@v4 + + - uses: actions/setup-go@v4 with: - go-version: '1.21' + go-version: ${{ env.GO_VERSION }} + - uses: actions/cache@v2 with: path: ~/go/pkg/mod @@ -36,7 +64,7 @@ jobs: # steps: # - uses: actions/checkout@v2 # - uses: actions/setup-go@v2 -# with: +# with: # go-version: '1.20' # - uses: actions/cache@v2 # with: diff --git a/.github/workflows/release.docker.yml b/.github/workflows/release.docker.yml index bf492451..f210171d 100644 --- a/.github/workflows/release.docker.yml +++ b/.github/workflows/release.docker.yml @@ -27,7 +27,7 @@ jobs: with: username: benbjohnson password: ${{ secrets.DOCKERHUB_TOKEN }} - + - id: meta uses: docker/metadata-action@v3 with: @@ -39,7 +39,7 @@ jobs: type=sha,format=long type=semver,pattern={{version}} type=semver,pattern={{major}}.{{minor}} - + - uses: docker/build-push-action@v2 with: context: . @@ -48,4 +48,4 @@ jobs: tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} build-args: | - LITESTREAM_VERSION=${{ env.VERSION }} \ No newline at end of file + LITESTREAM_VERSION=${{ env.VERSION }} diff --git a/.github/workflows/release.linux.yml b/.github/workflows/release.linux.yml index 73f06e13..3c4ec9ad 100644 --- a/.github/workflows/release.linux.yml +++ b/.github/workflows/release.linux.yml @@ -40,7 +40,7 @@ jobs: - name: Install cross-compilers run: | - sudo apt-get update + sudo apt-get update sudo apt-get install -y gcc-aarch64-linux-gnu gcc-arm-linux-gnueabihf gcc-arm-linux-gnueabi - name: Install nfpm @@ -55,10 +55,10 @@ jobs: cp etc/litestream.yml etc/litestream.service dist cat etc/nfpm.yml | LITESTREAM_VERSION=${{ steps.release.outputs.tag_name }} envsubst > dist/nfpm.yml CGO_ENABLED=1 go build -ldflags "-s -w -extldflags "-static" -X 'main.Version=${{ steps.release.outputs.tag_name }}'" -tags osusergo,netgo,sqlite_omit_load_extension -o dist/litestream ./cmd/litestream - + cd dist tar -czvf litestream-${{ steps.release.outputs.tag_name }}-${{ env.GOOS }}-${{ env.GOARCH }}${{ env.GOARM }}.tar.gz litestream - ../nfpm pkg --config nfpm.yml --packager deb --target litestream-${{ steps.release.outputs.tag_name }}-${{ env.GOOS }}-${{ env.GOARCH }}${{ env.GOARM }}.deb + ../nfpm pkg --config nfpm.yml --packager deb --target litestream-${{ steps.release.outputs.tag_name }}-${{ env.GOOS }}-${{ env.GOARCH }}${{ env.GOARM }}.deb - name: Upload release tarball uses: actions/upload-release-asset@v1.0.2 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..5004215c --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,20 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.1.0 + hooks: + - id: trailing-whitespace + exclude_types: [markdown] + - id: end-of-file-fixer + - id: check-yaml + - id: check-added-large-files + + - repo: https://github.com/tekwizely/pre-commit-golang + rev: v1.0.0-beta.5 + hooks: + - id: go-imports-repo + args: + - "-local" + - "github.com/benbjohnson/litestrem" + - "-w" + - id: go-vet-repo-mod +# - id: go-staticcheck-repo-mod diff --git a/LICENSE b/LICENSE index 7a4a3ea2..d6456956 100644 --- a/LICENSE +++ b/LICENSE @@ -199,4 +199,4 @@ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and - limitations under the License. \ No newline at end of file + limitations under the License. diff --git a/README.md b/README.md index 84d6e4e8..ded66ad4 100644 --- a/README.md +++ b/README.md @@ -58,4 +58,3 @@ If you find mistakes in the documentation, please submit a fix to the [new-issue]: https://github.com/benbjohnson/litestream/issues/new [docs]: https://github.com/benbjohnson/litestream.io - diff --git a/cmd/litestream/generations.go b/cmd/litestream/generations.go index 56754e28..2b0e1775 100644 --- a/cmd/litestream/generations.go +++ b/cmd/litestream/generations.go @@ -121,7 +121,7 @@ cover. Usage: litestream generations [arguments] DB_PATH - + litestream generations [arguments] REPLICA_URL Arguments: diff --git a/cmd/litestream/main_windows.go b/cmd/litestream/main_windows.go index 0f6c1c2b..be7e7dd3 100644 --- a/cmd/litestream/main_windows.go +++ b/cmd/litestream/main_windows.go @@ -5,6 +5,8 @@ package main import ( "context" "io" + "log" + "log/slog" "os" "os/signal" diff --git a/cmd/litestream/replicate.go b/cmd/litestream/replicate.go index 988407c7..7c9b4f30 100644 --- a/cmd/litestream/replicate.go +++ b/cmd/litestream/replicate.go @@ -181,7 +181,7 @@ func (c *ReplicateCommand) Close() (err error) { // Usage prints the help screen to STDOUT. func (c *ReplicateCommand) Usage() { fmt.Printf(` -The replicate command starts a server to monitor & replicate databases. +The replicate command starts a server to monitor & replicate databases. You can specify your database & replicas in a configuration file or you can replicate a single database file by specifying its path and its replicas in the command line arguments. diff --git a/etc/litestream.wxs b/etc/litestream.wxs index 034c9661..5246cb0c 100644 --- a/etc/litestream.wxs +++ b/etc/litestream.wxs @@ -26,9 +26,9 @@ Description="Litestream $(var.Version) installer" Compressed="yes" /> - + - +