[Test] Reduce CI Time #103
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI | |
on: | |
push: | |
branches: [ main ] | |
pull_request: | |
branches: [ main ] | |
paths-ignore: | |
- 'api/docs/**' | |
- 'build/charts/**' | |
- 'design/**' | |
- '**/*.md' | |
- '**/*.txt' | |
- '**/.gitignore' | |
env: | |
GO_VERSION: '1.21' | |
jobs: | |
ci-target-check: | |
runs-on: ubuntu-latest | |
outputs: | |
build: ${{ steps.ci-target-check.outputs.build }} | |
bench: ${{ steps.ci-target-check.outputs.bench }} | |
sharding-test: ${{ steps.ci-target-check.outputs.sharding-test }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: CI target check by path | |
uses: dorny/paths-filter@v3 | |
id: ci-target-check | |
with: | |
filters: | | |
build: '**' | |
bench: | |
- 'pkg/**' | |
- 'server/**' | |
- 'client/**' | |
- 'admin/**' | |
- 'api/converter/**' | |
sharding-test: | |
- 'server/backend/database/**' | |
make-tools: | |
name: make-tools | |
runs-on: ubuntu-latest | |
needs: ci-target-check | |
if: ${{ needs.ci-target-check.outputs.build == 'true' }} | |
steps: | |
- name: Set up Go ${{ env.GO_VERSION }} | |
uses: actions/setup-go@v4 | |
with: | |
go-version: ${{ env.GO_VERSION }} | |
- name: Save GOPATH to environment variables | |
run: echo "GOPATH=$(go env GOPATH)" >> $GITHUB_ENV | |
- name: Check out code | |
uses: actions/checkout@v4 | |
- name: Restore Go pkg cache | |
uses: actions/cache@v3 | |
id: restore-pkg | |
with: | |
path: ${{ env.GOPATH }}/gopath.tar.zst | |
key: ${{ runner.os }}-gopath-${{ hashFiles('Makefile') }} | |
restore-keys: | | |
${{ runner.os }}-gopath- | |
- name: Get tools dependencies if cache not exists | |
if: steps.restore-pkg.outputs.cache-hit != 'true' | |
run: make tools | |
- name: Compress Go pkg if cache not exists | |
if: steps.restore-pkg.outputs.cache-hit != 'true' | |
run: | | |
tar -I 'zstd -3' -cf $GOPATH/gopath.tar.zst -C $GOPATH pkg bin | |
- name: Store Go pkg if cache not exists | |
if: steps.restore-pkg.outputs.cache-hit != 'true' | |
uses: actions/cache/save@v3 | |
with: | |
path: ${{ env.GOPATH }}/gopath.tar.zst | |
key: ${{ runner.os }}-gopath-${{ hashFiles('Makefile') }} | |
build: | |
name: build | |
runs-on: ubuntu-latest | |
needs: [ci-target-check, make-tools] | |
if: ${{ needs.ci-target-check.outputs.build == 'true' }} | |
steps: | |
- name: Set up Go ${{ env.GO_VERSION }} | |
uses: actions/setup-go@v4 | |
with: | |
go-version: ${{ env.GO_VERSION }} | |
- name: Save GOPATH to environment variables | |
run: echo "GOPATH=$(go env GOPATH)" >> $GITHUB_ENV | |
- name: Setup buf action | |
uses: bufbuild/buf-setup-action@v1 | |
with: | |
github_token: ${{ github.token }} | |
- name: Check out code | |
uses: actions/checkout@v4 | |
- name: Restore Go pkg cache | |
uses: actions/cache@v3 | |
with: | |
path: ${{ env.GOPATH }}/gopath.tar.zst | |
key: ${{ runner.os }}-gopath-${{ hashFiles('Makefile') }} | |
restore-keys: | | |
${{ runner.os }}-gopath- | |
- name: Decompress Go pkg if cache exists | |
run: | | |
if [ -f "$GOPATH/gopath.tar.zst" ]; then | |
mkdir -p $GOPATH/pkg | |
tar -I 'zstd -d' -xf $GOPATH/gopath.tar.zst -C $GOPATH | |
fi | |
- name: Get tools dependencies if cache not exists | |
run: make tools | |
- name: Lint | |
run: make lint | |
- name: Lint proto files | |
uses: bufbuild/buf-lint-action@v1 | |
- name: Build | |
run: make build | |
- name: Stack | |
run: docker compose -f build/docker/docker-compose.yml up --build -d | |
- name: Test | |
run: go test -tags integration -race -coverprofile=coverage.txt -covermode=atomic -v ./... | |
- name: Upload coverage to Codecov | |
uses: codecov/codecov-action@v3 | |
with: | |
file: ./coverage.txt | |
env: | |
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} | |
bench: | |
name: bench | |
runs-on: ubuntu-latest | |
permissions: write-all | |
needs: [ci-target-check, make-tools] | |
if: ${{ needs.ci-target-check.outputs.bench == 'true' }} | |
steps: | |
- name: Set up Go ${{ env.GO_VERSION }} | |
uses: actions/setup-go@v4 | |
with: | |
go-version: ${{ env.GO_VERSION }} | |
- name: Check out code | |
uses: actions/checkout@v4 | |
- name: Stack | |
run: docker compose -f build/docker/docker-compose.yml up --build -d | |
- name: Bench | |
run: make bench | |
- name: Download previous benchmark data | |
uses: actions/cache@v3 | |
with: | |
path: ./cache | |
key: ${{ runner.os }}-benchmark | |
- name: Store benchmark result | |
uses: benchmark-action/github-action-benchmark@v1 | |
if: ${{ github.event.pull_request.head.repo.full_name == github.repository }} | |
with: | |
name: Go Benchmark | |
tool: 'go' | |
output-file-path: output.txt | |
external-data-json-path: ./cache/benchmark-data.json | |
fail-on-alert: false | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
comment-always: true | |
- name: Compress and save cache | |
run: | | |
tar -I 'zstd -1' -cf cache.tar.zst -C ./cache . | |
- name: Upload compressed cache | |
uses: actions/cache@v3 | |
with: | |
path: ./cache | |
key: ${{ runner.os }}-benchmark | |
sharding-test: | |
name: sharding-test | |
runs-on: ubuntu-latest | |
needs: [ci-target-check, make-tools] | |
if: ${{ needs.ci-target-check.outputs.sharding-test == 'true' }} | |
steps: | |
- name: Set up Go ${{ env.GO_VERSION }} | |
uses: actions/setup-go@v3 | |
with: | |
go-version: ${{ env.GO_VERSION }} | |
- name: Check out code | |
uses: actions/checkout@v4 | |
- name: Check Docker Compose Version | |
run: docker compose --version | |
- name: Run the Config server, Shard 1 and Shard 2 | |
run: docker compose -f build/docker/sharding/docker-compose.yml up --build -d --wait config1 shard1-1 shard2-1 | |
- name: Initialize the Config server | |
run: docker compose -f build/docker/sharding/docker-compose.yml exec config1 mongosh test /scripts/init-config1.js | |
- name: Initialize the Shard 1 | |
run: docker compose -f build/docker/sharding/docker-compose.yml exec shard1-1 mongosh test /scripts/init-shard1-1.js | |
- name: Initialize the Shard 2 | |
run: docker compose -f build/docker/sharding/docker-compose.yml exec shard2-1 mongosh test /scripts/init-shard2-1.js | |
- name: Run the Mongos | |
run: docker compose -f build/docker/sharding/docker-compose.yml up --build -d --wait mongos1 | |
- name: Initialize the Mongos | |
run: docker compose -f build/docker/sharding/docker-compose.yml exec mongos1 mongosh test /scripts/init-mongos1.js | |
- name: Run the tests with sharding tag | |
run: go test -tags sharding -race -v ./test/sharding/... |