Skip to content

Instantly share code, notes, and snippets.

@onnenon
Last active March 24, 2025 15:17
Show Gist options
  • Save onnenon/1d54863c06471531dc09f62c3d8a8945 to your computer and use it in GitHub Desktop.
Save onnenon/1d54863c06471531dc09f62c3d8a8945 to your computer and use it in GitHub Desktop.
A GitHub Actions workflow that runs whenever a check run completes and creates a commit status with the target_url. This allows Cloudflare pages deploy previews to work with Decap CMS
name: Convert Cloudflare Check Run to Status
on:
check_run:
types: [completed]
jobs:
create_status_for_check:
name: Create Status for Check Run
runs-on: ubuntu-latest
permissions:
checks: read
statuses: write
steps:
- uses: actions/github-script@v7
with:
script: |
const getPreviewUrlForCheck = (check) => {
const regex = /<strong>Preview URL:<\/strong><\/td><td>\n<a href='(.*?)'>/s;
const match = check?.output?.summary?.match(regex);
return match?.[1];
};
const getCloudflareCheckForRef = async (owner, repo, ref) => {
const {
data: { check_runs: checks },
} = await github.rest.checks.listForRef({ owner, repo, ref });
return checks.find((check) => check.app.slug === "cloudflare-pages");
};
const createDeployStatus = async (owner, repo, sha, target_url) => {
await github.rest.repos.createCommitStatus({
owner,
repo,
sha,
target_url,
state: "success",
context: "cloudflare preview deploy",
description: "Cloudflare preview deploy successful",
});
};
const main = async () => {
const [owner, repo] = "${{ github.repository }}".split("/");
const ref = "${{ github.event.check_run.check_suite.head_sha }}";
const check = await getCloudflareCheckForRef(owner, repo, ref);
const previewUrl = getPreviewUrlForCheck(check);
if (!previewUrl) {
console.log("No preview URL found in check run output")
return;
}
await createDeployStatus(owner, repo, ref, previewUrl);
console.log("Created status for Cloudflare preview deploy");
};
await main();
@tenhobi
Copy link

tenhobi commented Mar 24, 2025

I had to change line 28 to also include cloudflare-workers-and-pages, like this:

return checks.find((check) => check.app.slug === "cloudflare-pages" || check.app.slug === "cloudflare-workers-and-pages");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment