coverage #141
This file contains hidden or 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
| # Copyright 2026 FlagOS Contributors | |
| # | |
| # Licensed under the Apache License, Version 2.0 (the "License"); | |
| # you may not use this file except in compliance with the License. | |
| # You may obtain a copy of the License at | |
| # | |
| # http://www.apache.org/licenses/LICENSE-2.0 | |
| # | |
| # Unless required by applicable law or agreed to in writing, software | |
| # distributed under the License is distributed on an "AS IS" BASIS, | |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| # See the License for the specific language governing permissions and | |
| # limitations under the License. | |
| # Note this *workflow_run* workflow runs on the default branch. | |
| name: coverage | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| run_id: | |
| description: 'The workflow run ID' | |
| required: true | |
| type: string | |
| workflow_run: | |
| workflows: | |
| - daily | |
| types: | |
| - completed | |
| jobs: | |
| publish-coverage: | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| with: | |
| ref: gh-pages | |
| - id: download | |
| uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 | |
| with: | |
| result-encoding: string | |
| script: | | |
| if (context.eventName === 'workflow_dispatch') { | |
| run_id = context.payload.inputs.run_id; | |
| } else { | |
| run_id = context.payload.workflow_run.id; | |
| } | |
| console.log(`Fetch artifact for ${run_id}`); | |
| let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| run_id: run_id, | |
| }); | |
| let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => { | |
| return artifact.name == "op-ut-coverage"; | |
| })[0]; | |
| // There could be a case that no coverage data were generated. | |
| if (matchArtifact === undefined) { | |
| return "NO_DATA"; | |
| } else { | |
| console.log(`Found artifact ${matchArtifact.id}`); | |
| let download = await github.rest.actions.downloadArtifact({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| artifact_id: matchArtifact.id, | |
| archive_format: 'zip', | |
| }); | |
| const fs = require('fs'); | |
| const path = require('path'); | |
| const temp = '${{ runner.temp }}/artifacts'; | |
| if (!fs.existsSync(temp)){ | |
| fs.mkdirSync(temp); | |
| } | |
| fs.writeFileSync(path.join(temp, 'op-ut-coverage.zip'), Buffer.from(download.data)); | |
| return "HAS_DATA"; | |
| } | |
| - id: unzip-artifact | |
| if: ${{ steps.download.outputs.result == 'HAS_DATA' }} | |
| run: unzip "${{ runner.temp }}/artifacts/op-ut-coverage.zip" -d "${{ runner.temp }}/artifacts" | |
| - id: prepare-changes | |
| if: ${{ steps.download.outputs.result == 'HAS_DATA' }} | |
| shell: bash | |
| run: | | |
| COV_ID=$(cat ${{ runner.temp }}/artifacts/COVERAGE_ID) | |
| # Strip any newline characters to prevent environment variable injection | |
| COV_ID=${COV_ID//$'\r'/} | |
| COV_ID=${COV_ID//$'\n'/} | |
| # Ensure COV_ID only contains safe characters (alphanumerics, underscore, dash) | |
| if ! [[ "$COV_ID" =~ ^[A-Za-z0-9_-]+$ ]]; then | |
| echo "Invalid COVERAGE_ID value: '$COV_ID'" >&2 | |
| exit 1 | |
| fi | |
| echo "COV_ID=${COV_ID}" > "$GITHUB_ENV" | |
| DATE=${COV_ID:0:8} | |
| rm -fr docs/static/coverage/${COV_ID}* | |
| mkdir -p docs/static/coverage/${COV_ID} | |
| mv ${{ runner.temp }}/artifacts/htmlcov/* docs/static/coverage/${COV_ID}/ | |
| mv ${{ runner.temp }}/artifacts/ut-summary.md docs/content/en/references/test/unit/${DATE}-summary.md | |
| - id: commit-change | |
| if: ${{ steps.download.outputs.result == 'HAS_DATA' }} | |
| run: | | |
| git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| git config --local user.name "github-actions[bot]" | |
| git add docs | |
| git commit -a -m "Add coverage data for ${COV_ID}" | |
| - id: push-change | |
| if: ${{ steps.download.outputs.result == 'HAS_DATA' }} | |
| uses: ad-m/github-push-action@881a6320fdb16eb5318c5054f31c218aec2b324c # v1.3.0 | |
| with: | |
| branch: gh-pages | |
| github_token: ${{ secrets.GITHUB_TOKEN }} |