Whole bunch of general improvements

pull/33/head
Daniel Walsh 3 years ago
parent 364c7ca09a
commit c3fff75cbf
No known key found for this signature in database
GPG Key ID: 2533E346A14D232D

@ -31,6 +31,7 @@ GitHub Action for creating Cloudflare Pages deployments, using the new [Direct U
accountId: YOUR_ACCOUNT_ID accountId: YOUR_ACCOUNT_ID
projectName: YOUR_PROJECT_NAME projectName: YOUR_PROJECT_NAME
directory: YOUR_ASSET_DIRECTORY directory: YOUR_ASSET_DIRECTORY
# Optional: Enable this if you want to have GitHub Deployments triggered
gitHubToken: ${{ secrets.GITHUB_TOKEN }} gitHubToken: ${{ secrets.GITHUB_TOKEN }}
``` ```

@ -18,7 +18,7 @@ inputs:
required: true required: true
gitHubToken: gitHubToken:
description: "GitHub Token" description: "GitHub Token"
required: true required: false
branch: branch:
description: "The name of the branch you want to deploy to" description: "The name of the branch you want to deploy to"
required: false required: false

9618
index.js

File diff suppressed because one or more lines are too long

782
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -21,13 +21,14 @@
}, },
"homepage": "https://github.com/cloudflare/pages-action#readme", "homepage": "https://github.com/cloudflare/pages-action#readme",
"dependencies": { "dependencies": {
"@actions/core": "^1.8.0", "@actions/core": "^1.10.0",
"@actions/github": "^5.0.1", "@actions/github": "^5.1.1",
"shellac": "^0.7.0", "@cloudflare/types": "^6.16.10",
"undici": "^5.1.1" "shellac": "^0.7.2",
"undici": "^5.11.0"
}, },
"devDependencies": { "devDependencies": {
"esbuild": "^0.14.38", "esbuild": "^0.15.12",
"husky": "^8.0.1", "husky": "^8.0.1",
"prettier": "^2.6.2", "prettier": "^2.6.2",
"typescript": "^4.6.4" "typescript": "^4.6.4"

@ -2,57 +2,14 @@ import { getInput, setOutput, setFailed } from "@actions/core";
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";
import { Deployment } from '@cloudflare/types';
// TODO: Confirm types
interface Stage {
name: string;
started_on: null | string;
ended_on: null | string;
status: string;
}
interface Deployment {
id: string;
short_id: string;
project_id: string;
project_name: string;
environment: string;
url: string;
created_on: string;
modified_on: string;
latest_stage: Stage;
deployment_trigger: {
type: string;
metadata: {
branch: string;
commit_hash: string;
commit_message: string;
commit_dirty: boolean;
};
};
stages: Stage[];
build_config: {
build_command: null | string;
destination_dir: null | string;
root_dir: null | string;
web_analytics_tag: null | string;
web_analytics_token: null | string;
fast_builds: boolean;
};
env_vars: unknown;
kv_namespaces: Record<string, { namespace_id: string }>;
aliases: null | string[];
is_skipped: boolean;
production_branch: string;
}
try { try {
const apiToken = getInput("apiToken", { required: true }); const apiToken = getInput("apiToken", { required: true });
const accountId = getInput("accountId", { required: true }); const accountId = getInput("accountId", { required: true });
const projectName = getInput("projectName", { required: true }); const projectName = getInput("projectName", { required: true });
const directory = getInput("directory", { required: true }); const directory = getInput("directory", { required: true });
const gitHubToken = getInput("gitHubToken", { required: true }); const gitHubToken = getInput("gitHubToken", { required: false });
const branch = getInput("branch", { required: false }); const branch = getInput("branch", { required: false });
const octokit = getOctokit(gitHubToken); const octokit = getOctokit(gitHubToken);
@ -97,11 +54,13 @@ try {
const createGitHubDeploymentStatus = async ({ const createGitHubDeploymentStatus = async ({
id, id,
url, url,
deploymentId,
environmentName, environmentName,
productionEnvironment, productionEnvironment,
}: { }: {
id: number; id: number;
url: string; url: string;
deploymentId: string;
environmentName: string; environmentName: string;
productionEnvironment: boolean; productionEnvironment: boolean;
}) => { }) => {
@ -113,13 +72,17 @@ try {
environment: environmentName, environment: environmentName,
environment_url: url, environment_url: url,
production_environment: productionEnvironment, production_environment: productionEnvironment,
log_url: `https://dash.cloudflare.com/${accountId}/pages/view/${projectName}/${id}`, log_url: `https://dash.cloudflare.com/${accountId}/pages/view/${projectName}/${deploymentId}`,
description: "Cloudflare Pages", description: "Cloudflare Pages",
state: "success", state: "success",
}); });
}; };
(async () => { (async () => {
if (gitHubToken === "") {
return;
}
const gitHubDeployment = await createGitHubDeployment(); const gitHubDeployment = await createGitHubDeployment();
const pagesDeployment = await createPagesDeployment(); const pagesDeployment = await createPagesDeployment();
@ -127,17 +90,19 @@ try {
setOutput("id", pagesDeployment.id); setOutput("id", pagesDeployment.id);
setOutput("url", pagesDeployment.url); setOutput("url", pagesDeployment.url);
setOutput("environment", pagesDeployment.environment); setOutput("environment", pagesDeployment.environment);
setOutput("alias", pagesDeployment.environment === "production" ? pagesDeployment.url : pagesDeployment.aliases[0]);
const url = new URL(pagesDeployment.url);
const productionEnvironment = pagesDeployment.environment === "production"; const productionEnvironment = pagesDeployment.environment === "production";
const environmentName = productionEnvironment const environmentName = productionEnvironment
? "Production" ? "Production"
: `Preview (${url.host.split(".")[0]})`; // Use the branch alias (staging/walshy-fix-bug)
: `Preview (${pagesDeployment.aliases[0]})`;
if (gitHubDeployment) { if (gitHubDeployment) {
await createGitHubDeploymentStatus({ await createGitHubDeploymentStatus({
id: gitHubDeployment.id, id: gitHubDeployment.id,
url: pagesDeployment.url, url: pagesDeployment.url,
deploymentId: pagesDeployment.id,
environmentName, environmentName,
productionEnvironment, productionEnvironment,
}); });

Loading…
Cancel
Save