From 890c55d028105d7baa5832ca2b785adb2ef91f97 Mon Sep 17 00:00:00 2001 From: binary_ho Date: Wed, 14 Aug 2024 21:21:41 +0900 Subject: [PATCH 01/10] Add a CI target check job and modify the jobs to run only when the files in the target path are changed --- .github/workflows/ci.yml | 217 +++++++++++++++++++++++---------------- 1 file changed, 129 insertions(+), 88 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f3759c51b..7705ccf2a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,126 +16,167 @@ 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: CI target check by path + uses: dorny/paths-filter@v3 + id: ci-target-check + with: + filters: | + build: '**' + bench: + - 'pkg/**' + - 'server/packs/**' + sharding-test: + - 'server/backend/database/**' + build: name: build 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: Set up Go ${{ env.GO_VERSION }} - uses: actions/setup-go@v4 - with: - go-version: ${{ env.GO_VERSION }} + - name: Setup buf action + uses: bufbuild/buf-setup-action@v1 + with: + github_token: ${{ github.token }} - - name: Setup buf action - uses: bufbuild/buf-setup-action@v1 - with: - github_token: ${{ github.token }} + - name: Check out code + uses: actions/checkout@v4 - - name: Check out code - uses: actions/checkout@v4 + - name: Get tools dependencies + run: make tools - - name: Get tools dependencies - run: make tools + - name: Lint + run: make lint - - name: Lint - run: make lint + - name: Lint proto files + uses: bufbuild/buf-lint-action@v1 - - name: Lint proto files - uses: bufbuild/buf-lint-action@v1 + - name: Build + run: make build - - name: Build - run: make build + - name: Stack + run: docker compose -f build/docker/docker-compose.yml up --build -d - - 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: 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 }} - - 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 + 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: Get tools dependencies - run: make tools - - - 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: Check Benchmark Target + uses: dorny/paths-filter@v3 + id: bench-target-filter + with: + filters: | + bench-target: + - 'pkg/**' + - 'server/packs/**' + + - 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: Get tools dependencies + run: make tools + + - 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 sharding_test: name: sharding_test runs-on: ubuntu-latest + + needs: ci-target-check + 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: 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 out code - uses: actions/checkout@v4 + - name: Get tools dependencies + run: make tools - - name: Get tools dependencies - run: make tools + - name: Check Docker Compose Version + run: docker compose --version - - 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: 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 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 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: 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: 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: 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/... + - name: Run the tests with sharding tag + run: go test -tags sharding -race -v ./test/sharding/... From df1996423de57eef4c375d12fec16f8421fa78a6 Mon Sep 17 00:00:00 2001 From: binary_ho Date: Wed, 14 Aug 2024 21:35:41 +0900 Subject: [PATCH 02/10] Add `design` package to paths-ignore --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7705ccf2a..21562b190 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,6 +8,7 @@ on: paths-ignore: - 'api/docs/**' - 'build/charts/**' + - 'design/**' - '**/*.md' - '**/*.txt' - '**/.gitignore' From ab50d549de4d6c72e6ed6cf6e3d71a528c72fb05 Mon Sep 17 00:00:00 2001 From: binary_ho Date: Wed, 14 Aug 2024 21:43:30 +0900 Subject: [PATCH 03/10] Add Comment for test bench test running --- server/packs/packs.go | 1 + 1 file changed, 1 insertion(+) diff --git a/server/packs/packs.go b/server/packs/packs.go index f37d94655..ae1e029a3 100644 --- a/server/packs/packs.go +++ b/server/packs/packs.go @@ -37,6 +37,7 @@ import ( "github.com/yorkie-team/yorkie/server/logging" ) +// Add Comment For CI Bench Test (TODO: Remove after test) // PushPullKey creates a new sync.Key of PushPull for the given document. func PushPullKey(projectID types.ID, docKey key.Key) sync.Key { return sync.NewKey(fmt.Sprintf("pushpull-%s-%s", projectID, docKey)) From 17ca7d9ee944492f4a107e8beae232476ed18239 Mon Sep 17 00:00:00 2001 From: binary_ho Date: Wed, 14 Aug 2024 21:47:13 +0900 Subject: [PATCH 04/10] Add Comment for test `sharding test running` --- server/backend/database/memory/database.go | 1 + server/packs/packs.go | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/server/backend/database/memory/database.go b/server/backend/database/memory/database.go index 08b2b1364..e24cd33df 100644 --- a/server/backend/database/memory/database.go +++ b/server/backend/database/memory/database.go @@ -34,6 +34,7 @@ import ( "github.com/yorkie-team/yorkie/server/backend/database" ) +// Add Comment For CI Sharding Test (Remove after test) // DB is an in-memory database for testing or temporarily. type DB struct { db *memdb.MemDB diff --git a/server/packs/packs.go b/server/packs/packs.go index ae1e029a3..a1c0f82fc 100644 --- a/server/packs/packs.go +++ b/server/packs/packs.go @@ -37,7 +37,7 @@ import ( "github.com/yorkie-team/yorkie/server/logging" ) -// Add Comment For CI Bench Test (TODO: Remove after test) +// Add Comment For CI Bench Test (Remove after test) // PushPullKey creates a new sync.Key of PushPull for the given document. func PushPullKey(projectID types.ID, docKey key.Key) sync.Key { return sync.NewKey(fmt.Sprintf("pushpull-%s-%s", projectID, docKey)) From 96bf00b59bd8a2d90448bba4179468eced01259e Mon Sep 17 00:00:00 2001 From: binary_ho Date: Wed, 14 Aug 2024 21:50:01 +0900 Subject: [PATCH 05/10] Remove All test comments --- server/backend/database/memory/database.go | 1 - server/packs/packs.go | 1 - 2 files changed, 2 deletions(-) diff --git a/server/backend/database/memory/database.go b/server/backend/database/memory/database.go index e24cd33df..08b2b1364 100644 --- a/server/backend/database/memory/database.go +++ b/server/backend/database/memory/database.go @@ -34,7 +34,6 @@ import ( "github.com/yorkie-team/yorkie/server/backend/database" ) -// Add Comment For CI Sharding Test (Remove after test) // DB is an in-memory database for testing or temporarily. type DB struct { db *memdb.MemDB diff --git a/server/packs/packs.go b/server/packs/packs.go index a1c0f82fc..f37d94655 100644 --- a/server/packs/packs.go +++ b/server/packs/packs.go @@ -37,7 +37,6 @@ import ( "github.com/yorkie-team/yorkie/server/logging" ) -// Add Comment For CI Bench Test (Remove after test) // PushPullKey creates a new sync.Key of PushPull for the given document. func PushPullKey(projectID types.ID, docKey key.Key) sync.Key { return sync.NewKey(fmt.Sprintf("pushpull-%s-%s", projectID, docKey)) From 9dd2ce716cf932d028a1838fb6b39a5eda33b4ee Mon Sep 17 00:00:00 2001 From: binary_ho Date: Thu, 15 Aug 2024 01:01:55 +0900 Subject: [PATCH 06/10] Fix jobs depth --- .github/workflows/ci.yml | 212 +++++++++++++++++++-------------------- 1 file changed, 106 insertions(+), 106 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 21562b190..0b641b285 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,17 +26,17 @@ jobs: sharding-test: ${{ steps.ci-target-check.outputs.sharding-test }} steps: - - name: CI target check by path - uses: dorny/paths-filter@v3 - id: ci-target-check - with: - filters: | - build: '**' - bench: - - 'pkg/**' - - 'server/packs/**' - sharding-test: - - 'server/backend/database/**' + - name: CI target check by path + uses: dorny/paths-filter@v3 + id: ci-target-check + with: + filters: | + build: '**' + bench: + - 'pkg/**' + - 'server/packs/**' + sharding-test: + - 'server/backend/database/**' build: name: build @@ -46,43 +46,43 @@ jobs: 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: Set up Go ${{ env.GO_VERSION }} + uses: actions/setup-go@v4 + with: + go-version: ${{ env.GO_VERSION }} - - name: Setup buf action - uses: bufbuild/buf-setup-action@v1 - with: - github_token: ${{ github.token }} + - name: Setup buf action + uses: bufbuild/buf-setup-action@v1 + with: + github_token: ${{ github.token }} - - name: Check out code - uses: actions/checkout@v4 + - name: Check out code + uses: actions/checkout@v4 - - name: Get tools dependencies - run: make tools + - name: Get tools dependencies + run: make tools - - name: Lint - run: make lint + - name: Lint + run: make lint - - name: Lint proto files - uses: bufbuild/buf-lint-action@v1 + - name: Lint proto files + uses: bufbuild/buf-lint-action@v1 - - name: Build - run: make build + - name: Build + run: make build - - name: Stack - run: docker compose -f build/docker/docker-compose.yml up --build -d + - 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: 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 }} + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v3 + with: + file: ./coverage.txt + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} bench: name: bench @@ -94,49 +94,49 @@ jobs: steps: - - name: Check Benchmark Target - uses: dorny/paths-filter@v3 - id: bench-target-filter - with: - filters: | - bench-target: - - 'pkg/**' - - 'server/packs/**' - - - 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: Get tools dependencies - run: make tools - - - 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: Check Benchmark Target + uses: dorny/paths-filter@v3 + id: bench-target-filter + with: + filters: | + bench-target: + - 'pkg/**' + - 'server/packs/**' + + - 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: Get tools dependencies + run: make tools + + - 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 sharding_test: name: sharding_test @@ -147,37 +147,37 @@ jobs: steps: - - name: Set up Go ${{ env.GO_VERSION }} - uses: actions/setup-go@v3 - with: - go-version: ${{ env.GO_VERSION }} + - 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 out code + uses: actions/checkout@v4 - - name: Get tools dependencies - run: make tools + - name: Get tools dependencies + run: make tools - - name: Check Docker Compose Version - run: docker compose --version + - 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: 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 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 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: 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: 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: 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/... + - name: Run the tests with sharding tag + run: go test -tags sharding -race -v ./test/sharding/... From a654f6f2a9d747c00629437cffab9ac014d5e107 Mon Sep 17 00:00:00 2001 From: binary_ho Date: Thu, 15 Aug 2024 15:14:26 +0900 Subject: [PATCH 07/10] Remove unnecessary step in benchmark job --- .github/workflows/ci.yml | 9 --------- 1 file changed, 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0b641b285..b47704da5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -94,15 +94,6 @@ jobs: steps: - - name: Check Benchmark Target - uses: dorny/paths-filter@v3 - id: bench-target-filter - with: - filters: | - bench-target: - - 'pkg/**' - - 'server/packs/**' - - name: Set up Go ${{ env.GO_VERSION }} uses: actions/setup-go@v4 with: From acfd1f08c078da553214cb54cb1f1aa3fbea1fad Mon Sep 17 00:00:00 2001 From: binary_ho Date: Thu, 15 Aug 2024 15:15:52 +0900 Subject: [PATCH 08/10] Rename job name `sharding_test` to `sharding-test` --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b47704da5..9263da824 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -129,8 +129,8 @@ jobs: github-token: ${{ secrets.GITHUB_TOKEN }} comment-always: true - sharding_test: - name: sharding_test + sharding-test: + name: sharding-test runs-on: ubuntu-latest needs: ci-target-check From cdd85ade991bf792bb59f9d620c091554dbcaf88 Mon Sep 17 00:00:00 2001 From: binary_ho Date: Thu, 15 Aug 2024 16:36:18 +0900 Subject: [PATCH 09/10] Update bench test targets - all bench tests dependencies --- .github/workflows/ci.yml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9263da824..1a0103a3d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -33,8 +33,15 @@ jobs: filters: | build: '**' bench: - - 'pkg/**' - - 'server/packs/**' + - 'api/converter/**' + - 'api/types/**' + - 'pkg/document/**' + - 'pkg/locker/**' + - 'server/**' + - 'client/**' + - 'admin/**' + - 'test/helper/**' + sharding-test: - 'server/backend/database/**' From 57ea87b38af8750e70bc3141dd0e7a875c2a0069 Mon Sep 17 00:00:00 2001 From: binary_ho Date: Thu, 15 Aug 2024 19:43:05 +0900 Subject: [PATCH 10/10] Simplify bench target packages and remove `/api/types/**`, `/test/helper/**` --- .github/workflows/ci.yml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1a0103a3d..f4052f616 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -33,14 +33,11 @@ jobs: filters: | build: '**' bench: - - 'api/converter/**' - - 'api/types/**' - - 'pkg/document/**' - - 'pkg/locker/**' + - 'pkg/**' - 'server/**' - 'client/**' - 'admin/**' - - 'test/helper/**' + - 'api/converter/**' sharding-test: - 'server/backend/database/**'