Skip to content

Commit

Permalink
ci: add commit lint, code lint and unit test ci files (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
sysvm authored and will-2012 committed Feb 10, 2023
1 parent fd2c99a commit 595d029
Show file tree
Hide file tree
Showing 14 changed files with 636 additions and 43 deletions.
144 changes: 144 additions & 0 deletions .github/coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
name: Test Coverage

on:
push:
branches:
- main
- develop

pull_request:
branches:
- main
- develop

jobs:
split-test-files:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Create a file with all the pkgs
run: go list ./... > pkgs.txt
- name: Split pkgs into 4 files
run: split -d -n l/4 pkgs.txt pkgs.txt.part.
# cache multiple
- uses: actions/upload-artifact@v3
with:
name: "${{ github.sha }}-00"
path: ./pkgs.txt.part.00
- uses: actions/upload-artifact@v3
with:
name: "${{ github.sha }}-01"
path: ./pkgs.txt.part.01
- uses: actions/upload-artifact@v3
with:
name: "${{ github.sha }}-02"
path: ./pkgs.txt.part.02
- uses: actions/upload-artifact@v3
with:
name: "${{ github.sha }}-03"
path: ./pkgs.txt.part.03

build-linux:
name: Build
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
goarch: ["amd64"]
go-version: [1.19.x]
timeout-minutes: 5
steps:
- uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}
- name: Buf install
uses: bufbuild/buf-setup-action@v1.11.0
- name: Buf generate
run: |
buf generate
- uses: actions/checkout@v3
- uses: technote-space/get-diff-action@v6
with:
PATTERNS: |
**/**.go
go.mod
go.sum
- name: install
run: GOOS=linux GOARCH=${{ matrix.goarch }} make build
if: "env.GIT_DIFF != ''"

tests:
runs-on: ubuntu-latest
needs: split-test-files
strategy:
fail-fast: false
matrix:
part: ["00", "01", "02", "03"]
steps:
- uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}
- uses: actions/checkout@v3
- name: Buf install
uses: bufbuild/buf-setup-action@v1.11.0
- name: Buf generate
run: |
buf generate
- uses: technote-space/get-diff-action@v6
with:
PATTERNS: |
**/**.go
go.mod
go.sum
- uses: actions/download-artifact@v3
with:
name: "${{ github.sha }}-${{ matrix.part }}"
if: env.GIT_DIFF
- name: test & coverage report creation
run: |
cat pkgs.txt.part.${{ matrix.part }} | xargs go test -mod=readonly -timeout 8m -race -coverprofile=${{ matrix.part }}profile.out -covermode=atomic
if: env.GIT_DIFF
- uses: actions/upload-artifact@v3
with:
name: "${{ github.sha }}-${{ matrix.part }}-coverage"
path: ./${{ matrix.part }}profile.out

