Skip to content

Test Deploy

Test Deploy #4

Workflow file for this run

name: Test Deploy
on:
workflow_run:
workflows: ["Test Build"]
types: [completed]
concurrency:
group: test-deploy-${{ github.event.workflow_run.head_repository.id }}-${{ github.event.workflow_run.head_branch }}
cancel-in-progress: true
jobs:
deploy-preview:
if: >
github.event.workflow_run.conclusion == 'success' &&
github.event.workflow_run.head_repository.full_name != github.repository
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
pull-requests: write
steps:
- name: Get PR number
id: pr
uses: actions/github-script@v7
with:
result-encoding: string
script: |
const headRepo = context.payload.workflow_run.head_repository;
const headBranch = context.payload.workflow_run.head_branch;
const headSha = context.payload.workflow_run.head_sha;
console.log(`Looking up PR for ${headRepo.owner.login}:${headBranch} @ ${headSha}`);
const { data: prs } = await github.rest.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
head: `${headRepo.owner.login}:${headBranch}`,
});
console.log(`Found ${prs.length} PRs`);
prs.forEach(p => console.log(` PR #${p.number}: head.sha=${p.head.sha}`));
const pr = prs.find(p => p.head.sha === headSha);
if (!pr) {
core.setFailed(`No open PR found for ${headRepo.full_name}:${headBranch} @ ${headSha}`);
return;
}
console.log(`Matched PR #${pr.number}`);
return pr.number.toString();
- name: Download build artifact
uses: actions/download-artifact@v4
with:
name: pr-preview-build
path: build/
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: List build contents
run: |
echo "=== Build artifact contents ==="
find build/ -type f
echo "=== index.html ==="
cat build/index.html || echo "no index.html"
- name: Log what would be deployed
run: |
echo "Would deploy to branch: pr-${{ steps.pr.outputs.result }}"
echo "Commit hash: ${{ github.event.workflow_run.head_sha }}"
- name: Comment PR with test result
uses: actions/github-script@v7
env:
PR_NUMBER: ${{ steps.pr.outputs.result }}
with:
script: |
const prNumber = parseInt(process.env.PR_NUMBER, 10);
const commentBody = [
"### ✅ Test Deploy Workflow Ran Successfully!",
"",
`**PR:** #${prNumber}`,
`**Head SHA:** \`${context.payload.workflow_run.head_sha}\``,
`**Head Branch:** ${context.payload.workflow_run.head_branch}`,
`**Head Repo:** ${context.payload.workflow_run.head_repository.full_name}`,
"",
"All steps passed. Ready to replace with real Cloudflare deploy.",
].join("\n");
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body: commentBody
});