diff --git a/.github/workflows/ci_release.yml b/.github/workflows/ci_release.yml new file mode 100644 index 0000000000..7049e70001 --- /dev/null +++ b/.github/workflows/ci_release.yml @@ -0,0 +1,51 @@ +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: + 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.20' + + test: + uses: ./.github/workflows/test.yml + with: + GO_VERSION: '1.20' + + proto: + uses: ./.github/workflows/proto.yml + + # Make a release if this is a manually trigger job, i.e. workflow_dispatch + release: + needs: [lint, test, proto] + runs-on: ubuntu-latest + if: ${{ github.event_name == 'workflow_dispatch' }} + permissions: "write-all" + steps: + - uses: actions/checkout@v3 + - name: Version Release + uses: celestiaorg/.github/.github/actions/version-release@v0.1.1 + with: + github-token: ${{secrets.GITHUB_TOKEN}} + version-bump: ${{inputs.version}} diff --git a/.github/workflows/docker-build-da-mockserv.yml b/.github/workflows/docker-build-da-mockserv.yml index e4d8588879..20ce3db90f 100644 --- a/.github/workflows/docker-build-da-mockserv.yml +++ b/.github/workflows/docker-build-da-mockserv.yml @@ -6,10 +6,8 @@ on: branches: - "**" tags: - - "v[0-9]+.[0-9]+.[0-9]+" - - "v[0-9]+.[0-9]+.[0-9]+-alpha.[0-9]+" - - "v[0-9]+.[0-9]+.[0-9]+-beta.[0-9]+" - - "v[0-9]+.[0-9]+.[0-9]+-rc[0-9]+" + - 'v[0-9]+\.[0-9]+\.[0-9]+' + - 'v[0-9]+\.[0-9]+\.[0-9]+-rc(?:[0-9]+|\.[0-9]+)' pull_request: jobs: diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 9df71d9caa..ddab0b3793 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -1,14 +1,13 @@ -# lint runs all linters in this repository. This workflow is run on every pull -# request and push to main. +# lint runs all linters in this repository +# This workflow is triggered by ci_release.yml workflow name: lint on: - push: - tags: - - v* - branches: - - main - pull_request: workflow_call: + inputs: + GO_VERSION: + description: 'Go version to use' + type: string + required: true jobs: golangci-lint: @@ -18,7 +17,7 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-go@v4 with: - go-version: 1.19 + 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 @@ -31,7 +30,7 @@ jobs: go.sum - uses: golangci/golangci-lint-action@v3.4.0 with: - version: v1.50.1 + version: latest args: --timeout 10m github-token: ${{ secrets.github_token }} if: env.GIT_DIFF @@ -53,3 +52,11 @@ jobs: steps: - uses: actions/checkout@v3 - uses: celestiaorg/.github/.github/actions/markdown-lint@v0.1.1 + + protobuf-lint: + runs-on: ubuntu-latest + timeout-minutes: 5 + steps: + - uses: actions/checkout@v3 + - run: make proto-gen + - run: make proto-lint diff --git a/.github/workflows/proto.yml b/.github/workflows/proto.yml new file mode 100644 index 0000000000..756d4c18d1 --- /dev/null +++ b/.github/workflows/proto.yml @@ -0,0 +1,27 @@ +# Check if the generated protobuf code matches the committed code +name: Protobuf +on: + workflow_call: + +jobs: + proto-gen: + runs-on: ubuntu-latest + timeout-minutes: 5 + steps: + - uses: actions/checkout@v3 + - name: "Check protobuf generated code matches committed code" + # yamllint disable + run: | + set -euo pipefail + + make proto-gen + + if ! git diff --stat --exit-code ; then + echo ">> ERROR:" + echo ">>" + echo ">> Protobuf generated code requires update (either tools or .proto files may have changed)." + echo ">> Ensure your tools are up-to-date, re-run 'make proto-gen' and update this PR." + echo ">>" + exit 1 + fi + # yamllint enable diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e068561bbb..97ae2f7294 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,31 +1,74 @@ -name: Build and Test +# Tests / Code Coverage workflow +# This workflow is triggered by ci_release.yml workflow +name: Tests / Code Coverage on: - push: - tags: - - v* - branches: - - main - pull_request: -jobs: + workflow_call: + inputs: + GO_VERSION: + description: 'Go version to use' + type: string + required: true - build: +jobs: + go_mod_tidy_check: + name: Go Mod Tidy Check runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 + - uses: actions/setup-go@v4 + with: + go-version: ${{ inputs.GO_VERSION }} + - run: go mod tidy + - name: check for diff + run: git diff --exit-code - - name: Set up Go + test_coverage: + name: Unit Tests Coverage + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: set up go uses: actions/setup-go@v4 with: - go-version: 1.19 + go-version: ${{ inputs.GO_VERSION }} + - name: Test & Coverage + run: make cover + - uses: codecov/codecov-action@v3.1.3 + with: + file: ./coverage.txt - - name: Build - run: go build -v ./... + unit_test: + name: Run Unit Tests + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: set up go + uses: actions/setup-go@v4 + with: + go-version: ${{ inputs.GO_VERSION }} + - name: execute test run + run: make test-unit - - name: Test & Coverage - run: | - go install github.com/ory/go-acc@v0.2.6 - go-acc -o coverage.txt ./... -- -v --race + unit_race_test: + name: Run Unit Tests with Race Detector + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: set up go + uses: actions/setup-go@v4 + with: + go-version: ${{ inputs.GO_VERSION }} + - name: execute test run + run: make test-unit-race - - uses: codecov/codecov-action@v3 + integration_test: + name: Run Integration Tests + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: set up go + uses: actions/setup-go@v4 with: - file: ./coverage.txt + go-version: ${{ inputs.GO_VERSION }} + - name: Integration Tests + run: echo "No integration tests yet" diff --git a/.gitignore b/.gitignore index fc7c8d1187..1e04afd883 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +coverage.txt proto/pb proto/tendermint -types/pb/tendermint \ No newline at end of file +types/pb/tendermint diff --git a/Makefile b/Makefile new file mode 100644 index 0000000000..6d855e3be4 --- /dev/null +++ b/Makefile @@ -0,0 +1,40 @@ +DOCKER := $(shell which docker) +DOCKER_BUF := $(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace bufbuild/buf + +## 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 + +## cover: generate to code coverage report. +cover: + @echo "--> Generating Code Coverage" + @go install github.com/ory/go-acc@latest + @go-acc -o coverage.txt `go list ./...` +.PHONY: cover + +## test-unit: Running unit tests +test-unit: + @echo "--> Running unit tests" + @go test `go list ./...` +.PHONY: test-unit + +## test-unit-race: Running unit tests with data race detector +test-unit-race: + @echo "--> Running unit tests with data race detector" + @go test -race `go list ./...` +.PHONY: test-unit-race + +## 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/buf.yaml b/buf.yaml index 6ed37d3afd..fc7ba0b907 100644 --- a/buf.yaml +++ b/buf.yaml @@ -7,6 +7,21 @@ build: lint: use: - DEFAULT + - COMMENTS + - FILE_LOWER_SNAKE_CASE + except: + - COMMENT_ENUM + - COMMENT_ENUM_VALUE + - COMMENT_MESSAGE + - COMMENT_RPC + - COMMENT_SERVICE + - COMMENT_FIELD + - PACKAGE_VERSION_SUFFIX + - RPC_REQUEST_STANDARD_NAME + - SERVICE_SUFFIX + - UNARY_RPC + ignore: + - tendermint breaking: use: - FILE