upload-coverage-report:
runs-on: ubuntu-latest
needs: tests
steps:
- uses: actions/checkout@v3
- name: Buf install
uses: bufbuild/buf-setup-action@v1.11.0
- name: Buf generate
run: |
buf generate
- uses: technote-space/get-diff-action@v6
with:
PATTERNS: |
**/**.go
go.mod
go.sum
- uses: actions/download-artifact@v3
with:
name: "${{ github.sha }}-00-coverage"
if: env.GIT_DIFF
- uses: actions/download-artifact@v3
with:
name: "${{ github.sha }}-01-coverage"
if: env.GIT_DIFF
- uses: actions/download-artifact@v3
with:
name: "${{ github.sha }}-02-coverage"
if: env.GIT_DIFF
- uses: actions/download-artifact@v3
with:
name: "${{ github.sha }}-03-coverage"
if: env.GIT_DIFF
- run: |
cat ./*profile.out | grep -v "mode: atomic" >> coverage.txt
if: env.GIT_DIFF
- uses: codecov/codecov-action@v3
with:
file: ./coverage.txt
if: env.GIT_DIFF
88 changes: 88 additions & 0 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: Build Test

on:
push:
branches:
- main
- develop

pull_request:
branches:
- main
- develop

jobs:
build-test:
strategy:
matrix:
go-version: [1.19.x]
os: [ubuntu-20.04]
runs-on: ${{ matrix.os }}
steps:
- name: Install Go
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}

- name: Checkout code
uses: actions/checkout@v3

- uses: actions/cache@v3
with:
# In order:
# * Module download cache
# * Build cache (Linux)
# * Build cache (Mac)
# * Build cache (Windows)
path: |
~/go/pkg/mod
~/.cache/go-build
~/Library/Caches/go-build
%LocalAppData%\go-build
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- uses: ory/build-buf-action@v0
with:
bufVersion: v1.11.0
protocPlugins:
go@v1.28.0 go-grpc@v1.2.0
bufArgs:
generate

- name: Test Build
run: |
bash build.sh
build-test-success:
needs: build-test
if: ${{ success() }}
runs-on: ubuntu-latest
steps:
- name: Notify Slack on success
uses: rtCamp/action-slack-notify@v2.2.0
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
SLACK_CHANNEL: greenfield_storage_ci
SLACK_USERNAME: SP Build Test
SLACK_ICON_EMOJI: ':heavy_check_mark:'
SLACK_COLOR: good
SLACK_MESSAGE: Greenfield SP build test passed
SLACK_FOOTER: ''

build-test-failure:
needs: build-test
if: ${{ failure() }}
runs-on: ubuntu-latest
steps:
- name: Notify Slack on failure
uses: rtCamp/action-slack-notify@v2.2.0
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
SLACK_CHANNEL: greenfield_storage_ci
SLACK_USERNAME: SP Build Test
SLACK_ICON_EMOJI: ':x:'
SLACK_COLOR: danger
SLACK_MESSAGE: Greenfield SP build test failed
SLACK_FOOTER: ''
86 changes: 86 additions & 0 deletions .github/workflows/code-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
name: Golang Code Lint
# Lint runs golangci-lint over the entire Tendermint repository
# This workflow is run on every pull request and push to master
# The `golangci` job will pass without running if no *.{go, mod, sum} files have been modified.
on:
push:
branches:
- main
- develop

pull_request:
branches:
- main
- develop

jobs:
golangci:
name: golangci-lint
runs-on: ubuntu-latest
timeout-minutes: 8
strategy:
matrix:
go-version: [1.19.x]
steps:
- uses: actions/checkout@v3

- uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}

- uses: ory/build-buf-action@v0
with:
bufVersion: v1.11.0
protocPlugins:
go@v1.28.0 go-grpc@v1.2.0
bufArgs:
generate

- uses: technote-space/get-diff-action@v6
with:
PATTERNS: |
**/**.go
go.mod
go.sum
- uses: golangci/golangci-lint-action@v3
with:
# Required: the version of golangci-lint is required and
# must be specified without patch version: we always use the
# latest patch version.
version: v1.50.1
args: --timeout 10m
github-token: ${{ secrets.github_token }}
if: env.GIT_DIFF

golang-ci-lint-success:
needs: golangci
if: ${{ success() }}
runs-on: ubuntu-latest
steps:
- name: Notify Slack on success
uses: rtCamp/action-slack-notify@v2.2.0
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
SLACK_CHANNEL: greenfield_storage_ci
SLACK_USERNAME: SP Golang CI Lint
SLACK_ICON_EMOJI: ':heavy_check_mark:'
SLACK_COLOR: good
SLACK_MESSAGE: Greenfield golang ci lint passed
SLACK_FOOTER: ''

golang-ci-lint-failure:
needs: golangci
if: ${{ failure() }}
runs-on: ubuntu-latest
steps:
- name: Notify Slack on failure
uses: rtCamp/action-slack-notify@v2.2.0
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
SLACK_CHANNEL: greenfield_storage_ci
SLACK_USERNAME: SP Golang CI Lint
SLACK_ICON_EMOJI: ':x:'
SLACK_COLOR: danger
SLACK_MESSAGE: Greenfield golang ci lint failed
SLACK_FOOTER: ''
Loading

0 comments on commit 595d029

Please sign in to comment.