From 022d48602a77ad0bf4b30fd9fdc698428cc95fa2 Mon Sep 17 00:00:00 2001 From: Jason YI Date: Sat, 7 Oct 2023 10:19:01 +0800 Subject: [PATCH] feat: add pipeline --- .dockerignore | 6 +++ .github/workflows/CODEOWNERS | 1 + .github/workflows/release.yaml | 80 +++++++++++++++++++++++++++++++++ .github/workflows/reviewdog.yml | 29 ++++++++++++ .golangci.yml | 73 ++++++++++++++++++++++++++++++ .hadolint.yaml | 14 ++++++ .releaserc.yml | 14 ++++++ .tool-versions | 3 ++ Dockerfile | 6 ++- Makefile | 33 ++++++++++++++ 10 files changed, 257 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/CODEOWNERS create mode 100644 .github/workflows/release.yaml create mode 100644 .github/workflows/reviewdog.yml create mode 100644 .golangci.yml create mode 100644 .hadolint.yaml create mode 100644 .releaserc.yml create mode 100644 .tool-versions create mode 100644 Makefile diff --git a/.dockerignore b/.dockerignore index 9d3a1ea..cd716f6 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,3 +1,9 @@ nodes.json enrtree-info.json all.json +Dockerfile +CHANGELOG.md +README.md + +.git +.github \ No newline at end of file diff --git a/.github/workflows/CODEOWNERS b/.github/workflows/CODEOWNERS new file mode 100644 index 0000000..f730290 --- /dev/null +++ b/.github/workflows/CODEOWNERS @@ -0,0 +1 @@ +* @jasonyic \ No newline at end of file diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..b1aee96 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,80 @@ +name: release + +permissions: + id-token: write + contents: write + issues: write + pull-requests: write + +on: + push: + branches: + - "main" + - "release-**" + +env: + DOCKER_REGISTRY: ${{ secrets.DOCKER_REGISTRY }} + +jobs: + release: + name: release + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + with: + persist-credentials: false + + - name: Semantic Release Version + id: semantic + uses: cycjimmy/semantic-release-action@v3 + with: + extra_plugins: | + @semantic-release/changelog@6.0.2 + @semantic-release/git@10.0.1 + dry_run: true + env: + GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }} + + - name: Build discv4-crawl + if: steps.semantic.outputs.new_release_version != '' + run: make build + env: + VERSION: ${{ steps.semantic.outputs.new_release_version }} + + - name: Set up Docker Buildx + if: steps.semantic.outputs.new_release_version != '' + uses: docker/setup-buildx-action@v2 + + - name: Set up QEMU + if: steps.semantic.outputs.new_release_version != '' + uses: docker/setup-qemu-action@v2 + + - name: Login to Docker Registry + if: steps.semantic.outputs.new_release_version != '' + uses: docker/login-action@v1 + with: + registry: ${{ env.DOCKER_REGISTRY }} + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Build & Publish image + if: steps.semantic.outputs.new_release_version != '' + uses: docker/build-push-action@v3 + with: + context: . + tags: ${{env.DOCKER_REGISTRY}}/staking/discv4-crawl:${{ steps.semantic.outputs.new_release_version }} + push: true + platforms: linux/amd64,linux/arm64 + cache-from: type=gha + #cache-to: type=gha,mode=max + + - name: Semantic Release + if: steps.semantic.outputs.new_release_version != '' + uses: cycjimmy/semantic-release-action@v3 + with: + extra_plugins: | + @semantic-release/changelog@6.0.2 + @semantic-release/git@10.0.1 + env: + GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/reviewdog.yml b/.github/workflows/reviewdog.yml new file mode 100644 index 0000000..71b9577 --- /dev/null +++ b/.github/workflows/reviewdog.yml @@ -0,0 +1,29 @@ +name: reviewdog + +on: + push: + branches: + - main + - beta + pull_request: + types: + - opened + - synchronize + - reopened + - labeled + +jobs: + hadolint: + name: hadolint + runs-on: ubuntu-latest + + if: github.actor != 'dependabot[bot]' || contains(github.event.pull_request.labels.*.name, 'safe-to-test') + steps: + - uses: actions/checkout@v3 + + - name: hadolint + uses: reviewdog/action-hadolint@v1 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + reporter: github-check + fail_on_error: true diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..1f5365b --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,73 @@ +linters-settings: + govet: + settings: + printf: + funcs: + - (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof + - (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf + - (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf + - (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf + revive: + min-confidence: 0 + gocyclo: + min-complexity: 10 + maligned: + suggest-new: true + dupl: + threshold: 100 + goconst: + min-len: 5 + min-occurrences: 2 + depguard: + list-type: blacklist + packages: + # logging is allowed only by logutils.Log, logrus + # is allowed to use only in logutils package + - github.com/sirupsen/logrus + misspell: + locale: US + lll: + line-length: 140 + gocritic: + enabled-tags: + - performance + - style + - experimental + disabled-checks: + - wrapperFunc + - hugeParam + +linters: + enable: + - goconst + - gocritic + - revive + - govet + - misspell + - stylecheck + - unconvert + - unparam + - gofmt + disable: + - gochecknoinits + +issues: + max-same-issues: 10 + exclude-use-default: true + +run: + deadline: 20m + skip-dirs: + - .gocache + - pkg/go-ethereum + - build + - public + - mock + - scripts + - vendor + - tests + skip-files: + - ".*\\.pb(\\.gw)?\\.go$" + - ".*_test.go$" + - pkg/toolkit/app/http/handler/dashboard/genstatic/gen.go + - pkg/toolkit/app/http/handler/swagger/genstatic/gen.go diff --git a/.hadolint.yaml b/.hadolint.yaml new file mode 100644 index 0000000..7d0523e --- /dev/null +++ b/.hadolint.yaml @@ -0,0 +1,14 @@ +ignored: + - DL3018 + - DL3025 + - DL3008 + - DL4006 + - DL3003 + - DL3015 + - SC2086 + - SC1091 + - DL4001 + - SC2046 + +trustedRegistries: + - docker.io \ No newline at end of file diff --git a/.releaserc.yml b/.releaserc.yml new file mode 100644 index 0000000..ff70057 --- /dev/null +++ b/.releaserc.yml @@ -0,0 +1,14 @@ +branches: + - main + - name: beta-* + prerelease: true + - name: alpha-* + prerelease: true +plugins: + - "@semantic-release/commit-analyzer" + - "@semantic-release/release-notes-generator" + - "@semantic-release/changelog" + - - "@semantic-release/github" + - assets: + - "build/discv4-crawl" + - "@semantic-release/git" diff --git a/.tool-versions b/.tool-versions new file mode 100644 index 0000000..e2ba0f0 --- /dev/null +++ b/.tool-versions @@ -0,0 +1,3 @@ +golang 1.20.7 +golangci-lint 1.52.2 +ginkgo 2.1.3 diff --git a/Dockerfile b/Dockerfile index 1d84802..2d563c6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:latest +FROM golang:1.21 ENV CRAWL_GIT_REPO=https://github.com/skylenet/discv4-dns-lists.git \ CRAWL_GIT_BRANCH=master \ @@ -25,7 +25,9 @@ ENV CRAWL_GIT_REPO=https://github.com/skylenet/discv4-dns-lists.git \ PROMETHEUS_METRICS_ENABLED=true \ PROMETHEUS_METRICS_LISTEN=0.0.0.0:9100 -RUN apt-get update && apt-get install -y --no-install-recommends git curl jq +RUN apt-get update \ + && apt-get install -y --no-install-recommends git curl jq \ + && rm -rf /var/lib/apt/lists/* EXPOSE 9100 WORKDIR /crawler diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..7503d4e --- /dev/null +++ b/Makefile @@ -0,0 +1,33 @@ +SHELL := bash +.SHELLFLAGS := -eu -o pipefail -c +.ONESHELL: +MAKEFLAGS += --warn-undefined-variables +MAKEFLAGS += --no-builtin-rules + + +lint: + golangci-lint run + +lint-fix: + golangci-lint run --fix + +.PHONY: vendor +vendor: + go mod tidy + go mod vendor + go mod download + +build-dirs: + @mkdir -p build + +asdf-bootstrap: + asdf plugin update --all + asdf plugin-add golang https://github.com/kennyp/asdf-golang.git || true + asdf plugin-add golangci-lint https://github.com/hypnoglow/asdf-golangci-lint.git || true + asdf plugin-add ginkgo https://github.com/jimmidyson/asdf-ginkgo.git || true + NODEJS_CHECK_SIGNATURES=no asdf install + +.PHONY: docker +docker: + # for multiple platform: --platform linux/amd64,linux/arm64 + docker buildx build -t staking/discv4-crawl . --load