|
50 | 50 | uses: ./.github/workflows/benchmark.yml |
51 | 51 | with: |
52 | 52 | branch: ${{ github.head_ref || github.ref_name }} |
| 53 | + |
| 54 | + fetch_beat_analyzer_report: |
| 55 | + name: Fetch previous beat analyzer report |
| 56 | + if: github.event.issue.pull_request != '' && startsWith(github.event.comment.body, '/beat-analyzer') |
| 57 | + runs-on: ubuntu-latest |
| 58 | + outputs: |
| 59 | + previous_snapshot: ${{ steps.report.outputs.previous_snapshot }} |
| 60 | + steps: |
| 61 | + - name: Fetch latest report |
| 62 | + uses: actions/github-script@v6 |
| 63 | + id: resolve |
| 64 | + with: |
| 65 | + script: | |
| 66 | + // Check if the issue is associated with a PR |
| 67 | + if (!context.payload.issue.pull_request) { |
| 68 | + console.log("This issue is not associated with a pull request."); |
| 69 | + return false; |
| 70 | + } |
| 71 | +
|
| 72 | + // Fetch PR details to get the branch |
| 73 | + const prResponse = await github.rest.pulls.get({ |
| 74 | + owner: context.repo.owner, |
| 75 | + repo: context.repo.repo, |
| 76 | + pull_number: context.payload.issue.number, |
| 77 | + }); |
| 78 | + const branch = prResponse.data.head.ref; |
| 79 | + console.log(`Resolved branch: ${branch}`); |
| 80 | +
|
| 81 | + const { data: workflow_runs } = await github.rest.actions.listWorkflowRuns({ |
| 82 | + owner: context.repo.owner, |
| 83 | + repo: context.repo.repo, |
| 84 | + workflow_id: 'release.yml', |
| 85 | + branch: branch, |
| 86 | + per_page: 1, |
| 87 | + }); |
| 88 | +
|
| 89 | + if (workflow_runs.workflow_runs.length === 0) { |
| 90 | + core.setFailed('No workflow runs found.'); |
| 91 | + return false; |
| 92 | + } |
| 93 | +
|
| 94 | + const latest_run_id = workflow_runs.workflow_runs[0].id; |
| 95 | +
|
| 96 | + const { data: artifacts } = await github.rest.actions.listWorkflowRunArtifacts({ |
| 97 | + owner: context.repo.owner, |
| 98 | + repo: context.repo.repo, |
| 99 | + run_id: latest_run_id, |
| 100 | + }); |
| 101 | +
|
| 102 | + if (artifacts.artifacts.length === 0) { |
| 103 | + console.log('No artifacts found.'); |
| 104 | + return false; |
| 105 | + } |
| 106 | +
|
| 107 | + // Filter artifacts by name |
| 108 | + const targetArtifact = artifacts.artifacts.find( |
| 109 | + artifact => artifact.name === "Beat analyzer report" |
| 110 | + ); |
| 111 | +
|
| 112 | + if (!targetArtifact) { |
| 113 | + console.log(`Artifact with name "${targetArtifactName}" not found.`); |
| 114 | + return false; |
| 115 | + } |
| 116 | +
|
| 117 | + console.log(`Found target artifact: ${targetArtifact.name}, ID: ${targetArtifact.id}`); |
| 118 | + console.log(`Download URL: ${targetArtifact.archive_download_url}`); |
| 119 | +
|
| 120 | + // Optionally, download the artifact |
| 121 | + const artifact_download_url = latest_artifact.archive_download_url; |
| 122 | + const artifact_response = await fetch(artifact_download_url, { |
| 123 | + headers: { |
| 124 | + 'Authorization': `token ${process.env.GITHUB_TOKEN}`, |
| 125 | + 'Accept': 'application/vnd.github.v3+json', |
| 126 | + }, |
| 127 | + }); |
| 128 | + const artifact_data = await artifact_response.buffer(); |
| 129 | +
|
| 130 | + const fs = require('fs'); |
| 131 | + fs.writeFileSync('report.zip', artifact_data); |
| 132 | + console.log('Artifact downloaded as report.zip'); |
| 133 | + return true; |
| 134 | + - name: Extra report |
| 135 | + if: steps.resolve.outputs.result == 'true' |
| 136 | + id: report |
| 137 | + run: | |
| 138 | + unzip report.zip |
| 139 | + ls -l |
| 140 | + echo "previous_snapshot=$(base64 -w0 report/snapshot.json)" >> $GITHUB_OUTPUT |
| 141 | +
|
| 142 | + analyzer_report: |
| 143 | + needs: [fetch_beat_analyzer_report] |
| 144 | + if: needs.fetch_beat_analyzer_report.outcome == 'success' |
| 145 | + uses: ./.github/workflows/beat_analyzer.yml |
| 146 | + with: |
| 147 | + branch: ${{ github.head_ref || github.ref_name }} |
0 commit comments