From 3bb60e8e528abf025f6ead137a93729ba96b29ae Mon Sep 17 00:00:00 2001 From: Manav Aggarwal Date: Tue, 24 Oct 2023 15:04:25 +0200 Subject: [PATCH] Init --- .github/auto_request_review.yml | 32 ++++++++++++ .github/dependabot.yml | 23 +++++++++ .github/workflows/ci_release.yml | 49 ++++++++++++++++++ .github/workflows/housekeeping.yml | 77 +++++++++++++++++++++++++++++ .github/workflows/lint.yml | 48 ++++++++++++++++++ .github/workflows/test.yml | 52 ++++++++++++++++++++ .golangci.yml | 41 ++++++++++++++++ .markdownlint.yaml | 6 +++ Makefile | 79 ++++++++++++++++++++++++++++++ NOTICE | 2 + go.mod | 3 ++ 11 files changed, 412 insertions(+) create mode 100644 .github/auto_request_review.yml create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/ci_release.yml create mode 100644 .github/workflows/housekeeping.yml create mode 100644 .github/workflows/lint.yml create mode 100644 .github/workflows/test.yml create mode 100644 .golangci.yml create mode 100644 .markdownlint.yaml create mode 100644 Makefile create mode 100644 NOTICE create mode 100644 go.mod diff --git a/.github/auto_request_review.yml b/.github/auto_request_review.yml new file mode 100644 index 0000000..a31206d --- /dev/null +++ b/.github/auto_request_review.yml @@ -0,0 +1,32 @@ +reviewers: + defaults: + - code-owners + groups: + code-owners: + - Nashqueue + - tzdybal + - gupadhyaya + rollkit: + - Manav-Aggarwal + - S1nus + - tuxcanfly + devops: + - smuu + - sysrex + - jrmanes + - Bidon15 + celestia: + - team:celestia +files: + '**': + - code-owners + - rollkit + '**/*Dockerfile': + - devops + '.github/**': + - devops +options: + ignore_draft: true + ignored_keywords: + - WIP + number_of_reviewers: 3 diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..14c2668 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,23 @@ +version: 2 +updates: + - package-ecosystem: github-actions + directory: "/" + schedule: + interval: daily + open-pull-requests-limit: 10 + labels: + - T:dependencies + - package-ecosystem: gomod + directory: "/" + schedule: + interval: weekly + open-pull-requests-limit: 10 + labels: + - T:dependencies + - package-ecosystem: docker + directory: "/docker" + schedule: + interval: weekly + open-pull-requests-limit: 10 + labels: + - T:dependencies diff --git a/.github/workflows/ci_release.yml b/.github/workflows/ci_release.yml new file mode 100644 index 0000000..2fc6ebf --- /dev/null +++ b/.github/workflows/ci_release.yml @@ -0,0 +1,49 @@ +name: CI and Release +on: + push: + branches: + - main + # Trigger on version tags + tags: + - 'v[0-9]+\.[0-9]+\.[0-9]+' + - 'v[0-9]+\.[0-9]+\.[0-9]+-rc(?:[0-9]+|\.[0-9]+)' + pull_request: + merge_group: + workflow_dispatch: + # Inputs the workflow accepts. + inputs: + version: + # Friendly description to be shown in the UI instead of 'name' + description: "Semver type of new version (major / minor / patch)" + # Input has to be provided for the workflow to run + required: true + type: choice + options: + - patch + - minor + - major + +jobs: + lint: + uses: ./.github/workflows/lint.yml + with: + GO_VERSION: "1.21" + + test: + uses: ./.github/workflows/test.yml + with: + GO_VERSION: "1.21" + + # Make a release if this is a manually trigger job, i.e. workflow_dispatch + release: + needs: [lint, test] + runs-on: ubuntu-latest + if: ${{ github.event_name == 'workflow_dispatch' }} + permissions: "write-all" + steps: + - uses: actions/checkout@v4 + - name: Version Release + uses: rollkit/.github/.github/actions/version-release@v0.2.2 + with: + github-token: ${{secrets.GITHUB_TOKEN}} + version-bump: ${{inputs.version}} diff --git a/.github/workflows/housekeeping.yml b/.github/workflows/housekeeping.yml new file mode 100644 index 0000000..a0d984c --- /dev/null +++ b/.github/workflows/housekeeping.yml @@ -0,0 +1,77 @@ +name: Housekeeping + +on: + issues: + types: [opened] + pull_request_target: + types: [opened] + +jobs: + issue-management: + if: ${{ github.event.issue }} + name: Add issues to project and add triage label + uses: rollkit/.github/.github/workflows/reusable_housekeeping.yml@v0.2.2 + secrets: inherit + permissions: + issues: write + pull-requests: write + with: + run-labels: true + labels-to-add: "needs-triage" + run-projects: true + project-url: https://github.com/orgs/rollkit/projects/7 + + add-pr-to-project: + # ignore dependabot PRs + if: ${{ github.event.pull_request && github.actor != 'dependabot[bot]' }} + name: Add PRs to project + uses: rollkit/.github/.github/workflows/reusable_housekeeping.yml@v0.2.2 + secrets: inherit + permissions: + issues: write + pull-requests: write + with: + run-projects: true + project-url: https://github.com/orgs/rollkit/projects/7 + + auto-add-reviewer: + name: Auto add reviewer to PR + if: github.event.pull_request + uses: rollkit/.github/.github/workflows/reusable_housekeeping.yml@v0.2.2 + secrets: inherit + permissions: + issues: write + pull-requests: write + with: + run-auto-request-review: true + + auto-add-assignee: + # ignore dependabot PRs + if: ${{ github.event.pull_request && github.actor != 'dependabot[bot]' }} + name: Assign issue and PR to creator + runs-on: ubuntu-latest + permissions: + issues: write + pull-requests: write + steps: + - name: Set pull_request url and creator login + # yamllint disable rule:line-length + run: | + echo "PR=${{ github.event.pull_request.html_url }}" >> $GITHUB_ENV + echo "CREATOR=${{ github.event.pull_request.user.login }}" >> $GITHUB_ENV + # yamllint enable rule:line-length + - name: Assign PR to creator + run: gh pr edit ${{ env.PR }} --add-assignee ${{ env.CREATOR }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + required-labels: + # ignore dependabot PRs + if: ${{ github.actor != 'dependabot[bot]' }} + runs-on: ubuntu-latest + steps: + - uses: mheap/github-action-required-labels@v5 + with: + mode: minimum + count: 1 + labels: "T:enhancement, T:documentation, T:code-hygiene, T:bug, T:adr, T:sdk, T:testing, T:question, T:dependencies, T:spec-and-docs, T:da-integration, T:dev-usability-and-ux" # yamllint disable-line rule:line-length diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..e109ec7 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,48 @@ +# lint runs all linters in this repository +# This workflow is triggered by ci_release.yml workflow +name: lint +on: + workflow_call: + inputs: + GO_VERSION: + description: 'Go version to use' + type: string + required: true + +jobs: + golangci-lint: + name: golangci-lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v4 + with: + go-version: ${{ inputs.GO_VERSION }} + # This steps sets the GIT_DIFF environment variable to true + # if files defined in PATTERS changed + - uses: technote-space/get-diff-action@v6.1.2 + with: + # This job will pass without running if go.mod, go.sum, and *.go + # wasn't modified. + PATTERNS: | + **/**.go + go.mod + go.sum + - uses: golangci/golangci-lint-action@v3.7.0 + with: + version: latest + args: --timeout 10m + github-token: ${{ secrets.github_token }} + if: env.GIT_DIFF + + yamllint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: rollkit/.github/.github/actions/yamllint@v0.2.2 + + markdown-lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: rollkit/.github/.github/actions/markdown-lint@v0.2.2 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..41dd6b8 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,52 @@ +# Tests / Code Coverage workflow +# This workflow is triggered by ci_release.yml workflow +name: Tests / Code Coverage +on: + workflow_call: + inputs: + GO_VERSION: + description: "Go version to use" + type: string + required: true + +jobs: + go_mod_tidy_check: + name: Go Mod Tidy Check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v4 + with: + go-version: ${{ inputs.GO_VERSION }} + - run: go mod tidy + - name: check for diff + run: git diff --exit-code + + unit_test: + name: Run Unit Tests + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: set up go + uses: actions/setup-go@v4 + with: + go-version: ${{ inputs.GO_VERSION }} + - name: Run unit test + run: make test + - name: upload coverage report + uses: codecov/codecov-action@v3.1.4 + with: + token: ${{ secrets.CODECOV_TOKEN }} + file: ./coverage.txt + + integration_test: + name: Run Integration Tests + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: set up go + uses: actions/setup-go@v4 + with: + go-version: ${{ inputs.GO_VERSION }} + - name: Integration Tests + run: echo "No integration tests yet" diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..690483b --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,41 @@ +run: + timeout: 5m + modules-download-mode: readonly + +linters: + enable: + - deadcode + - errcheck + - gofmt + - goimports + - gosec + - gosimple + - govet + - ineffassign + - misspell + - revive + - staticcheck + - structcheck + - typecheck + - unused + - varcheck + +issues: + exclude-use-default: false + include: + - EXC0012 # EXC0012 revive: Annoying issue about not having a comment. + - EXC0014 # EXC0014 revive: Annoying issue about not having a comment. + +linters-settings: + revive: + rules: + - name: package-comments + disabled: true + - name: duplicated-imports + severity: warning + - name: exported + arguments: + - disableStutteringCheck + + goimports: + local-prefixes: github.com/rollkit diff --git a/.markdownlint.yaml b/.markdownlint.yaml new file mode 100644 index 0000000..6369b8d --- /dev/null +++ b/.markdownlint.yaml @@ -0,0 +1,6 @@ +default: true +MD010: + code_blocks: false +MD013: false +MD024: + allow_different_nesting: true diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..9c668cc --- /dev/null +++ b/Makefile @@ -0,0 +1,79 @@ +DOCKER := $(shell which docker) +DOCKER_BUF := $(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace bufbuild/buf + +# Define pkgs, run, and cover vairables for test so that we can override them in +# the terminal more easily. +pkgs := $(shell go list ./...) +run := . +count := 1 + +## help: Show this help message +help: Makefile + @echo " Choose a command run in "$(PROJECTNAME)":" + @sed -n 's/^##//p' $< | column -t -s ':' | sed -e 's/^/ /' +.PHONY: help + +## clean: clean testcache +clean: + @echo "--> Clearing testcache" + @go clean --testcache +.PHONY: clean + +## cover: generate to code coverage report. +cover: + @echo "--> Generating Code Coverage" + @go install github.com/ory/go-acc@latest + @go-acc -o coverage.txt $(pkgs) +.PHONY: cover + +## deps: Install dependencies +deps: + @echo "--> Installing dependencies" + @go mod download +# @make proto-gen + @go mod tidy +.PHONY: deps + +## lint: Run linters golangci-lint and markdownlint. +lint: vet + @echo "--> Running golangci-lint" + @golangci-lint run + @echo "--> Running markdownlint" + @markdownlint --config .markdownlint.yaml '**/*.md' + @echo "--> Running hadolint" + @hadolint docker/mockserv.Dockerfile + @echo "--> Running yamllint" + @yamllint --no-warnings . -c .yamllint.yml + +.PHONY: lint + +## fmt: Run fixes for linters. Currently only markdownlint. +fmt: + @echo "--> Formatting markdownlint" + @markdownlint --config .markdownlint.yaml '**/*.md' -f +.PHONY: fmt + +## vet: Run go vet +vet: + @echo "--> Running go vet" + @go vet $(pkgs) +.PHONY: vet + +## test: Running unit tests +test: vet + @echo "--> Running unit tests" + @go test -v -race -covermode=atomic -coverprofile=coverage.txt $(pkgs) -run $(run) -count=$(count) +.PHONY: test + +### proto-gen: Generate protobuf files. Requires docker. +#proto-gen: +# @echo "--> Generating Protobuf files" +# ./proto/get_deps.sh +# ./proto/gen.sh +#.PHONY: proto-gen +# +### proto-lint: Lint protobuf files. Requires docker. +#proto-lint: +# @echo "--> Linting Protobuf files" +# @$(DOCKER_BUF) lint --error-format=json +#.PHONY: proto-lint diff --git a/NOTICE b/NOTICE new file mode 100644 index 0000000..ef63bae --- /dev/null +++ b/NOTICE @@ -0,0 +1,2 @@ +avail--da +Copyright 2023 and onwards Strange Loop Labs AG diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..1d142ea --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module github.com/rollkit/avail-da + +go 1.21.0