diff --git a/.github/workflows/housekeeping.yml b/.github/workflows/housekeeping.yml index 46fc9279..8f40bf50 100644 --- a/.github/workflows/housekeeping.yml +++ b/.github/workflows/housekeeping.yml @@ -7,9 +7,10 @@ on: types: [opened, ready_for_review] jobs: - issue-management: - if: ${{ github.event.issue }} - name: Add issues to project and add triage label + add-to-project-with-knuu-label: + # ignore dependabot PRs + if: ${{ github.actor != 'dependabot[bot]' }} + name: Add issues and PRs to project and add knuu label uses: celestiaorg/.github/.github/workflows/reusable_housekeeping.yml@v0.4.1 secrets: inherit permissions: @@ -21,20 +22,6 @@ jobs: run-projects: true project-url: https://github.com/orgs/celestiaorg/projects/27 - add-pr-to-project: - # ignore dependabot PRs - if: ${{ github.event.pull_request && github.actor != 'dependabot[bot]' }} - name: Add PRs to project - uses: celestiaorg/.github/.github/workflows/reusable_housekeeping.yml@v0.4.1 - secrets: inherit - permissions: - issues: write - pull-requests: write - with: - run-projects: true - project-labels: "knuu" - project-url: https://github.com/orgs/celestiaorg/projects/27 - auto-add-reviewer: name: Auto add reviewer to PR if: github.event.pull_request diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 00000000..48683a85 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,55 @@ +name: Lint +on: + push: + branches: [main] + pull_request: + workflow_dispatch: + merge_group: + +jobs: + golangci-lint: + name: golangci-lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version: 1.22.1 + # 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@v6.0.1 + 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: celestiaorg/.github/.github/actions/yamllint@v0.4.1 + + markdown-lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: celestiaorg/.github/.github/actions/markdown-lint@v0.4.1 + + govulncheck: + runs-on: ubuntu-latest + name: Run govulncheck + steps: + - id: govulncheck + uses: golang/govulncheck-action@v1 + with: + go-version-input: 1.22.1 + go-package: ./... diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..26490d39 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +coverage.txt +.vscode/launch.json +*/**.html +*.idea diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 00000000..f6d91b67 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,46 @@ +run: + timeout: 5m + modules-download-mode: readonly + +linters: + disable: + # TODO: there are tons of errors for these, we need to handle in a separate PR + - errorlint + - errcheck + - gosec + enable: + - gofmt + - goimports + - gosimple + - govet + - ineffassign + - misspell + - revive + - staticcheck + - typecheck + - unconvert + - unused + +issues: + exclude-use-default: false + include: + - EXC0012 # EXC0012 revive: Annoying issue about not having a comment. The rare codebase has such comments + - EXC0014 # EXC0014 revive: Annoying issue about not having a comment. The rare codebase has such comments + exclude: + - SA1019 # TODO enable: SA 1019 staticcheck: this is being triggered by the refactor and all the deprecated code. We need to enable this once we make the breaking change official + +linters-settings: + revive: + rules: + - name: package-comments + disabled: true + - name: duplicated-imports + severity: warning + - name: exported + disabled: true + # Leaving for reference if we can enable in the future. + # arguments: + # - disableStutteringCheck + + goimports: + local-prefixes: github.com/celestiaorg diff --git a/.markdownlint.yaml b/.markdownlint.yaml new file mode 100644 index 00000000..ee333bec --- /dev/null +++ b/.markdownlint.yaml @@ -0,0 +1,6 @@ +default: true +MD010: false +MD013: false +MD041: false +MD024: + allow_different_nesting: true diff --git a/.yamllint.yml b/.yamllint.yml new file mode 100644 index 00000000..cd2a9e82 --- /dev/null +++ b/.yamllint.yml @@ -0,0 +1,9 @@ +--- +# Built from docs https://yamllint.readthedocs.io/en/stable/configuration.html +extends: default + +rules: + # 120 chars should be enough, but don't fail if a line is longer + line-length: + max: 120 + level: warning diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c8eb2561..35842760 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -10,48 +10,49 @@ If you are new to Knuu, please go through the [README](./README.md) to familiari - Have a suggestion you want to implement? Open an issue, then create a Pull Request with your implementation. -- Want to resolve an issue in the repo, make a request to be assigned, and be sure to tag the issue in your PR!. +- Want to resolve an issue in the repo, make a request to be assigned, and be sure to tag the issue in your PR! ## Contribution Workflow To contribute to Knuu, follow these steps: 1. Fork the repository: Click on the 'Fork' button at the top right of this page. This will create a copy of the repository in your GitHub account. - -2. Clone the forked repository to your local machine. Open your terminal and run: -```bash -git clone -``` +1. Clone the forked repository to your local machine. Open your terminal and run: -3. Create your working branch: In the project directory, create a new branch by running the following command in your terminal: + ```bash + git clone + ``` -```bash -git checkout -b working-branch -``` -Be sure to name your branch according to the changes you are making. -For example: `add-missing-tests`. +1. Create your working branch: In the project directory, create a new branch by running the following command in your terminal: -4. Make your changes: Do not address multiple issues per PR. -For example, if you are adding a feature, it should not have bug fixes too. This is to enable the maintainers review your PR efficiently. + ```bash + git checkout -b working-branch + ``` -5. Commit the changes to your branch: After making the desired changes to the repo, run the following commands to commit them: + Be sure to name your branch according to the changes you are making. + For example: `add-missing-tests`. -```bash -git add . -``` +1. Make your changes: Do not address multiple issues per PR. + For example, if you are adding a feature, it should not have bug fixes too. This is to enable the maintainers review your PR efficiently. -```bash -git commit -m "add an appropriate commit message" -``` +1. Commit the changes to your branch: After making the desired changes to the repo, run the following commands to commit them: -```bash -git push origin -``` + ```bash + git add . + ``` -To ensure that your contribution is working as expected, please run `knuu-example` with your fork and working branch. + ```bash + git commit -m "add an appropriate commit message" + ``` -5. Create a Pull Request: Go to your forked repository on GitHub, and be sure that you are in the branch you pushed the changes to. Click on the 'Compare & pull request' button. This will open a new page where you can create your PR. Fill in the description field and click on 'Create pull request'. + ```bash + git push origin + ``` + + To ensure that your contribution is working as expected, please run `knuu-example` with your fork and working branch. + +1. Create a Pull Request: Go to your forked repository on GitHub, and be sure that you are in the branch you pushed the changes to. Click on the 'Compare & pull request' button. This will open a new page where you can create your PR. Fill in the description field and click on 'Create pull request'. Be sure to name your PR with a semantic prefix. For example, if it is a fix, it should be specified with the `fix:` prefix. Congratulations! You have successfully made a Pull Request, and your changes will be reviewed by the maintainers. diff --git a/LICENCE b/LICENSE similarity index 100% rename from LICENCE rename to LICENSE diff --git a/Makefile b/Makefile index dfb72ba7..cda44f3a 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,62 @@ 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 -test: - go test -v $(pkgs) -run $(run) -count=$(count) -timeout 120m +## clean: clean testcache +clean: + @echo "--> Clearing testcache" + @go clean --testcache + @rm coverage.txt +.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 + @go mod tidy +.PHONY: deps + +## lint: Run linters golangci-lint and markdownlint. +lint: vet + @echo "--> Running markdownlint" + @markdownlint --config .markdownlint.yaml '**/*.md' + @echo "--> Running yamllint" + @yamllint --no-warnings . -c .yamllint.yml + @echo "--> Running actionlint" + @actionlint + @echo "--> Running govulncheck" + @govulncheck ./... + @echo "--> Running golangci-lint" + @golangci-lint run +.PHONY: lint + +## fmt: Run fixes for linters. +fmt: + @echo "--> Formatting markdownlint" + @markdownlint --config .markdownlint.yaml '**/*.md' -f + @echo "--> Formatting go" + @golangci-lint run --fix +.PHONY: fmt + +## vet: Run go vet +vet: + @echo "--> Running go vet" + @go vet $(pkgs) +.PHONY: vet + +## test: Run the testsuite +test: vet + go test -v $(pkgs) -run $(run) -count=$(count) -timeout 120m .PHONY: test diff --git a/README.md b/README.md index db76891b..daac61b8 100644 --- a/README.md +++ b/README.md @@ -204,7 +204,7 @@ In the folder `e2e`, you will find some examples of how to use the [knuu](https: ## Write Tests -You can find the relevant documentation in the `pkg/knuu` package at: https://pkg.go.dev/github.com/celestiaorg/knuu +You can find the relevant documentation in the `pkg/knuu` package at: ## Run @@ -256,7 +256,7 @@ See [SECURITY.md](SECURITY.md) for security and disclosure information. ## Licensing -Knuu is licensed under the [Apache License 2.0](LICENSE). +Knuu is licensed under the [Apache License 2.0](./LICENSE).