Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/preview_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ jobs:
mkdir -p preview-site
wasm-bindgen --target web --out-dir preview-site --out-name wasm_3d_overlay examples/wasm-3d-overlay/target/wasm32-unknown-unknown/release/egui-bevy-wasm-3d-overlay.wasm
cp examples/wasm-3d-overlay/web/index.html preview-site/index.html
- name: Record source revision
- name: Record preview metadata
env:
PR_NUMBER: ${{ github.event.pull_request.number }}
PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }}
run: |
mkdir -p preview-meta
printf '%s\n' "$PR_NUMBER" > preview-meta/pr-number
printf '%s\n' "$PR_HEAD_SHA" > preview-meta/head-sha
- uses: actions/upload-artifact@v4
with:
Expand Down
69 changes: 42 additions & 27 deletions .github/workflows/preview_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,36 +20,58 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- name: Find the associated open pull request
- uses: actions/download-artifact@v4
with:
name: preview-meta
path: preview-meta
github-token: ${{ secrets.GITHUB_TOKEN }}
run-id: ${{ github.event.workflow_run.id }}
- name: Read and validate preview metadata
id: meta
run: |
PR_NUMBER=$(cat preview-meta/pr-number)
PR_HEAD_SHA=$(cat preview-meta/head-sha)
if [[ ! "$PR_NUMBER" =~ ^[0-9]+$ ]]; then
echo "Invalid PR number in preview metadata."
exit 1
fi
if [[ ! "$PR_HEAD_SHA" =~ ^[0-9a-fA-F]{40}$ ]]; then
echo "Invalid head SHA in preview metadata."
exit 1
fi
echo "number=$PR_NUMBER" >> "$GITHUB_OUTPUT"
- name: Verify the metadata pull request is open
id: pr
uses: actions/github-script@v7
env:
PR_NUMBER: ${{ steps.meta.outputs.number }}
with:
script: |
const run = context.payload.workflow_run;
let candidates = run.pull_requests || [];
if (candidates.length === 0) {
const response = await github.rest.repos.listPullRequestsAssociatedWithCommit({
owner: context.repo.owner,
repo: context.repo.repo,
commit_sha: run.head_sha,
});
candidates = response.data;
}
const candidate = candidates.find(pr =>
pr.head?.ref === run.head_branch &&
(!run.head_repository?.full_name || pr.head?.repo?.full_name === run.head_repository.full_name)
);
if (!candidate) {
core.notice('No matching pull request was found; skipping preview deployment.');
core.setOutput('number', '');
core.setOutput('head_sha', '');
const number = Number(process.env.PR_NUMBER);
if (!Number.isSafeInteger(number) || number < 1) {
core.setFailed('Invalid PR number in preview metadata.');
return;
}
const { data: pr } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: candidate.number,
pull_number: number,
});
const run = context.payload.workflow_run;
const linkedPullRequests = run.pull_requests || [];
if (linkedPullRequests.length > 0 && !linkedPullRequests.some(linked => linked.number === pr.number)) {
core.setFailed('Preview metadata PR number does not match the build run.');
return;
}
if (pr.head.ref !== run.head_branch) {
core.setFailed('Preview metadata PR branch does not match the build run.');
return;
}
const runHeadRepository = run.head_repository?.full_name;
if (runHeadRepository && pr.head.repo?.full_name !== runHeadRepository) {
core.setFailed('Preview metadata PR repository does not match the build run.');
return;
}
if (pr.state !== 'open') {
core.notice('Pull request is no longer open; skipping preview deployment.');
core.setOutput('number', '');
Expand All @@ -65,13 +87,6 @@ jobs:
path: preview-site
github-token: ${{ secrets.GITHUB_TOKEN }}
run-id: ${{ github.event.workflow_run.id }}
- uses: actions/download-artifact@v4
if: steps.pr.outputs.number != ''
with:
name: preview-meta
path: preview-meta
github-token: ${{ secrets.GITHUB_TOKEN }}
run-id: ${{ github.event.workflow_run.id }}
- name: Verify the artifact matches the current PR revision
id: verify
if: steps.pr.outputs.number != ''
Expand Down
Binary file removed egui-bevy-v012.png
Binary file not shown.
Loading