Skip to content

Commit

Permalink
Merge pull request cosmos#903 from smuu/feature/ci-cd-setup
Browse files Browse the repository at this point in the history
feat: CI/CD setup
  • Loading branch information
Bidon15 authored Apr 27, 2023
2 parents 66d7e50 + 4db6a34 commit 931c35c
Show file tree
Hide file tree
Showing 8 changed files with 216 additions and 34 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/ci_release.yml
Original file line number Diff line number Diff line change
@@ -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}}
6 changes: 2 additions & 4 deletions .github/workflows/docker-build-da-mockserv.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
27 changes: 17 additions & 10 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
27 changes: 27 additions & 0 deletions .github/workflows/proto.yml
Original file line number Diff line number Diff line change
@@ -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
81 changes: 62 additions & 19 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -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"
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
coverage.txt
proto/pb
proto/tendermint
types/pb/tendermint
types/pb/tendermint
40 changes: 40 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions buf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 931c35c

Please sign in to comment.