Skip to content

Commit

Permalink
chore: Add weekly coverage run to Ci, publish to GitHub pages, create…
Browse files Browse the repository at this point in the history
… and upload TiCS report (#5570)

- remove coverage runs from `test.yaml` as we do not want to involve a full TiCS measurement on every MP/push
- add coverage runs to their own `coverage.yaml` job
  - add cronjob to run this weekly
  - add  coverage run with istanbul, create cobertura compatible output in `.coverage` for TiCS
  - edit workflow so that less copying up-/and downloading is done
  - fix TiCS, make sure coverage is uploaded to https://canonical.github.io/maas-ui/
  - setup job so that a push to `ci-tics-main` is always provoking a run so that we can test things

Co-authored-by: Peter Makowski <[email protected]>
Co-authored-by: Jack Lloyd-Walters <[email protected]>
  • Loading branch information
3 people authored Jan 6, 2025
1 parent cb06baf commit 52960a1
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 75 deletions.
101 changes: 101 additions & 0 deletions .github/workflows/coverage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
name: Test coverage and TiCS Report
on:
push:
branches:
- ci-tics-main
schedule: # uses last commit on default branch (main)
- cron: "30 0 * * 6" # At 0:30 on Saturday
# temporarily disabling client mode due to quota
# pull_request:
# types: [opened, synchronize, reopened]

jobs:
test-coverage-tics:
name: Run tests with coverage and generate TiCS report
runs-on: ubuntu-latest
timeout-minutes: 720
steps:
- uses: actions/checkout@v4

- name: Restore node_modules from cache
id: yarn-cache
uses: actions/cache@v4
with:
path: "**/node_modules"
key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}

- name: Setup Node.js from .nvmrc
uses: actions/setup-node@v4
with:
node-version-file: ".nvmrc"

- name: Install packages if cache is outdated
if: steps.yarn-cache.outputs.cache-hit != 'true'
run: CYPRESS_INSTALL_BINARY=0 yarn install

- name: Run tests with coverage
run: yarn test-coverage

- name: Upload coverage report
if: always()
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: coverage
retention-days: 1

- name: Run TICS Analyzer
uses: tiobe/tics-github-action@v3
with:
# Use 'qserver' mode for weekly runs and on push to ci-tics-main to
# generate reference points
# Use 'client' mode for runs on PRs. Client is a quality gate comparing
# changed files to the reference points and can fail if quality degrades
# See:
# https://github.com/tiobe/tics-github-action?tab=readme-ov-file#tics-github-action
mode: ${{ github.event_name == 'pull_request' && 'client' || 'qserver' }}
project: maas-ui
viewerUrl: https://canonical.tiobe.com/tiobeweb/TICS/api/cfg?name=default
ticsAuthToken: ${{ secrets.TICSAUTHTOKEN }}
installTics: true
tmpdir: /tmp/tics
branchdir: ${{ github.workspace }}

- name: Upload TICS Report
uses: actions/upload-artifact@v4
with:
name: tics-report
path: /tmp/tics
retention-days: 7

publish-coverage-report:
name: Publish Coverage Report
# if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
needs: test-coverage-tics
continue-on-error: true

permissions:
id-token: write
pages: write

steps:
- uses: actions/checkout@v4

- name: Download coverage report
uses: actions/download-artifact@v4
with:
name: coverage-report
path: coverage

- name: Setup Pages
uses: actions/configure-pages@v5

- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: coverage

- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
75 changes: 4 additions & 71 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,19 @@ jobs:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4

- name: Restore node_modules
id: yarn-cache
uses: actions/cache@v4
with:
path: "**/node_modules"
key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}

- name: Use Node.js from .nvmrc
uses: actions/setup-node@v4
with:
node-version-file: ".nvmrc"

- name: Install
if: steps.yarn-cache.outputs.cache-hit != 'true'
run: CYPRESS_INSTALL_BINARY=0 yarn install
Expand All @@ -44,77 +47,7 @@ jobs:
- name: Install
if: steps.yarn-cache.outputs.cache-hit != 'true'
run: CYPRESS_INSTALL_BINARY=0 yarn install
- run: yarn test:ci
- name: Upload coverage report
if: always()
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: coverage
retention-days: 1

publish-coverage-report:
name: Publish Coverage Report
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
needs: test

permissions:
id-token: write
pages: write
steps:
- uses: actions/checkout@v4

- name: Download coverage report
uses: actions/download-artifact@v4
with:
name: coverage-report
path: coverage

- name: Setup Pages
uses: actions/configure-pages@v5

- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: coverage

- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4

tics-report:
name: TICS Report
runs-on: ubuntu-latest
needs: test
steps:
- name: Download coverage report
uses: actions/download-artifact@v4
with:
name: coverage-report
path: .coverage
- name: Display structure of downloaded files
run: ls -R .coverage
- uses: actions/checkout@v4
- name: Run TICS Analyzer
uses: tiobe/tics-github-action@v3
with:
# Use 'qserver' for push to main branch, 'client' for others. See: https://github.com/tiobe/tics-github-action?tab=readme-ov-file#client-default
mode: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' && 'qserver' || 'client' }}
project: maas-ui
viewerUrl: https://canonical.tiobe.com/tiobeweb/TICS/api/cfg?name=default
ticsAuthToken: ${{ secrets.TICSAUTHTOKEN }}
installTics: true
tmpdir: /tmp/tics
branchdir: ${{ github.workspace }}

- name: Upload TICS Report
if: always()
uses: actions/upload-artifact@v4
with:
name: tics-report
path: /tmp/tics
retention-days: 7
- run: yarn test

build:
name: Build
Expand Down
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,9 @@
"sitespeed": "docker run -v \"$(pwd)/sitespeed.io:/sitespeed.io\" --add-host=host.docker.internal:host-gateway sitespeedio/sitespeed.io:25.2.1 --config /sitespeed.io/config.json /sitespeed.io/scripts/machines.js --multi --spa --browsertime.domain=host.docker.internal --browsertime.port=8400 --browsertime.iterations=1",
"start": "concurrently \"yarn serve-proxy\" \"yarn serve-react\" \"yarn show-ready\"",
"test-cypress": "start-server-and-test start '8401' serve-base 'tcp:8400' cypress-run",
"test-ui": "TZ=UTC vitest",
"test:debug": "vitest --inspect-brk test --runInBand --no-cache --testTimeout=100000000",
"test": "yarn test-ui",
"test-coverage": "yarn test-ui -- --coverage",
"test:ci": "yarn test-coverage",
"test": "TZ=UTC yarn vitest",
"test-coverage": "yarn test --coverage",
"unlink-components": "yarn unlink react && yarn unlink \"@canonical/react-components\"",
"wait-on-ui": "wait-on http-get://0.0.0.0:8400/MAAS/r",
"storybook": "storybook dev -p 6006",
Expand Down
6 changes: 6 additions & 0 deletions vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ export default defineConfig({
exclude: [...configDefaults.exclude, "**/tests/**"],
clearMocks: true,
coverage: {
// use instrumented coverage via istanbul instead of v8
provider: "istanbul",
reporter: [
["text"],
["html"],
["cobertura", { file: "../.coverage/cobertura-coverage.xml" }],
],
},
},
});

0 comments on commit 52960a1

Please sign in to comment.