From 08be04cf490f9faf84dfbd5bf1f50696571fce15 Mon Sep 17 00:00:00 2001 From: yk-eukarya <81808708+yk-eukarya@users.noreply.github.com> Date: Tue, 15 Oct 2024 10:14:43 +0200 Subject: [PATCH] ci(server): enhance performance (#928) * imp * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * Update .github/workflows/ci.yml Co-authored-by: KeisukeYamashita <19yamashita15@gmail.com> * Update .github/workflows/ci.yml Co-authored-by: KeisukeYamashita <19yamashita15@gmail.com> * Update .github/workflows/ci.yml Co-authored-by: KeisukeYamashita <19yamashita15@gmail.com> * Update .github/workflows/ci.yml Co-authored-by: KeisukeYamashita <19yamashita15@gmail.com> * fix --------- Co-authored-by: KeisukeYamashita <19yamashita15@gmail.com> --- .../{server_build.yml => build_server.yml} | 0 .../{worker_build.yml => build_worker.yml} | 0 .github/workflows/ci.yml | 71 ++++++++++++++++ .github/workflows/ci_server.yml | 85 ++++++++++--------- .github/workflows/ci_web.yml | 32 +------ .github/workflows/ci_worker.yml | 71 +++++++--------- .github/workflows/{pr_title.yml => pr.yml} | 17 +++- 7 files changed, 162 insertions(+), 114 deletions(-) rename .github/workflows/{server_build.yml => build_server.yml} (100%) rename .github/workflows/{worker_build.yml => build_worker.yml} (100%) create mode 100644 .github/workflows/ci.yml rename .github/workflows/{pr_title.yml => pr.yml} (76%) diff --git a/.github/workflows/server_build.yml b/.github/workflows/build_server.yml similarity index 100% rename from .github/workflows/server_build.yml rename to .github/workflows/build_server.yml diff --git a/.github/workflows/worker_build.yml b/.github/workflows/build_worker.yml similarity index 100% rename from .github/workflows/worker_build.yml rename to .github/workflows/build_worker.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000000..5e70e71ec0 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,71 @@ +name: ci +on: + push: + branches: [main, release] + pull_request: +jobs: + prepare: + runs-on: ubuntu-latest + outputs: + web: ${{ steps.web.outputs.any_modified }} + server: ${{ steps.server.outputs.any_modified }} + worker: ${{ steps.worker.outputs.any_modified }} + steps: + - name: checkout + uses: actions/checkout@v4 + - name: changed files for web + id: web + uses: tj-actions/changed-files@v45 + with: + files: | + web + .github/workflows/ci.yml + .github/workflows/ci_web.yml + + - name: changed files for server + id: server + uses: tj-actions/changed-files@v45 + with: + files: | + server + .github/workflows/ci.yml + .github/workflows/ci_server.yml + .github/workflows/build_server.yml + + - name: changed files for worker + id: worker + uses: tj-actions/changed-files@v45 + with: + files: | + worker + .github/workflows/ci.yml + .github/workflows/ci_worker.yml + .github/workflows/build_worker.yml + + ci-web: + name: web + needs: prepare + if: needs.prepare.outputs.web == 'true' + uses: ./.github/workflows/ci_web.yml + + ci-server: + name: server + needs: prepare + if: needs.prepare.outputs.server == 'true' + uses: ./.github/workflows/ci_server.yml + + ci-worker: + name: worker + needs: prepare + if: needs.prepare.outputs.worker == 'true' + uses: ./.github/workflows/ci_worker.yml + + ci: + runs-on: ubuntu-latest + needs: + - ci-web + - ci-server + - ci-worker + if: '!failure()' + steps: + - run: echo OK \ No newline at end of file diff --git a/.github/workflows/ci_server.yml b/.github/workflows/ci_server.yml index 0f92662ec2..5041479b96 100644 --- a/.github/workflows/ci_server.yml +++ b/.github/workflows/ci_server.yml @@ -1,64 +1,65 @@ name: ci-server on: - push: - branches: [main, release] - paths: - - server/** - - .github/workflows/ci_server.yml - - .github/workflows/server_build.yml - - .github/workflows/deploy_test.yml - - .github/workflows/pr_title.yml - - .github/workflows/stage.yml - - .github/workflows/release.yml - - .github/workflows/server_build.yml - pull_request: - paths: - - server/** - - .github/workflows/ci_server.yml - - .github/workflows/server_build.yml - - .github/workflows/deploy_test.yml - - .github/workflows/pr_title.yml - - .github/workflows/stage.yml - - .github/workflows/release.yml + workflow_call: +env: + GO_VERSION: "1.23" + jobs: - ci: - name: ci + ci-server-lint: + name: lint + runs-on: ubuntu-latest + steps: + - name: checkout + uses: actions/checkout@v4 + - name: go setup + uses: actions/setup-go@v5 + with: + go-version: ${{ env.GO_VERSION }} + - name: golangci-lint + uses: golangci/golangci-lint-action@v6 + with: + version: v1.61 + working-directory: server + args: --config=../.golangci.yml + skip-cache: true + ci-server-i18n: + name: i18n runs-on: ubuntu-latest defaults: run: working-directory: server + steps: + - name: checkout + uses: actions/checkout@v4 + - name: go setup + uses: actions/setup-go@v5 + with: + go-version: ${{ env.GO_VERSION }} + - name: check forgotten translations + working-directory: server + run: make i18n-ci + ci-server-test: + name: test + runs-on: ubuntu-latest services: mongo: image: mongo:6-focal ports: - 27017:27017 steps: - - uses: actions/setup-go@v5 - with: - go-version: 1.23 - name: checkout uses: actions/checkout@v4 - - name: cache - uses: actions/cache@v4 - with: - path: ~/go/pkg/mod - key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} - restore-keys: | - ${{ runner.os }}-go- - - name: golangci-lint - uses: golangci/golangci-lint-action@v6 + - name: go setup + uses: actions/setup-go@v5 with: - version: v1.61 - working-directory: server - args: --config=../.golangci.yml + go-version: ${{ env.GO_VERSION }} - name: test - run: go test ./... -v -race -coverprofile=coverage.txt -covermode=atomic + run: go test ./... -v -race -coverprofile=coverage.txt -covermode=atomic -timeout 10m + working-directory: server env: REEARTH_CMS_DB: mongodb://localhost - - name: codecov + - name: Send coverage report uses: codecov/codecov-action@v4 with: flags: server - file: coverage.txt - - name: check forgotten translations - run: make i18n-ci + file: coverage.txt \ No newline at end of file diff --git a/.github/workflows/ci_web.yml b/.github/workflows/ci_web.yml index d0d9ace00e..7009e38770 100644 --- a/.github/workflows/ci_web.yml +++ b/.github/workflows/ci_web.yml @@ -1,22 +1,6 @@ name: ci-web on: - push: - branches: [main, release] - paths: - - web/** - - .github/workflows/ci_web.yml - - .github/workflows/deploy_test.yml - - .github/workflows/pr_title.yml - - .github/workflows/stage.yml - - .github/workflows/release.yml - pull_request: - paths: - - web/** - - .github/workflows/ci_web.yml - - .github/workflows/deploy_test.yml - - .github/workflows/pr_title.yml - - .github/workflows/stage.yml - - .github/workflows/release.yml + workflow_call: jobs: ci: name: ci @@ -25,20 +9,12 @@ jobs: run: working-directory: web steps: + - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: node-version: lts/* - - uses: actions/checkout@v4 - - name: Get yarn cache directory path - id: yarn-cache-dir-path - run: echo "::set-output name=dir::$(yarn cache dir)" - - uses: actions/cache@v4 - id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) - with: - path: ${{ steps.yarn-cache-dir-path.outputs.dir }} - key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} - restore-keys: | - ${{ runner.os }}-yarn- + cache: yarn + cache-dependency-path: '**/yarn.lock' - name: Install run: yarn install - name: Lint diff --git a/.github/workflows/ci_worker.yml b/.github/workflows/ci_worker.yml index 00faf90cef..158faf18ca 100644 --- a/.github/workflows/ci_worker.yml +++ b/.github/workflows/ci_worker.yml @@ -1,61 +1,48 @@ name: ci-worker on: - push: - branches: [main, release] - paths: - - worker/** - - .github/workflows/ci_worker.yml - - .github/workflows/deploy_test.yml - - .github/workflows/pr_title.yml - - .github/workflows/stage.yml - - .github/workflows/release.yml - - .github/workflows/decompressor_build.yml - - .github/workflows/worker_build.yml - pull_request: - paths: - - worker/** - - .github/workflows/ci_worker.yml - - .github/workflows/deploy_test.yml - - .github/workflows/pr_title.yml - - .github/workflows/stage.yml - - .github/workflows/release.yml + workflow_call: +env: + GO_VERSION: "1.23" jobs: - ci: - name: ci + ci-server-lint: + name: lint runs-on: ubuntu-latest - defaults: - run: - working-directory: worker - services: - mongo: - image: mongo:6-focal - ports: - - 27017:27017 steps: - - uses: actions/setup-go@v5 - with: - go-version: 1.23 - name: checkout uses: actions/checkout@v4 - - name: cache - uses: actions/cache@v4 + - name: go setup + uses: actions/setup-go@v5 with: - path: ~/go/pkg/mod - key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} - restore-keys: | - ${{ runner.os }}-go- + go-version: ${{ env.GO_VERSION }} - name: golangci-lint uses: golangci/golangci-lint-action@v6 with: version: v1.61 working-directory: worker args: --config=../.golangci.yml + skip-cache: true + ci-server-test: + name: test + runs-on: ubuntu-latest + services: + mongo: + image: mongo:6-focal + ports: + - 27017:27017 + steps: + - name: checkout + uses: actions/checkout@v4 + - name: go setup + uses: actions/setup-go@v5 + with: + go-version: ${{ env.GO_VERSION }} - name: test - run: go test ./... -v -race -coverprofile=coverage.txt -covermode=atomic + run: go test ./... -v -race -coverprofile=coverage.txt -covermode=atomic -timeout 10m + working-directory: worker env: - REEARTH_CMS_WORKER_DB: mongodb://localhost - - name: codecov + REEARTH_CMS_DB: mongodb://localhost + - name: Send coverage report uses: codecov/codecov-action@v4 with: flags: worker - file: coverage.txt + file: coverage.txt \ No newline at end of file diff --git a/.github/workflows/pr_title.yml b/.github/workflows/pr.yml similarity index 76% rename from .github/workflows/pr_title.yml rename to .github/workflows/pr.yml index 06179c4f4c..09bf18e614 100644 --- a/.github/workflows/pr_title.yml +++ b/.github/workflows/pr.yml @@ -1,4 +1,4 @@ -name: PR Title Checker +name: PR on: pull_request: types: @@ -8,12 +8,17 @@ on: - labeled - unlabeled jobs: - pr_title: + labeler: + name: labeler runs-on: ubuntu-latest steps: - uses: actions/labeler@v5 with: repo-token: ${{ secrets.GITHUB_TOKEN }} + title_check: + name: title check + runs-on: ubuntu-latest + steps: - uses: amannn/action-semantic-pull-request@v5 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -27,3 +32,11 @@ jobs: The subject "{subject}" found in the pull request title "{title}" didn't match the configured pattern. Please ensure that the subject doesn't start with an uppercase character. + pr_title: + runs-on: ubuntu-latest + needs: + - labeler + - title_check + if: '!failure()' + steps: + - run: echo OK