Skip to content

PHAR prefix diff workflow #4

PHAR prefix diff workflow

PHAR prefix diff workflow #4

# https://help.github.com/en/categories/automating-your-workflow-with-github-actions
name: "PHAR Prefix Diff"
on:
pull_request:
paths:
- 'compiler/**'
- '.github/workflows/phar-prefix-diff.yml'
concurrency:
group: phar-prefix-diff-${{ github.head_ref || github.run_id }} # will be canceled on subsequent pushes in pull requests but not branches
cancel-in-progress: true
jobs:
phar-prefix-diff:
name: "PHAR Prefix Diff"
runs-on: "ubuntu-latest"
timeout-minutes: 60
steps:
- name: Get base commit SHA
id: base
run: echo "base_sha=${{ github.event.pull_request.base.sha }}" >> "$GITHUB_OUTPUT"
- name: Find phar-file-checksum from base commit
id: find-artifact
uses: actions/github-script@v7
with:
script: |
const commitSha = `${{ steps.base.outputs.base_sha }}`
const artifactName = "phar-file-checksum"
// Get all workflow runs for this commit
const runs = await github.rest.actions.listWorkflowRunsForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
per_page: 20,
event: "push",
head_sha: commitSha
});
if (runs.data.workflow_runs.length === 0) {
core.setFailed(`No workflow runs found for commit ${commitSha}`);
return;
}
const workflowRuns = runs.data.workflow_runs;
if (workflowRuns.length === 0) {
core.setFailed(`No workflow runs found for commit ${commitSha}`);
return;
}
let found = false;
for (const run of workflowRuns) {
if (run.status !== "completed" || run.conclusion !== "success") {
continue;
}
if (run.name !== "Compile PHAR" {
continue;
}
const artifactsResp = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: run.id,
});
const artifact = artifactsResp.data.artifacts.find(a => a.name === artifactName);
if (artifact) {
core.setOutput("artifact_id", artifact.id);
core.setOutput("run_id", run.id);
found = true;
break;
}
}
if (!found) {
core.setFailed(`No artifact named '${expectedArtifactName}' found for commit ${commitSha}`);
}
- name: Download artifact by ID
uses: actions/download-artifact@v4
with:
artifact-ids: ${{ steps.find-artifact.outputs.artifact_id }}
run-id: ${{ steps.find-artifact.outputs.run_id }}
github-token: ${{ secrets.GITHUB_TOKEN }}
path: ./phar-file-checksum-old.phar