mirror of
https://github.com/cloudflare/pages-action
synced 2024-11-23 19:36:42 +00:00
chore: use tabs (#46)
This commit is contained in:
parent
c2ad89679f
commit
1aff065c9e
10
.editorconfig
Normal file
10
.editorconfig
Normal file
|
@ -0,0 +1,10 @@
|
|||
# https://editorconfig.org
|
||||
root = true
|
||||
|
||||
[*]
|
||||
end_of_line = lf
|
||||
indent_style = tab
|
||||
tab_width = 2
|
||||
|
||||
[*.yml]
|
||||
indent_style = space
|
2
.github/workflows/publish.yml
vendored
2
.github/workflows/publish.yml
vendored
|
@ -8,4 +8,4 @@ jobs:
|
|||
tag-release:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: Actions-R-Us/actions-tagger@latest
|
||||
- uses: Actions-R-Us/actions-tagger@latest
|
||||
|
|
6
.prettierrc
Normal file
6
.prettierrc
Normal file
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"printWidth": 120,
|
||||
"singleQuote": false,
|
||||
"semi": true,
|
||||
"useTabs": true
|
||||
}
|
|
@ -38,12 +38,15 @@ GitHub Action for creating Cloudflare Pages deployments, using the new [Direct U
|
|||
1. Replace `YOUR_ACCOUNT_ID`, `YOUR_PROJECT_NAME` and `YOUR_ASSET_DIRECTORY` with the appropriate values to your Pages project.
|
||||
|
||||
### Get account ID
|
||||
To find your account ID, log in to the Cloudflare dashboard > select your zone in Account Home > find your account ID in Overview under **API** on the right-side menu. If you have not added a zone, add one by selecting **Add site** . You can purchase a domain from [Cloudflare’s registrar](https://developers.cloudflare.com/registrar/).
|
||||
|
||||
To find your account ID, log in to the Cloudflare dashboard > select your zone in Account Home > find your account ID in Overview under **API** on the right-side menu. If you have not added a zone, add one by selecting **Add site** . You can purchase a domain from [Cloudflare’s registrar](https://developers.cloudflare.com/registrar/).
|
||||
|
||||
If you do not have a zone registered to your account, you can also get your account ID from the `pages.dev` URL. E.g: `https://dash.cloudflare.com/<ACCOUNT_ID>/pages`
|
||||
|
||||
### Generate an API Token
|
||||
|
||||
To generate an API token:
|
||||
|
||||
1. Log in to the Cloudflare dashboard.
|
||||
2. Select My Profile from the dropdown menu of your user icon on the top right of your dashboard.
|
||||
3. Select API Tokens > Create Token.
|
||||
|
@ -55,6 +58,7 @@ To generate an API token:
|
|||
More information can be found on [our guide for making Direct Upload deployments with continous integration](https://developers.cloudflare.com/pages/how-to/use-direct-upload-with-continuous-integration/#use-github-actions).
|
||||
|
||||
### Specifying a branch
|
||||
|
||||
The branch name is used by Cloudflare Pages to determine if the deployment is production or preview. Read more about
|
||||
[git branch build controls](https://developers.cloudflare.com/pages/platform/branch-build-controls/#branch-build-controls).
|
||||
|
||||
|
@ -62,6 +66,7 @@ If you are in a Git workspace, Wrangler will automatically pull the branch infor
|
|||
manually by adding the argument `branch: YOUR_BRANCH_NAME`.
|
||||
|
||||
## Outputs
|
||||
|
||||
| Name | Description |
|
||||
| ------------- | --------------------------------------------------- |
|
||||
| `id` | The ID of the pages deployment |
|
||||
|
|
|
@ -1,50 +1,38 @@
|
|||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Direct Upload Demo | Cloudflare Pages</title>
|
||||
<link href="style.css" rel="stylesheet" />
|
||||
</head>
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Direct Upload Demo | Cloudflare Pages</title>
|
||||
<link href="style.css" rel="stylesheet" />
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="header">
|
||||
<h3>Example project</h3>
|
||||
<h1>Welcome to Cloudflare Pages</h1>
|
||||
<p>
|
||||
Upload your prebuilt assets directly to Pages and deploy <br />
|
||||
your project to the Cloudflare edge within seconds.
|
||||
</p>
|
||||
<p>Create new deployments using:</p>
|
||||
<section class="options">
|
||||
<img src="assets/terminal.svg" />
|
||||
<a
|
||||
href="https://dash.cloudflare.com/?to=/:account/pages/new/wrangler-guide"
|
||||
target="_blank"
|
||||
> Wrangler CLI</a
|
||||
>
|
||||
<img src="assets/cloud-upload.svg" />
|
||||
<a
|
||||
href="https://dash.cloudflare.com/?to=/:account/pages/new/upload"
|
||||
target="_blank"
|
||||
> Dashboard</a
|
||||
>
|
||||
</section>
|
||||
</div>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="header">
|
||||
<h3>Example project</h3>
|
||||
<h1>Welcome to Cloudflare Pages</h1>
|
||||
<p>
|
||||
Upload your prebuilt assets directly to Pages and deploy <br />
|
||||
your project to the Cloudflare edge within seconds.
|
||||
</p>
|
||||
<p>Create new deployments using:</p>
|
||||
<section class="options">
|
||||
<img src="assets/terminal.svg" />
|
||||
<a href="https://dash.cloudflare.com/?to=/:account/pages/new/wrangler-guide" target="_blank"> Wrangler CLI</a>
|
||||
<img src="assets/cloud-upload.svg" />
|
||||
<a href="https://dash.cloudflare.com/?to=/:account/pages/new/upload" target="_blank"> Dashboard</a>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<section class="learn-more">
|
||||
<a
|
||||
href="https://developers.cloudflare.com/pages/platform/direct-uploads"
|
||||
>
|
||||
<button>Learn more</button>
|
||||
</a>
|
||||
</section>
|
||||
<div class="logo">
|
||||
<a href="https://pages.cloudflare.com/" target="_blank">
|
||||
<img src="assets/cloudflare-pages.svg"
|
||||
/></a>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
<section class="learn-more">
|
||||
<a href="https://developers.cloudflare.com/pages/platform/direct-uploads">
|
||||
<button>Learn more</button>
|
||||
</a>
|
||||
</section>
|
||||
<div class="logo">
|
||||
<a href="https://pages.cloudflare.com/" target="_blank"> <img src="assets/cloudflare-pages.svg" /></a>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -1,159 +1,159 @@
|
|||
* {
|
||||
box-sizing: border-box;
|
||||
font-family: -apple-system, system-ui, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, "Helvetica Neue", Arial, sans-serif;
|
||||
margin: auto;
|
||||
box-sizing: border-box;
|
||||
font-family: -apple-system, system-ui, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, "Helvetica Neue", Arial,
|
||||
sans-serif;
|
||||
margin: auto;
|
||||
}
|
||||
|
||||
.bg-image {
|
||||
position: absolute;
|
||||
bottom: -88%;
|
||||
position: absolute;
|
||||
bottom: -88%;
|
||||
}
|
||||
|
||||
.container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 165px 0 124px;
|
||||
width: 100%;
|
||||
margin: auto;
|
||||
border: #fbab40;
|
||||
height: 100vh;
|
||||
background-color: #242628;
|
||||
background-image: url(./assets/world.svg);
|
||||
background-repeat: no-repeat;
|
||||
background-position-x: center;
|
||||
background-position-y: 70px;
|
||||
background-origin: padding-box;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 165px 0 124px;
|
||||
width: 100%;
|
||||
margin: auto;
|
||||
border: #fbab40;
|
||||
height: 100vh;
|
||||
background-color: #242628;
|
||||
background-image: url(./assets/world.svg);
|
||||
background-repeat: no-repeat;
|
||||
background-position-x: center;
|
||||
background-position-y: 70px;
|
||||
background-origin: padding-box;
|
||||
}
|
||||
|
||||
.header h3 {
|
||||
text-align: center;
|
||||
color: #ff9e40;
|
||||
font-size: 24px;
|
||||
font-style: normal;
|
||||
font-weight: 600;
|
||||
margin: 0;
|
||||
line-height: 36px;
|
||||
text-align: center;
|
||||
color: #ff9e40;
|
||||
font-size: 24px;
|
||||
font-style: normal;
|
||||
font-weight: 600;
|
||||
margin: 0;
|
||||
line-height: 36px;
|
||||
}
|
||||
|
||||
.header {
|
||||
display: flex;
|
||||
position: relative;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
padding: 0px;
|
||||
font-style: normal;
|
||||
display: flex;
|
||||
position: relative;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
padding: 0px;
|
||||
font-style: normal;
|
||||
}
|
||||
|
||||
.header > h1 {
|
||||
font-style: normal;
|
||||
font-weight: 600;
|
||||
font-size: 48px;
|
||||
line-height: 150%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
text-align: center;
|
||||
color: #ffffff;
|
||||
font-style: normal;
|
||||
font-weight: 600;
|
||||
font-size: 48px;
|
||||
line-height: 150%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
text-align: center;
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
.header > p {
|
||||
font-style: normal;
|
||||
font-weight: 400;
|
||||
font-size: 24px;
|
||||
line-height: 150%;
|
||||
text-align: center;
|
||||
color: #ffffff;
|
||||
flex-grow: 0;
|
||||
margin: 16px 0px;
|
||||
font-style: normal;
|
||||
font-weight: 400;
|
||||
font-size: 24px;
|
||||
line-height: 150%;
|
||||
text-align: center;
|
||||
color: #ffffff;
|
||||
flex-grow: 0;
|
||||
margin: 16px 0px;
|
||||
}
|
||||
|
||||
.options {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
}
|
||||
|
||||
.options > a {
|
||||
color: #ffffff;
|
||||
text-decoration: underline;
|
||||
margin: 0px 8px;
|
||||
font-weight: 400;
|
||||
font-size: 24px;
|
||||
line-height: 150%;
|
||||
color: #ffffff;
|
||||
text-decoration: underline;
|
||||
margin: 0px 8px;
|
||||
font-weight: 400;
|
||||
font-size: 24px;
|
||||
line-height: 150%;
|
||||
}
|
||||
|
||||
.options > a:first-of-type {
|
||||
margin-right: 30px;
|
||||
margin-right: 30px;
|
||||
}
|
||||
|
||||
.logo {
|
||||
margin-top: 75px;
|
||||
margin-top: 75px;
|
||||
}
|
||||
|
||||
.logo > img {
|
||||
width: 160px;
|
||||
height: 64px;
|
||||
width: 160px;
|
||||
height: 64px;
|
||||
}
|
||||
|
||||
.learn-more > a > button {
|
||||
background: #f6821f;
|
||||
border-radius: 4px;
|
||||
border: none;
|
||||
width: 180px;
|
||||
margin-top: 78px;
|
||||
height: 55px;
|
||||
color: #ffffff;
|
||||
text-align: center;
|
||||
font-weight: 600;
|
||||
font-size: 16px;
|
||||
line-height: 19px;
|
||||
background: rgba(246, 130, 31, 1);
|
||||
box-shadow: 0px 0px 0px 0px rgba(0, 0, 0, 0.25);
|
||||
cursor: pointer;
|
||||
background: #f6821f;
|
||||
border-radius: 4px;
|
||||
border: none;
|
||||
width: 180px;
|
||||
margin-top: 78px;
|
||||
height: 55px;
|
||||
color: #ffffff;
|
||||
text-align: center;
|
||||
font-weight: 600;
|
||||
font-size: 16px;
|
||||
line-height: 19px;
|
||||
background: rgba(246, 130, 31, 1);
|
||||
box-shadow: 0px 0px 0px 0px rgba(0, 0, 0, 0.25);
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
@media screen and (max-width: 1024px) {
|
||||
.container {
|
||||
background-size: contain;
|
||||
background-position-y: center;
|
||||
}
|
||||
.container {
|
||||
background-size: contain;
|
||||
background-position-y: center;
|
||||
}
|
||||
}
|
||||
|
||||
@media screen and (max-width: 600px) {
|
||||
.container {
|
||||
background-size: contain;
|
||||
background-position-y: center;
|
||||
}
|
||||
pre {
|
||||
font-size: 0.8rem;
|
||||
padding: 8px 12px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.container{
|
||||
background-size: contain;
|
||||
background-position-y: center;
|
||||
}
|
||||
pre {
|
||||
font-size: 0.8rem;
|
||||
padding: 8px 12px;
|
||||
width: 100%;
|
||||
}
|
||||
body {
|
||||
width: 100vw;
|
||||
}
|
||||
|
||||
body {
|
||||
width: 100vw;
|
||||
}
|
||||
.header img {
|
||||
margin-left: 0;
|
||||
}
|
||||
|
||||
.header img {
|
||||
margin-left: 0;
|
||||
}
|
||||
.installation-steps {
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.installation-steps {
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
h1 {
|
||||
font-size: 1.6rem;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 1.6rem;
|
||||
}
|
||||
ol {
|
||||
padding-left: 20px;
|
||||
}
|
||||
|
||||
ol {
|
||||
padding-left: 20px;
|
||||
}
|
||||
|
||||
li {
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
li {
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
}
|
||||
|
|
11
index.js
11
index.js
|
@ -22128,10 +22128,7 @@ try {
|
|||
state: "success"
|
||||
});
|
||||
};
|
||||
const createJobSummary = async ({
|
||||
deployment,
|
||||
aliasUrl
|
||||
}) => {
|
||||
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") {
|
||||
|
@ -22139,7 +22136,8 @@ try {
|
|||
} else if (deployStage?.status === "failure") {
|
||||
status = "\u{1F6AB} Deployment failed";
|
||||
}
|
||||
await import_core.summary.addRaw(`
|
||||
await import_core.summary.addRaw(
|
||||
`
|
||||
# Deploying with Cloudflare Pages
|
||||
|
||||
| Name | Result |
|
||||
|
@ -22148,7 +22146,8 @@ try {
|
|||
| **Status**: | ${status} |
|
||||
| **Preview URL**: | ${deployment.url} |
|
||||
| **Branch Preview URL**: | ${aliasUrl} |
|
||||
`).write();
|
||||
`
|
||||
).write();
|
||||
};
|
||||
(async () => {
|
||||
const project = await getProject();
|
||||
|
|
2620
package-lock.json
generated
2620
package-lock.json
generated
File diff suppressed because it is too large
Load diff
71
package.json
71
package.json
|
@ -1,37 +1,38 @@
|
|||
{
|
||||
"name": "pages-action",
|
||||
"version": "1.3.0",
|
||||
"description": "Publish to Cloudflare Pages",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"build": "npx esbuild src/index.ts --bundle --platform=node --target=es2021 --outfile=index.js",
|
||||
"prepare": "husky install"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/cloudflare/pages-action.git"
|
||||
},
|
||||
"keywords": [
|
||||
"Cloudflare Pages",
|
||||
"GitHub Actions"
|
||||
],
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/cloudflare/pages-action/issues"
|
||||
},
|
||||
"homepage": "https://github.com/cloudflare/pages-action#readme",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.10.0",
|
||||
"@actions/github": "^5.1.1",
|
||||
"@cloudflare/types": "^6.18.16",
|
||||
"shellac": "^0.7.2",
|
||||
"undici": "^5.11.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^18.11.3",
|
||||
"esbuild": "^0.15.12",
|
||||
"husky": "^8.0.1",
|
||||
"prettier": "^2.6.2",
|
||||
"typescript": "^4.6.4"
|
||||
}
|
||||
"name": "pages-action",
|
||||
"version": "1.3.0",
|
||||
"description": "Publish to Cloudflare Pages",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"build": "npx esbuild src/index.ts --bundle --platform=node --target=es2021 --outfile=index.js",
|
||||
"prepare": "husky install",
|
||||
"prettify": "prettier . --write --ignore-unknown"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/cloudflare/pages-action.git"
|
||||
},
|
||||
"keywords": [
|
||||
"Cloudflare Pages",
|
||||
"GitHub Actions"
|
||||
],
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/cloudflare/pages-action/issues"
|
||||
},
|
||||
"homepage": "https://github.com/cloudflare/pages-action#readme",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.10.0",
|
||||
"@actions/github": "^5.1.1",
|
||||
"@cloudflare/types": "^6.18.16",
|
||||
"shellac": "^0.7.2",
|
||||
"undici": "^5.11.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^18.11.3",
|
||||
"esbuild": "^0.15.12",
|
||||
"husky": "^8.0.1",
|
||||
"prettier": "^2.8.1",
|
||||
"typescript": "^4.6.4"
|
||||
}
|
||||
}
|
||||
|
|
247
src/index.ts
247
src/index.ts
|
@ -1,5 +1,5 @@
|
|||
import { getInput, setOutput, setFailed, summary } from "@actions/core";
|
||||
import type { Project, Deployment } from '@cloudflare/types';
|
||||
import type { Project, Deployment } from "@cloudflare/types";
|
||||
import { context, getOctokit } from "@actions/github";
|
||||
import shellac from "shellac";
|
||||
import { fetch } from "undici";
|
||||
|
@ -8,25 +8,25 @@ import { env } from "process";
|
|||
type Octokit = ReturnType<typeof getOctokit>;
|
||||
|
||||
try {
|
||||
const apiToken = getInput("apiToken", { required: true });
|
||||
const accountId = getInput("accountId", { required: true });
|
||||
const projectName = getInput("projectName", { required: true });
|
||||
const directory = getInput("directory", { required: true });
|
||||
const gitHubToken = getInput("gitHubToken", { required: false });
|
||||
const branch = getInput("branch", { required: false });
|
||||
const apiToken = getInput("apiToken", { required: true });
|
||||
const accountId = getInput("accountId", { required: true });
|
||||
const projectName = getInput("projectName", { required: true });
|
||||
const directory = getInput("directory", { required: true });
|
||||
const gitHubToken = getInput("gitHubToken", { required: false });
|
||||
const branch = getInput("branch", { required: false });
|
||||
|
||||
const getProject = async () => {
|
||||
const response = await fetch(
|
||||
`https://api.cloudflare.com/client/v4/accounts/${accountId}/pages/projects/${projectName}`,
|
||||
{ headers: { Authorization: `Bearer ${apiToken}` } }
|
||||
);
|
||||
const { result } = await response.json() as { result: Project | null };
|
||||
return result;
|
||||
}
|
||||
|
||||
const createPagesDeployment = async () => {
|
||||
// TODO: Replace this with an API call to wrangler so we can get back a full deployment response object
|
||||
await shellac`
|
||||
const getProject = async () => {
|
||||
const response = await fetch(
|
||||
`https://api.cloudflare.com/client/v4/accounts/${accountId}/pages/projects/${projectName}`,
|
||||
{ headers: { Authorization: `Bearer ${apiToken}` } }
|
||||
);
|
||||
const { result } = (await response.json()) as { result: Project | null };
|
||||
return result;
|
||||
};
|
||||
|
||||
const createPagesDeployment = async () => {
|
||||
// TODO: Replace this with an API call to wrangler so we can get back a full deployment response object
|
||||
await shellac`
|
||||
$ export CLOUDFLARE_API_TOKEN="${apiToken}"
|
||||
if ${accountId} {
|
||||
$ export CLOUDFLARE_ACCOUNT_ID="${accountId}"
|
||||
|
@ -35,84 +35,76 @@ try {
|
|||
$$ npx wrangler@2 pages publish "${directory}" --project-name="${projectName}" --branch="${branch}"
|
||||
`;
|
||||
|
||||
const response = await fetch(
|
||||
`https://api.cloudflare.com/client/v4/accounts/${accountId}/pages/projects/${projectName}/deployments`,
|
||||
{ headers: { Authorization: `Bearer ${apiToken}` } }
|
||||
);
|
||||
const {
|
||||
result: [deployment],
|
||||
} = (await response.json()) as { result: Deployment[] };
|
||||
const response = await fetch(
|
||||
`https://api.cloudflare.com/client/v4/accounts/${accountId}/pages/projects/${projectName}/deployments`,
|
||||
{ headers: { Authorization: `Bearer ${apiToken}` } }
|
||||
);
|
||||
const {
|
||||
result: [deployment],
|
||||
} = (await response.json()) as { result: Deployment[] };
|
||||
|
||||
return deployment;
|
||||
};
|
||||
return deployment;
|
||||
};
|
||||
|
||||
const createGitHubDeployment = async (octokit: Octokit, productionEnvironment: boolean, environment: string) => {
|
||||
const deployment = await octokit.rest.repos.createDeployment({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
ref: context.ref,
|
||||
auto_merge: false,
|
||||
description: "Cloudflare Pages",
|
||||
required_contexts: [],
|
||||
environment,
|
||||
production_environment: productionEnvironment,
|
||||
});
|
||||
const createGitHubDeployment = async (octokit: Octokit, productionEnvironment: boolean, environment: string) => {
|
||||
const deployment = await octokit.rest.repos.createDeployment({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
ref: context.ref,
|
||||
auto_merge: false,
|
||||
description: "Cloudflare Pages",
|
||||
required_contexts: [],
|
||||
environment,
|
||||
production_environment: productionEnvironment,
|
||||
});
|
||||
|
||||
if (deployment.status === 201) {
|
||||
return deployment.data;
|
||||
}
|
||||
};
|
||||
if (deployment.status === 201) {
|
||||
return deployment.data;
|
||||
}
|
||||
};
|
||||
|
||||
const createGitHubDeploymentStatus = async ({
|
||||
id,
|
||||
url,
|
||||
deploymentId,
|
||||
environmentName,
|
||||
productionEnvironment,
|
||||
octokit,
|
||||
}: {
|
||||
octokit: Octokit,
|
||||
id: number;
|
||||
url: string;
|
||||
deploymentId: string;
|
||||
environmentName: string;
|
||||
productionEnvironment: boolean;
|
||||
}) => {
|
||||
await octokit.rest.repos.createDeploymentStatus({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
deployment_id: id,
|
||||
// @ts-ignore
|
||||
environment: environmentName,
|
||||
environment_url: url,
|
||||
production_environment: productionEnvironment,
|
||||
log_url: `https://dash.cloudflare.com/${accountId}/pages/view/${projectName}/${deploymentId}`,
|
||||
description: "Cloudflare Pages",
|
||||
state: "success",
|
||||
});
|
||||
};
|
||||
const createGitHubDeploymentStatus = async ({
|
||||
id,
|
||||
url,
|
||||
deploymentId,
|
||||
environmentName,
|
||||
productionEnvironment,
|
||||
octokit,
|
||||
}: {
|
||||
octokit: Octokit;
|
||||
id: number;
|
||||
url: string;
|
||||
deploymentId: string;
|
||||
environmentName: string;
|
||||
productionEnvironment: boolean;
|
||||
}) => {
|
||||
await octokit.rest.repos.createDeploymentStatus({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
deployment_id: id,
|
||||
// @ts-ignore
|
||||
environment: environmentName,
|
||||
environment_url: url,
|
||||
production_environment: productionEnvironment,
|
||||
log_url: `https://dash.cloudflare.com/${accountId}/pages/view/${projectName}/${deploymentId}`,
|
||||
description: "Cloudflare Pages",
|
||||
state: "success",
|
||||
});
|
||||
};
|
||||
|
||||
const createJobSummary = async (
|
||||
{
|
||||
deployment,
|
||||
aliasUrl,
|
||||
}:
|
||||
{
|
||||
deployment: Deployment;
|
||||
aliasUrl: string;
|
||||
}
|
||||
) => {
|
||||
const deployStage = deployment.stages.find((stage) => stage.name === 'deploy');
|
||||
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';
|
||||
}
|
||||
let status = "⚡️ Deployment in progress...";
|
||||
if (deployStage?.status === "success") {
|
||||
status = "✅ Deploy successful!";
|
||||
} else if (deployStage?.status === "failure") {
|
||||
status = "🚫 Deployment failed";
|
||||
}
|
||||
|
||||
await summary
|
||||
.addRaw(`
|
||||
await summary
|
||||
.addRaw(
|
||||
`
|
||||
# Deploying with Cloudflare Pages
|
||||
|
||||
| Name | Result |
|
||||
|
@ -121,51 +113,52 @@ try {
|
|||
| **Status**: | ${status} |
|
||||
| **Preview URL**: | ${deployment.url} |
|
||||
| **Branch Preview URL**: | ${aliasUrl} |
|
||||
`)
|
||||
.write();
|
||||
}
|
||||
`
|
||||
)
|
||||
.write();
|
||||
};
|
||||
|
||||
(async () => {
|
||||
const project = await getProject();
|
||||
if (!project) throw new Error('Unable to find pages project')
|
||||
(async () => {
|
||||
const project = await getProject();
|
||||
if (!project) throw new Error("Unable to find pages project");
|
||||
|
||||
const githubBranch = env.GITHUB_REF_NAME;
|
||||
const productionEnvironment = githubBranch === project.production_branch;
|
||||
const environmentName = productionEnvironment ? "Production" : `Preview: (${githubBranch})`;
|
||||
const githubBranch = env.GITHUB_REF_NAME;
|
||||
const productionEnvironment = githubBranch === project.production_branch;
|
||||
const environmentName = productionEnvironment ? "Production" : `Preview: (${githubBranch})`;
|
||||
|
||||
let gitHubDeployment: Awaited<ReturnType<typeof createGitHubDeployment>>;
|
||||
let gitHubDeployment: Awaited<ReturnType<typeof createGitHubDeployment>>;
|
||||
|
||||
if (gitHubToken && gitHubToken.length) {
|
||||
const octokit = getOctokit(gitHubToken);
|
||||
gitHubDeployment = await createGitHubDeployment(octokit, productionEnvironment, environmentName);
|
||||
}
|
||||
if (gitHubToken && gitHubToken.length) {
|
||||
const octokit = getOctokit(gitHubToken);
|
||||
gitHubDeployment = await createGitHubDeployment(octokit, productionEnvironment, environmentName);
|
||||
}
|
||||
|
||||
const pagesDeployment = await createPagesDeployment();
|
||||
setOutput("id", pagesDeployment.id);
|
||||
setOutput("url", pagesDeployment.url);
|
||||
setOutput("environment", pagesDeployment.environment);
|
||||
const pagesDeployment = await createPagesDeployment();
|
||||
setOutput("id", pagesDeployment.id);
|
||||
setOutput("url", pagesDeployment.url);
|
||||
setOutput("environment", pagesDeployment.environment);
|
||||
|
||||
let alias = pagesDeployment.url;
|
||||
if (!productionEnvironment && pagesDeployment.aliases && pagesDeployment.aliases.length > 0) {
|
||||
alias = pagesDeployment.aliases[0];
|
||||
}
|
||||
setOutput("alias", alias);
|
||||
let alias = pagesDeployment.url;
|
||||
if (!productionEnvironment && pagesDeployment.aliases && pagesDeployment.aliases.length > 0) {
|
||||
alias = pagesDeployment.aliases[0];
|
||||
}
|
||||
setOutput("alias", alias);
|
||||
|
||||
await createJobSummary({ deployment: pagesDeployment, aliasUrl: alias });
|
||||
await createJobSummary({ deployment: pagesDeployment, aliasUrl: alias });
|
||||
|
||||
if (gitHubDeployment) {
|
||||
const octokit = getOctokit(gitHubToken);
|
||||
if (gitHubDeployment) {
|
||||
const octokit = getOctokit(gitHubToken);
|
||||
|
||||
await createGitHubDeploymentStatus({
|
||||
id: gitHubDeployment.id,
|
||||
url: pagesDeployment.url,
|
||||
deploymentId: pagesDeployment.id,
|
||||
environmentName,
|
||||
productionEnvironment,
|
||||
octokit
|
||||
});
|
||||
}
|
||||
})();
|
||||
await createGitHubDeploymentStatus({
|
||||
id: gitHubDeployment.id,
|
||||
url: pagesDeployment.url,
|
||||
deploymentId: pagesDeployment.id,
|
||||
environmentName,
|
||||
productionEnvironment,
|
||||
octokit,
|
||||
});
|
||||
}
|
||||
})();
|
||||
} catch (thrown) {
|
||||
setFailed(thrown.message);
|
||||
setFailed(thrown.message);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue