From df18b595b8c39ff6cadb5f00478c621bccb22f4f Mon Sep 17 00:00:00 2001 From: cephaschapa Date: Thu, 15 Feb 2024 15:30:38 +0200 Subject: [PATCH 01/11] added code coverage workflow, ci script --- app/package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/app/package.json b/app/package.json index dc0c3691a..177172855 100644 --- a/app/package.json +++ b/app/package.json @@ -21,6 +21,7 @@ "db:gen-migration": "sequelize-cli migration:generate --name", "db:gen-seed": "sequelize-cli seed:generate --name", "sync-catalogue": "tsx scripts/catalogue-sync.ts", + "ci:test": "node --test --experimental-test-coverage src/**/*.test.ts", "cy:open": "cypress open", "cy:run": "cypress run", "cy:test": "start-server-and-test start http://localhost:3000/en/auth/login cy:run", From f226e9f2ac6aa88362d41b0c4ed0a2d07c12ad9e Mon Sep 17 00:00:00 2001 From: cephaschapa Date: Thu, 15 Feb 2024 15:32:14 +0200 Subject: [PATCH 02/11] added code coverage workflow --- .github/workflows/coverage-report.yml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 .github/workflows/coverage-report.yml diff --git a/.github/workflows/coverage-report.yml b/.github/workflows/coverage-report.yml new file mode 100644 index 000000000..c763a4266 --- /dev/null +++ b/.github/workflows/coverage-report.yml @@ -0,0 +1,14 @@ +name: Coverage report +on: + pull_request: + branches: + - develop +jobs: + coverage: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: artiomtr/jest-coverage-report-action@v1.3 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + # threshold: 80 # optional parameter From 46b82711e7c01627350d5ef65e6b2a5a4dce1ea5 Mon Sep 17 00:00:00 2001 From: cephaschapa Date: Thu, 15 Feb 2024 16:19:24 +0200 Subject: [PATCH 03/11] fix(ci):coverage workflow changes --- .github/workflows/coverage-report.yml | 14 ---- .github/workflows/web-actions.yml | 98 ++++++++++++++++----------- 2 files changed, 58 insertions(+), 54 deletions(-) delete mode 100644 .github/workflows/coverage-report.yml diff --git a/.github/workflows/coverage-report.yml b/.github/workflows/coverage-report.yml deleted file mode 100644 index c763a4266..000000000 --- a/.github/workflows/coverage-report.yml +++ /dev/null @@ -1,14 +0,0 @@ -name: Coverage report -on: - pull_request: - branches: - - develop -jobs: - coverage: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: artiomtr/jest-coverage-report-action@v1.3 - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - # threshold: 80 # optional parameter diff --git a/.github/workflows/web-actions.yml b/.github/workflows/web-actions.yml index 4758c7614..61cac4a58 100644 --- a/.github/workflows/web-actions.yml +++ b/.github/workflows/web-actions.yml @@ -9,7 +9,7 @@ on: - k8s/cc-web-deploy.yml - k8s/cc-web.yml - .github/workflows/web-actions.yml - branches: [ "develop" ] + branches: ["develop"] pull_request: jobs: @@ -28,7 +28,7 @@ jobs: - uses: actions/setup-node@v4 with: node-version: 20 - cache: 'npm' + cache: "npm" cache-dependency-path: app/package-lock.json - name: Install dependencies @@ -55,30 +55,49 @@ jobs: - name: Shut down database run: docker stop github_action_postgresql + runCoverageTest: + name: Generate coverage report + needs: runTests + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + # ... Generate LCOV files or download it from a different job + - name: Setup LCOV + uses: hrishikesh-kadam/setup-lcov@v1 + - name: Report code coverage + uses: zgosalvez/github-actions-report-lcov@v3 + with: + coverage-files: coverage/lcov.*.info + minimum-coverage: 90 + artifact-name: code-coverage-report + github-token: ${{ secrets.GITHUB_TOKEN }} + working-directory: ./app + update-comment: true + pushToGHCR: needs: runTests runs-on: ubuntu-latest if: github.ref == 'refs/heads/develop' steps: + - uses: actions/checkout@v4 - - uses: actions/checkout@v4 - - - name: Log in to the Container registry - uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Pushing CC Web to GHCR - env: - VERSION: ${{ github.sha }} - IMAGE: ghcr.io/open-earth-foundation/citycatalyst - run: | - docker build -t $IMAGE:$VERSION app - docker tag $IMAGE:$VERSION $IMAGE:latest - docker push $IMAGE:$VERSION - docker push $IMAGE:latest + - name: Log in to the Container registry + uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Pushing CC Web to GHCR + env: + VERSION: ${{ github.sha }} + IMAGE: ghcr.io/open-earth-foundation/citycatalyst + run: | + docker build -t $IMAGE:$VERSION app + docker tag $IMAGE:$VERSION $IMAGE:latest + docker push $IMAGE:$VERSION + docker push $IMAGE:latest deployToEKS: needs: pushToGHCR @@ -89,24 +108,23 @@ jobs: AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY_EKS_DEV_USER }} EKS_DEV_NAME: ${{ secrets.EKS_DEV_NAME }} steps: + - uses: actions/checkout@v4 - - uses: actions/checkout@v4 - - - name: Creating kubeconfig file - run: aws eks update-kubeconfig --name ${{secrets.EKS_DEV_NAME}} --region us-east-1 - - - name: Testing connection to EKS - run: kubectl get pods -n default - - - name: Deploying service - run: | - kubectl create -f k8s/cc-migrate.yml -n default - kubectl create -f k8s/cc-seed.yml -n default - kubectl apply -f k8s/cc-sync-catalogue.yml -n default - # kubectl create job --from=cronjob/cc-sync-catalogue cc-sync-catalogue-manual -n default - kubectl apply -f k8s/cc-web-deploy.yml -n default - kubectl set env deployment/cc-web-deploy SMTP_USER=${{secrets.SMTP_USER}} - kubectl set env deployment/cc-web-deploy SMTP_PASSWORD=${{secrets.SMTP_PASSWORD}} - kubectl set env deployment/cc-web-deploy NEXTAUTH_SECRET=${{secrets.NEXTAUTH_SECRET}} - kubectl set env deployment/cc-web-deploy RESET_TOKEN_SECRET=${{secrets.RESET_TOKEN_SECRET}} - kubectl rollout restart deployment cc-web-deploy -n default + - name: Creating kubeconfig file + run: aws eks update-kubeconfig --name ${{secrets.EKS_DEV_NAME}} --region us-east-1 + + - name: Testing connection to EKS + run: kubectl get pods -n default + + - name: Deploying service + run: | + kubectl create -f k8s/cc-migrate.yml -n default + kubectl create -f k8s/cc-seed.yml -n default + kubectl apply -f k8s/cc-sync-catalogue.yml -n default + # kubectl create job --from=cronjob/cc-sync-catalogue cc-sync-catalogue-manual -n default + kubectl apply -f k8s/cc-web-deploy.yml -n default + kubectl set env deployment/cc-web-deploy SMTP_USER=${{secrets.SMTP_USER}} + kubectl set env deployment/cc-web-deploy SMTP_PASSWORD=${{secrets.SMTP_PASSWORD}} + kubectl set env deployment/cc-web-deploy NEXTAUTH_SECRET=${{secrets.NEXTAUTH_SECRET}} + kubectl set env deployment/cc-web-deploy RESET_TOKEN_SECRET=${{secrets.RESET_TOKEN_SECRET}} + kubectl rollout restart deployment cc-web-deploy -n default From 2b900057419fd45e1ce92a33f41581e8664f6006 Mon Sep 17 00:00:00 2001 From: cephaschapa Date: Thu, 15 Feb 2024 18:21:24 +0200 Subject: [PATCH 04/11] fix(action): test run script workflow changes --- app/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/package.json b/app/package.json index 177172855..317b2308d 100644 --- a/app/package.json +++ b/app/package.json @@ -21,7 +21,7 @@ "db:gen-migration": "sequelize-cli migration:generate --name", "db:gen-seed": "sequelize-cli seed:generate --name", "sync-catalogue": "tsx scripts/catalogue-sync.ts", - "ci:test": "node --test --experimental-test-coverage src/**/*.test.ts", + "ci:test": "tsx --test --experimental-test-coverage tests/**/*.test.ts", "cy:open": "cypress open", "cy:run": "cypress run", "cy:test": "start-server-and-test start http://localhost:3000/en/auth/login cy:run", From 35283b11af9ca6c89a3ce8bacc7fae46bc1d4a1e Mon Sep 17 00:00:00 2001 From: cephaschapa Date: Thu, 15 Feb 2024 18:21:52 +0200 Subject: [PATCH 05/11] fix(ci):coverage workflow changes --- .github/workflows/web-actions.yml | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/.github/workflows/web-actions.yml b/.github/workflows/web-actions.yml index 61cac4a58..e410d8fa2 100644 --- a/.github/workflows/web-actions.yml +++ b/.github/workflows/web-actions.yml @@ -46,35 +46,28 @@ jobs: - name: Run NextJS build run: npm run build - - name: Run API tests - run: npm run api:test - # - name: Run Cypress tests # run: npm run cy:test - - name: Shut down database - run: docker stop github_action_postgresql - - runCoverageTest: - name: Generate coverage report - needs: runTests - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v2 # ... Generate LCOV files or download it from a different job + - name: generate coverage file + run: npm run ci:test + - name: Setup LCOV uses: hrishikesh-kadam/setup-lcov@v1 - name: Report code coverage uses: zgosalvez/github-actions-report-lcov@v3 with: - coverage-files: coverage/lcov.*.info - minimum-coverage: 90 + coverage-files: ./app/coverage/lcov.*.info + minimum-coverage: 40 artifact-name: code-coverage-report github-token: ${{ secrets.GITHUB_TOKEN }} working-directory: ./app update-comment: true + - name: Shut down database + run: docker stop github_action_postgresql + pushToGHCR: needs: runTests runs-on: ubuntu-latest From c643df65377c84bfdd3f7470857ba5fdac1554d8 Mon Sep 17 00:00:00 2001 From: Milan Gruner Date: Mon, 4 Mar 2024 10:56:22 +0100 Subject: [PATCH 06/11] Ignore lcov.info test coverage info file --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index b1aaa670e..594383785 100644 --- a/.gitignore +++ b/.gitignore @@ -138,3 +138,7 @@ values-*.yml # Data coverage output global-api/data-coverage/*.csv + +# Test coverage output from ci:test +lcov.info + From c59a39bc125fe9ea8395595f1625cafc10f3b07c Mon Sep 17 00:00:00 2001 From: Milan Gruner Date: Mon, 4 Mar 2024 10:56:43 +0100 Subject: [PATCH 07/11] Save test coverage file in npm script ci:test --- app/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/package.json b/app/package.json index b211eb39a..be99c12c8 100644 --- a/app/package.json +++ b/app/package.json @@ -21,7 +21,7 @@ "db:gen-migration": "sequelize-cli migration:generate --name", "db:gen-seed": "sequelize-cli seed:generate --name", "sync-catalogue": "tsx scripts/catalogue-sync.ts", - "ci:test": "tsx --test --experimental-test-coverage tests/**/*.test.ts", + "ci:test": "tsx --test --experimental-test-coverage --test-reporter=lcov --test-reporter-destination=lcov.info tests/**/*.test.ts", "cy:open": "cypress open", "cy:run": "cypress run", "cy:test": "start-server-and-test start http://localhost:3000/en/auth/login cy:run", From 4f5efce888f8211be79d0d337a041632b85a2ed6 Mon Sep 17 00:00:00 2001 From: Milan Gruner Date: Mon, 4 Mar 2024 10:59:04 +0100 Subject: [PATCH 08/11] Adjust path to test coverage files in Github Action Signed-off-by: Milan Gruner --- .github/workflows/web-actions.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/web-actions.yml b/.github/workflows/web-actions.yml index 87d575da4..f0ce539d2 100644 --- a/.github/workflows/web-actions.yml +++ b/.github/workflows/web-actions.yml @@ -58,7 +58,7 @@ jobs: - name: Report code coverage uses: zgosalvez/github-actions-report-lcov@v3 with: - coverage-files: ./app/coverage/lcov.*.info + coverage-files: ./app/lcov*.info minimum-coverage: 40 artifact-name: code-coverage-report github-token: ${{ secrets.GITHUB_TOKEN }} From 216568364b1c77c1adb9e464d7a0b5f11599835f Mon Sep 17 00:00:00 2001 From: Milan Gruner Date: Mon, 4 Mar 2024 11:02:05 +0100 Subject: [PATCH 09/11] Adjust name for for test step in Github Action Signed-off-by: Milan Gruner --- .github/workflows/web-actions.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/web-actions.yml b/.github/workflows/web-actions.yml index f0ce539d2..c6446a826 100644 --- a/.github/workflows/web-actions.yml +++ b/.github/workflows/web-actions.yml @@ -50,7 +50,7 @@ jobs: # run: npm run cy:test # ... Generate LCOV files or download it from a different job - - name: generate coverage file + - name: Run tests and generate coverage file run: npm run ci:test - name: Setup LCOV From 27ba5f70fefd142dcada954b81941bb362d20011 Mon Sep 17 00:00:00 2001 From: Milan Gruner Date: Mon, 4 Mar 2024 11:22:19 +0100 Subject: [PATCH 10/11] Setup Codecov in Github Action Signed-off-by: Milan Gruner --- .github/workflows/web-actions.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/web-actions.yml b/.github/workflows/web-actions.yml index c6446a826..0ed5f6954 100644 --- a/.github/workflows/web-actions.yml +++ b/.github/workflows/web-actions.yml @@ -65,6 +65,12 @@ jobs: working-directory: ./app update-comment: true + - name: Upload coverage reports to Codecov + uses: codecov/codecov-action@v4.0.1 + with: + token: ${{ secrets.CODECOV_TOKEN }} + slug: Open-Earth-Foundation/CityCatalyst + - name: Shut down database run: docker stop github_action_postgresql From e95d21e1376522a1665487e4a45548133d8e8759 Mon Sep 17 00:00:00 2001 From: Milan Gruner Date: Mon, 4 Mar 2024 11:33:56 +0100 Subject: [PATCH 11/11] Add codecov badge to README.md Signed-off-by: Milan Gruner --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c94655ad0..a6cc6381e 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,5 @@ -# OpenClimate for Cities +# CityCatalyst Open Source carbon accounting for cities + +## Test coverage +[![codecov](https://codecov.io/github/Open-Earth-Foundation/CityCatalyst/graph/badge.svg?token=FD69J1XR6M)](https://codecov.io/github/Open-Earth-Foundation/CityCatalyst)