Automated tests - publish results #19
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: Automated tests - publish results | |
| on: | |
| workflow_run: | |
| workflows: | |
| - Automated tests | |
| types: | |
| - completed | |
| - requested | |
| env: | |
| isCompleted: ${{ github.event.workflow_run.status == 'completed' }} | |
| jobs: | |
| get-pr-data: | |
| runs-on: ubuntu-latest | |
| concurrency: | |
| group: github-api-request | |
| cancel-in-progress: false | |
| if: ${{ github.event.workflow_run.event == 'pull_request' }} | |
| outputs: | |
| pr-number: ${{ steps.pr.outputs.result || steps.set-env.outputs.pr-number }} | |
| workflow-id: ${{ github.event.workflow_run.id || steps.set-env.outputs.workflow-id }} | |
| steps: | |
| - name: Find associated pull request | |
| if: ${{ !fromJson(env.isCompleted) }} | |
| id: pr | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const response = await github.rest.search.issuesAndPullRequests({ | |
| q: 'repo:${{ github.repository }} is:pr sha:${{ github.event.workflow_run.head_sha }}', | |
| per_page: 1, | |
| }) | |
| const items = response.data.items | |
| if (items.length < 1) { | |
| console.error('No PRs found') | |
| return | |
| } | |
| const pullRequestNumber = items[0].number | |
| return pullRequestNumber | |
| - name: Download PR artifact | |
| if: ${{ fromJson(env.isCompleted) }} | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| try { | |
| let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| run_id: context.payload.workflow_run.id, | |
| }); | |
| let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => { | |
| return artifact.name == "pr-comment-data" | |
| })[0]; | |
| if (!matchArtifact) { | |
| console.log('No artifact found'); | |
| return; | |
| } | |
| 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}/pr-comment-data.zip`, Buffer.from(download.data)); | |
| } catch (error) { | |
| console.log('Error downloading artifact:', error); | |
| } | |
| - name: Check if artifact data was provided | |
| if: ${{ fromJson(env.isCompleted) }} | |
| id: check-artifact | |
| run: | | |
| if [[ -f "pr-comment-data.zip" ]]; then | |
| echo "ARTIFACT_DATA_PROVIDED=true" >> "$GITHUB_ENV" | |
| else | |
| echo "ARTIFACT_DATA_PROVIDED=false" >> "$GITHUB_ENV" | |
| fi | |
| - name: Unzip artifact | |
| if: ${{ fromJson(env.isCompleted) && env.ARTIFACT_DATA_PROVIDED == 'true' }} | |
| run: unzip pr-comment-data.zip | |
| - name: Set env variables from artifact | |
| if: ${{ fromJson(env.isCompleted) && env.ARTIFACT_DATA_PROVIDED == 'true' }} | |
| id: set-env | |
| run: | | |
| if [ -f ./pr_number ] && [ -f ./workflow_id ]; then | |
| echo "pr-number=$(cat ./pr_number)" >> $GITHUB_OUTPUT | |
| echo "workflow-id=$(cat ./workflow_id)" >> $GITHUB_OUTPUT | |
| else | |
| echo "Required files not found in artifact" | |
| fi | |
| publish-test-results: | |
| runs-on: ubuntu-latest | |
| needs: get-pr-data | |
| if: ${{ needs.get-pr-data.outputs.pr-number && needs.get-pr-data.outputs.workflow-id }} | |
| steps: | |
| - name: Publish Test Results | |
| run: echo "hello world" | |
| comment-pr: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| pull-requests: write | |
| needs: get-pr-data | |
| if: ${{ needs.get-pr-data.outputs.pr-number && needs.get-pr-data.outputs.workflow-id }} | |
| steps: | |
| - name: Find Comment | |
| uses: peter-evans/find-comment@v3 | |
| id: fc | |
| with: | |
| issue-number: ${{ needs.get-pr-data.outputs.pr-number }} | |
| comment-author: "github-actions[bot]" | |
| body-includes: Automated tests Summary | |
| - name: Remove previous comment | |
| if: steps.fc.outputs.comment-id != '' | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| github.rest.issues.deleteComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| comment_id: ${{ steps.fc.outputs.comment-id }} | |
| }) | |
| - name: In progress tests comment | |
| if: ${{ !fromJson(env.isCompleted) }} | |
| uses: peter-evans/create-or-update-comment@v4 | |
| with: | |
| issue-number: ${{ needs.get-pr-data.outputs.pr-number }} | |
| body: | | |
| <h1>Automated tests Summary</h1> | |
| <h3><strong>:hourglass_flowing_sand:</strong> Tests are running...</h3> | |
| - name: Passing tests comment | |
| if: ${{ github.event.workflow_run.conclusion == 'success' }} | |
| uses: peter-evans/create-or-update-comment@v4 | |
| with: | |
| issue-number: ${{ needs.get-pr-data.outputs.pr-number }} | |
| body: | | |
| <h1>Automated tests Summary</h1> | |
| <h3><strong>:white_check_mark:</strong> All the CI tests have passed!</h3> | |
| - name: Failing tests comment | |
| if: ${{ github.event.workflow_run.conclusion != 'success' && fromJson(env.isCompleted) }} | |
| uses: peter-evans/create-or-update-comment@v4 | |
| with: | |
| issue-number: ${{ needs.get-pr-data.outputs.pr-number }} | |
| body: | | |
| <h1> Automated tests Summary</h1> | |
| <h3><strong>:rotating_light:</strong> Test workflow has failed</h3> | |
| ___ | |
| [Click here](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ needs.get-pr-data.outputs.workflow-id }}) to check the action test reports (_to view the report locally, see the [docs](https://github.com/bigbluebutton/bigbluebutton/blob/v3.0.x-release/bigbluebutton-tests/playwright/README.md#check-test-results)_) |