Report on physmon #2
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
| name: Report on physmon | |
| on: | |
| workflow_run: | |
| workflows: [Builds] | |
| types: | |
| - completed | |
| jobs: | |
| post_comment: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v5 | |
| - name: 'Download artifact' | |
| uses: actions/github-script@v8 | |
| id: dl-af | |
| with: | |
| script: | | |
| console.log(`Getting artifacts for workflow run id: ${context.payload.workflow_run.id}`); | |
| let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| run_id: context.payload.workflow_run.id, | |
| }); | |
| let matchArtifacts = allArtifacts.data.artifacts.filter((artifact) => { | |
| return artifact.name == 'physmon' | |
| }); | |
| if(matchArtifacts.length == 0) { | |
| console.log("Could not find artifact"); | |
| return false; | |
| } | |
| let matchArtifact = matchArtifacts[0]; | |
| console.log(`Artifact id is: ${matchArtifact.id}`); | |
| let download = await github.rest.actions.downloadArtifact({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| artifact_id: matchArtifact.id, | |
| archive_format: 'zip', | |
| }); | |
| let fs = require('fs'); | |
| fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/physmon.zip`, Buffer.from(download.data)); | |
| let = url = `https://acts-herald.app.cern.ch/view/${process.env.GITHUB_REPOSITORY}/${matchArtifact.id}`; | |
| // Check if any other comment artifacts are available | |
| let matchCommentArtifacts = allArtifacts.data.artifacts.filter((artifact) => { | |
| return artifact.name.startsWith('comment-') | |
| }); | |
| core.setOutput('comment-artifacts-found', matchCommentArtifacts.length >= 1); | |
| core.exportVariable('ARTIFACT_URL', url) | |
| return true; | |
| - name: 'Unzip artifact' | |
| if: steps.dl-af.outputs.result != 'false' | |
| run: unzip -d $GITHUB_WORKSPACE/physmon $GITHUB_WORKSPACE/physmon.zip | |
| - name: 'Determine PR number' | |
| id: get-pr-number | |
| if: steps.dl-af.outputs.result != 'false' | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| PR_TARGET_REPO: ${{ github.repository }} | |
| PR_BRANCH: |- | |
| ${{ | |
| (github.event.workflow_run.head_repository.owner.login != github.event.workflow_run.repository.owner.login) | |
| && format('{0}:{1}', github.event.workflow_run.head_repository.owner.login, github.event.workflow_run.head_branch) | |
| || github.event.workflow_run.head_branch | |
| }} | |
| run: | | |
| gh pr view --repo "${PR_TARGET_REPO}" "${PR_BRANCH}" \ | |
| --json 'number,headRefOid' \ | |
| --jq '"PR_NUMBER=\(.number)\nPR_SHA=\(.headRefOid)"' \ | |
| >> $GITHUB_OUTPUT | |
| # ping the url, triggers caching of the artifact | |
| - name: Prime cache | |
| if: steps.get-pr-number.outcome == 'success' | |
| run: curl -sL $ARTIFACT_URL | |
| - uses: actions/setup-python@v6 | |
| with: | |
| python-version: '3.12' | |
| - uses: actions/download-artifact@v6 | |
| if: steps.dl-af.outputs.comment-artifacts-found | |
| with: | |
| pattern: comment-*.md | |
| merge-multiple: true | |
| github-token: ${{ github.token }} | |
| repository: ${{ github.event.workflow_run.repository.full_name }} | |
| run-id: ${{ github.event.workflow_run.id }} | |
| - name: Render comment | |
| if: steps.get-pr-number.outcome == 'success' | |
| env: | |
| PR_SHA: ${{ steps.get-pr-number.outputs.PR_SHA }} | |
| run: | | |
| ls -al $GITHUB_WORKSPACE/physmon | |
| echo "# 📊: Physics performance monitoring for ${PR_SHA}" >> comment.md | |
| echo "[Full contents](${ARTIFACT_URL})" >> comment.md | |
| if [ -f "$GITHUB_WORKSPACE/physmon/summary.md" ]; then | |
| cat $GITHUB_WORKSPACE/physmon/summary.md >> comment.md | |
| else | |
| echo "🟥 summary not found!" >> comment.md | |
| fi | |
| cat comment-*.md >> comment.md || true | |
| cat comment.md | |
| - name: Find Comment | |
| if: steps.get-pr-number.outcome == 'success' | |
| uses: peter-evans/find-comment@v4 | |
| id: fc | |
| with: | |
| issue-number: ${{ steps.get-pr-number.outputs.PR_NUMBER }} | |
| comment-author: 'github-actions[bot]' | |
| body-includes: Physics performance monitoring | |
| - name: Create or update comment | |
| if: steps.get-pr-number.outcome == 'success' | |
| uses: peter-evans/create-or-update-comment@v5 | |
| with: | |
| comment-id: ${{ steps.fc.outputs.comment-id }} | |
| issue-number: ${{ steps.get-pr-number.outputs.PR_NUMBER }} | |
| body-file: comment.md | |
| edit-mode: replace | |
| - name: Post failure notifications to EIC/ePIC mattermost | |
| if: steps.get-pr-number.outcome == 'success' | |
| env: | |
| EIC_EPIC_MATTERMOST_HOOK_URL: ${{secrets.EIC_EPIC_MATTERMOST_HOOK_URL}} | |
| run: | | |
| if [ -f comment-50-external-failure.md ] ; then | |
| echo "{\"text\":\"External pipeline failure in ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}?pr=${{steps.get-pr-number.outputs.PR_NUMBER}}.\"}" | tee data.json | |
| curl -X POST -H 'Content-type: application/json' --data "@data.json" ${EIC_EPIC_MATTERMOST_HOOK_URL} | |
| fi |