chore: use tabs (#46)

This commit is contained in:
James Ross 2022-12-20 23:03:33 +00:00 committed by GitHub
parent c2ad89679f
commit 1aff065c9e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 1637 additions and 1635 deletions

10
.editorconfig Normal file
View file

@ -0,0 +1,10 @@
# https://editorconfig.org
root = true
[*]
end_of_line = lf
indent_style = tab
tab_width = 2
[*.yml]
indent_style = space

6
.prettierrc Normal file
View file

@ -0,0 +1,6 @@
{
"printWidth": 120,
"singleQuote": false,
"semi": true,
"useTabs": true
}

View file

@ -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. 1. Replace `YOUR_ACCOUNT_ID`, `YOUR_PROJECT_NAME` and `YOUR_ASSET_DIRECTORY` with the appropriate values to your Pages project.
### Get account ID ### 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 [Cloudflares 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 [Cloudflares 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` 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 ### Generate an API Token
To generate an API token: To generate an API token:
1. Log in to the Cloudflare dashboard. 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. 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. 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). 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 ### Specifying a branch
The branch name is used by Cloudflare Pages to determine if the deployment is production or preview. Read more about 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). [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`. manually by adding the argument `branch: YOUR_BRANCH_NAME`.
## Outputs ## Outputs
| Name | Description | | Name | Description |
| ------------- | --------------------------------------------------- | | ------------- | --------------------------------------------------- |
| `id` | The ID of the pages deployment | | `id` | The ID of the pages deployment |

View file

@ -19,31 +19,19 @@
<p>Create new deployments using:</p> <p>Create new deployments using:</p>
<section class="options"> <section class="options">
<img src="assets/terminal.svg" /> <img src="assets/terminal.svg" />
<a <a href="https://dash.cloudflare.com/?to=/:account/pages/new/wrangler-guide" target="_blank"> Wrangler CLI</a>
href="https://dash.cloudflare.com/?to=/:account/pages/new/wrangler-guide"
target="_blank"
> Wrangler CLI</a
>
<img src="assets/cloud-upload.svg" /> <img src="assets/cloud-upload.svg" />
<a <a href="https://dash.cloudflare.com/?to=/:account/pages/new/upload" target="_blank"> Dashboard</a>
href="https://dash.cloudflare.com/?to=/:account/pages/new/upload"
target="_blank"
> Dashboard</a
>
</section> </section>
</div> </div>
<section class="learn-more"> <section class="learn-more">
<a <a href="https://developers.cloudflare.com/pages/platform/direct-uploads">
href="https://developers.cloudflare.com/pages/platform/direct-uploads"
>
<button>Learn more</button> <button>Learn more</button>
</a> </a>
</section> </section>
<div class="logo"> <div class="logo">
<a href="https://pages.cloudflare.com/" target="_blank"> <a href="https://pages.cloudflare.com/" target="_blank"> <img src="assets/cloudflare-pages.svg" /></a>
<img src="assets/cloudflare-pages.svg"
/></a>
</div> </div>
</div> </div>
</body> </body>

View file

@ -1,6 +1,7 @@
* { * {
box-sizing: border-box; box-sizing: border-box;
font-family: -apple-system, system-ui, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, "Helvetica Neue", Arial, sans-serif; font-family: -apple-system, system-ui, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, "Helvetica Neue", Arial,
sans-serif;
margin: auto; margin: auto;
} }
@ -121,8 +122,7 @@
} }
@media screen and (max-width: 600px) { @media screen and (max-width: 600px) {
.container {
.container{
background-size: contain; background-size: contain;
background-position-y: center; background-position-y: center;
} }

View file

@ -22128,10 +22128,7 @@ try {
state: "success" state: "success"
}); });
}; };
const createJobSummary = async ({ const createJobSummary = async ({ deployment, aliasUrl }) => {
deployment,
aliasUrl
}) => {
const deployStage = deployment.stages.find((stage) => stage.name === "deploy"); const deployStage = deployment.stages.find((stage) => stage.name === "deploy");
let status = "\u26A1\uFE0F Deployment in progress..."; let status = "\u26A1\uFE0F Deployment in progress...";
if (deployStage?.status === "success") { if (deployStage?.status === "success") {
@ -22139,7 +22136,8 @@ try {
} else if (deployStage?.status === "failure") { } else if (deployStage?.status === "failure") {
status = "\u{1F6AB} Deployment failed"; status = "\u{1F6AB} Deployment failed";
} }
await import_core.summary.addRaw(` await import_core.summary.addRaw(
`
# Deploying with Cloudflare Pages # Deploying with Cloudflare Pages
| Name | Result | | Name | Result |
@ -22148,7 +22146,8 @@ try {
| **Status**: | ${status} | | **Status**: | ${status} |
| **Preview URL**: | ${deployment.url} | | **Preview URL**: | ${deployment.url} |
| **Branch Preview URL**: | ${aliasUrl} | | **Branch Preview URL**: | ${aliasUrl} |
`).write(); `
).write();
}; };
(async () => { (async () => {
const project = await getProject(); const project = await getProject();

14
package-lock.json generated
View file

@ -19,7 +19,7 @@
"@types/node": "^18.11.3", "@types/node": "^18.11.3",
"esbuild": "^0.15.12", "esbuild": "^0.15.12",
"husky": "^8.0.1", "husky": "^8.0.1",
"prettier": "^2.6.2", "prettier": "^2.8.1",
"typescript": "^4.6.4" "typescript": "^4.6.4"
} }
}, },
@ -688,9 +688,9 @@
} }
}, },
"node_modules/prettier": { "node_modules/prettier": {
"version": "2.7.1", "version": "2.8.1",
"resolved": "https://registry.npmjs.org/prettier/-/prettier-2.7.1.tgz", "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.8.1.tgz",
"integrity": "sha512-ujppO+MkdPqoVINuDFDRLClm7D78qbDt0/NR+wp5FqEZOoTNAjPHWj17QRhu7geIHJfcNhRk1XVQmF8Bp3ye+g==", "integrity": "sha512-lqGoSJBQNJidqCHE80vqZJHWHRFoNYsSpP9AjFhlhi9ODCJA541svILes/+/1GM3VaL/abZi7cpFzOpdR9UPKg==",
"dev": true, "dev": true,
"bin": { "bin": {
"prettier": "bin-prettier.js" "prettier": "bin-prettier.js"
@ -1222,9 +1222,9 @@
} }
}, },
"prettier": { "prettier": {
"version": "2.7.1", "version": "2.8.1",
"resolved": "https://registry.npmjs.org/prettier/-/prettier-2.7.1.tgz", "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.8.1.tgz",
"integrity": "sha512-ujppO+MkdPqoVINuDFDRLClm7D78qbDt0/NR+wp5FqEZOoTNAjPHWj17QRhu7geIHJfcNhRk1XVQmF8Bp3ye+g==", "integrity": "sha512-lqGoSJBQNJidqCHE80vqZJHWHRFoNYsSpP9AjFhlhi9ODCJA541svILes/+/1GM3VaL/abZi7cpFzOpdR9UPKg==",
"dev": true "dev": true
}, },
"react": { "react": {

View file

@ -5,7 +5,8 @@
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
"build": "npx esbuild src/index.ts --bundle --platform=node --target=es2021 --outfile=index.js", "build": "npx esbuild src/index.ts --bundle --platform=node --target=es2021 --outfile=index.js",
"prepare": "husky install" "prepare": "husky install",
"prettify": "prettier . --write --ignore-unknown"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
@ -31,7 +32,7 @@
"@types/node": "^18.11.3", "@types/node": "^18.11.3",
"esbuild": "^0.15.12", "esbuild": "^0.15.12",
"husky": "^8.0.1", "husky": "^8.0.1",
"prettier": "^2.6.2", "prettier": "^2.8.1",
"typescript": "^4.6.4" "typescript": "^4.6.4"
} }
} }

View file

@ -1,5 +1,5 @@
import { getInput, setOutput, setFailed, summary } from "@actions/core"; 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 { context, getOctokit } from "@actions/github";
import shellac from "shellac"; import shellac from "shellac";
import { fetch } from "undici"; import { fetch } from "undici";
@ -20,9 +20,9 @@ try {
`https://api.cloudflare.com/client/v4/accounts/${accountId}/pages/projects/${projectName}`, `https://api.cloudflare.com/client/v4/accounts/${accountId}/pages/projects/${projectName}`,
{ headers: { Authorization: `Bearer ${apiToken}` } } { headers: { Authorization: `Bearer ${apiToken}` } }
); );
const { result } = await response.json() as { result: Project | null }; const { result } = (await response.json()) as { result: Project | null };
return result; return result;
} };
const createPagesDeployment = async () => { const createPagesDeployment = async () => {
// TODO: Replace this with an API call to wrangler so we can get back a full deployment response object // TODO: Replace this with an API call to wrangler so we can get back a full deployment response object
@ -71,7 +71,7 @@ try {
productionEnvironment, productionEnvironment,
octokit, octokit,
}: { }: {
octokit: Octokit, octokit: Octokit;
id: number; id: number;
url: string; url: string;
deploymentId: string; deploymentId: string;
@ -92,27 +92,19 @@ try {
}); });
}; };
const createJobSummary = async ( const createJobSummary = async ({ deployment, aliasUrl }: { deployment: Deployment; aliasUrl: string }) => {
{ const deployStage = deployment.stages.find((stage) => stage.name === "deploy");
deployment,
aliasUrl,
}:
{
deployment: Deployment;
aliasUrl: string;
}
) => {
const deployStage = deployment.stages.find((stage) => stage.name === 'deploy');
let status = '⚡️ Deployment in progress...'; let status = "⚡️ Deployment in progress...";
if (deployStage?.status === 'success') { if (deployStage?.status === "success") {
status = '✅ Deploy successful!'; status = "✅ Deploy successful!";
} else if (deployStage?.status === 'failure') { } else if (deployStage?.status === "failure") {
status = '🚫 Deployment failed'; status = "🚫 Deployment failed";
} }
await summary await summary
.addRaw(` .addRaw(
`
# Deploying with Cloudflare Pages # Deploying with Cloudflare Pages
| Name | Result | | Name | Result |
@ -121,13 +113,14 @@ try {
| **Status**: | ${status} | | **Status**: | ${status} |
| **Preview URL**: | ${deployment.url} | | **Preview URL**: | ${deployment.url} |
| **Branch Preview URL**: | ${aliasUrl} | | **Branch Preview URL**: | ${aliasUrl} |
`) `
)
.write(); .write();
} };
(async () => { (async () => {
const project = await getProject(); const project = await getProject();
if (!project) throw new Error('Unable to find pages project') if (!project) throw new Error("Unable to find pages project");
const githubBranch = env.GITHUB_REF_NAME; const githubBranch = env.GITHUB_REF_NAME;
const productionEnvironment = githubBranch === project.production_branch; const productionEnvironment = githubBranch === project.production_branch;
@ -162,7 +155,7 @@ try {
deploymentId: pagesDeployment.id, deploymentId: pagesDeployment.id,
environmentName, environmentName,
productionEnvironment, productionEnvironment,
octokit octokit,
}); });
} }
})(); })();