diff --git a/README.md b/README.md index ab12737..8796a0d 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ GitHub Action for creating Cloudflare Pages deployments, using the new [Direct U # Run a build step here if your project requires - name: Publish to Cloudflare Pages - uses: cloudflare/pages-action@1 + uses: cloudflare/pages-action@v1 with: apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} accountId: YOUR_ACCOUNT_ID diff --git a/index.js b/index.js index 24a2664..4932d2d 100644 --- a/index.js +++ b/index.js @@ -22128,6 +22128,28 @@ try { state: "success" }); }; + const createJobSummary = async ({ + deployment, + aliasUrl + }) => { + const deployStage = deployment.stages.find((stage) => stage.name === "deploy"); + let status = "\u26A1\uFE0F Deployment in progress..."; + if (deployStage?.status === "success") { + status = "\u2705 Deploy successful!"; + } else if (deployStage?.status === "failure") { + status = "\u{1F6AB} Deployment failed"; + } + await import_core.summary.addRaw(` +# Deploying with Cloudflare Pages + +| Name | Result | +| ----------------------- | - | +| **Last commit:** | \`${deployment.deployment_trigger.metadata.commit_hash.substring(0, 8)}\` | +| **Status**: | ${status} | +| **Preview URL**: | ${deployment.url} | +| **Branch Preview URL**: | ${aliasUrl} | + `).write(); + }; (async () => { const project = await getProject(); if (!project) @@ -22149,6 +22171,7 @@ try { alias = pagesDeployment.aliases[0]; } (0, import_core.setOutput)("alias", alias); + await createJobSummary({ deployment: pagesDeployment, aliasUrl: alias }); if (gitHubDeployment) { const octokit = (0, import_github.getOctokit)(gitHubToken); await createGitHubDeploymentStatus({ diff --git a/src/index.ts b/src/index.ts index 0fd82e4..997dfe1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,4 @@ -import { getInput, setOutput, setFailed } from "@actions/core"; +import { getInput, setOutput, setFailed, summary } from "@actions/core"; import type { Project, Deployment } from '@cloudflare/types'; import { context, getOctokit } from "@actions/github"; import shellac from "shellac"; @@ -92,6 +92,39 @@ try { }); }; + const createJobSummary = async ( + { + deployment, + aliasUrl, + }: + { + deployment: Deployment; + aliasUrl: string; + } + ) => { + const deployStage = deployment.stages.find((stage) => stage.name === 'deploy'); + + let status = '⚡️ Deployment in progress...'; + if (deployStage?.status === 'success') { + status = '✅ Deploy successful!'; + } else if (deployStage?.status === 'failure') { + status = '🚫 Deployment failed'; + } + + await summary + .addRaw(` +# Deploying with Cloudflare Pages + +| Name | Result | +| ----------------------- | - | +| **Last commit:** | \`${deployment.deployment_trigger.metadata.commit_hash.substring(0, 8)}\` | +| **Status**: | ${status} | +| **Preview URL**: | ${deployment.url} | +| **Branch Preview URL**: | ${aliasUrl} | + `) + .write(); + } + (async () => { const project = await getProject(); if (!project) throw new Error('Unable to find pages project') @@ -106,7 +139,7 @@ try { const octokit = getOctokit(gitHubToken); gitHubDeployment = await createGitHubDeployment(octokit, productionEnvironment, environmentName); } - + const pagesDeployment = await createPagesDeployment(); setOutput("id", pagesDeployment.id); setOutput("url", pagesDeployment.url); @@ -118,6 +151,8 @@ try { } setOutput("alias", alias); + await createJobSummary({ deployment: pagesDeployment, aliasUrl: alias }); + if (gitHubDeployment) { const octokit = getOctokit(gitHubToken);