|
| 1 | +# https://help.github.com/en/categories/automating-your-workflow-with-github-actions |
| 2 | + |
| 3 | +name: "PHAR Prefix Diff" |
| 4 | + |
| 5 | +on: |
| 6 | + pull_request: |
| 7 | + paths: |
| 8 | + - 'compiler/**' |
| 9 | + - '.github/workflows/phar-prefix-diff.yml' |
| 10 | + |
| 11 | +concurrency: |
| 12 | + group: phar-prefix-diff-${{ github.head_ref || github.run_id }} # will be canceled on subsequent pushes in pull requests but not branches |
| 13 | + cancel-in-progress: true |
| 14 | + |
| 15 | +jobs: |
| 16 | + phar-prefix-diff: |
| 17 | + name: "PHAR Prefix Diff" |
| 18 | + |
| 19 | + runs-on: "ubuntu-latest" |
| 20 | + timeout-minutes: 60 |
| 21 | + |
| 22 | + steps: |
| 23 | + - name: Get base commit SHA |
| 24 | + id: base |
| 25 | + run: echo "base_sha=${{ github.event.pull_request.base.sha }}" >> "$GITHUB_OUTPUT" |
| 26 | + |
| 27 | + - name: Find phar-file-checksum from base commit |
| 28 | + id: find-artifact |
| 29 | + uses: actions/github-script@v7 |
| 30 | + with: |
| 31 | + script: | |
| 32 | + const commitSha = `${{ steps.base.outputs.base_sha }}` |
| 33 | + const artifactName = "phar-file-checksum" |
| 34 | +
|
| 35 | + // Get all workflow runs for this commit |
| 36 | + const runs = await github.rest.actions.listWorkflowRunsForRepo({ |
| 37 | + owner: context.repo.owner, |
| 38 | + repo: context.repo.repo, |
| 39 | + per_page: 20, |
| 40 | + event: "push", |
| 41 | + head_sha: commitSha |
| 42 | + }); |
| 43 | +
|
| 44 | + if (runs.data.workflow_runs.length === 0) { |
| 45 | + core.setFailed(`No workflow runs found for commit ${commitSha}`); |
| 46 | + return; |
| 47 | + } |
| 48 | +
|
| 49 | +
|
| 50 | + const workflowRuns = runs.data.workflow_runs; |
| 51 | +
|
| 52 | + if (workflowRuns.length === 0) { |
| 53 | + core.setFailed(`No workflow runs found for commit ${commitSha}`); |
| 54 | + return; |
| 55 | + } |
| 56 | +
|
| 57 | + let found = false; |
| 58 | + for (const run of workflowRuns) { |
| 59 | + if (run.status !== "completed" || run.conclusion !== "success") { |
| 60 | + continue; |
| 61 | + } |
| 62 | +
|
| 63 | + if (run.name !== "Compile PHAR") { |
| 64 | + continue; |
| 65 | + } |
| 66 | +
|
| 67 | + const artifactsResp = await github.rest.actions.listWorkflowRunArtifacts({ |
| 68 | + owner: context.repo.owner, |
| 69 | + repo: context.repo.repo, |
| 70 | + run_id: run.id, |
| 71 | + }); |
| 72 | +
|
| 73 | + const artifact = artifactsResp.data.artifacts.find(a => a.name === artifactName); |
| 74 | + if (artifact) { |
| 75 | + core.setOutput("artifact_id", artifact.id); |
| 76 | + core.setOutput("run_id", run.id); |
| 77 | + found = true; |
| 78 | + break; |
| 79 | + } |
| 80 | + } |
| 81 | +
|
| 82 | + if (!found) { |
| 83 | + core.setFailed(`No artifact named '${expectedArtifactName}' found for commit ${commitSha}`); |
| 84 | + } |
| 85 | +
|
| 86 | + - name: Download artifact by ID |
| 87 | + uses: actions/download-artifact@v4 |
| 88 | + with: |
| 89 | + artifact-ids: ${{ steps.find-artifact.outputs.artifact_id }} |
| 90 | + run-id: ${{ steps.find-artifact.outputs.run_id }} |
| 91 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 92 | + path: ./phar-file-checksum-old.phar |
0 commit comments