add github environment option

pull/116/head
Nader Eloshaiker 1 year ago
parent aeb0d936a7
commit 06e15683f6

@ -37,6 +37,8 @@ GitHub Action for creating Cloudflare Pages deployments, using the new [Direct U
# By default this will be the branch which triggered this workflow # By default this will be the branch which triggered this workflow
branch: main branch: main
# Optional: Change the working directory # Optional: Change the working directory
environmentName: projectName (Production)
# Optional: The name of the GitHub environment you want to associate with the deployment
workingDirectory: my-site workingDirectory: my-site
# Optional: Change the Wrangler version, allows you to point to a specific version or a tag such as `beta` # Optional: Change the Wrangler version, allows you to point to a specific version or a tag such as `beta`
wranglerVersion: '3' wranglerVersion: '3'

@ -22,6 +22,9 @@ inputs:
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
environmentName:
description: "The name of the GitHub environment you want to associate with the deployment"
required: false
workingDirectory: workingDirectory:
description: "The working directory in which to run Wrangler" description: "The working directory in which to run Wrangler"
required: false required: false

@ -22068,6 +22068,7 @@ try {
const directory = (0, import_core.getInput)("directory", { required: true }); const directory = (0, import_core.getInput)("directory", { required: true });
const gitHubToken = (0, import_core.getInput)("gitHubToken", { required: false }); const gitHubToken = (0, import_core.getInput)("gitHubToken", { required: false });
const branch = (0, import_core.getInput)("branch", { required: false }); const branch = (0, import_core.getInput)("branch", { required: false });
const environmentName = (0, import_core.getInput)("environmentName", { required: false });
const workingDirectory = (0, import_core.getInput)("workingDirectory", { required: false }); const workingDirectory = (0, import_core.getInput)("workingDirectory", { required: false });
const wranglerVersion = (0, import_core.getInput)("wranglerVersion", { required: false }); const wranglerVersion = (0, import_core.getInput)("wranglerVersion", { required: false });
const getProject = async () => { const getProject = async () => {
@ -22125,7 +22126,7 @@ try {
id, id,
url, url,
deploymentId, deploymentId,
environmentName, environmentName: environmentName2,
productionEnvironment, productionEnvironment,
octokit octokit
}) => { }) => {
@ -22133,7 +22134,7 @@ try {
owner: import_github.context.repo.owner, owner: import_github.context.repo.owner,
repo: import_github.context.repo.repo, repo: import_github.context.repo.repo,
deployment_id: id, deployment_id: id,
environment: environmentName, environment: environmentName2,
environment_url: url, environment_url: url,
production_environment: productionEnvironment, production_environment: productionEnvironment,
log_url: `https://dash.cloudflare.com/${accountId}/pages/view/${projectName}/${deploymentId}`, log_url: `https://dash.cloudflare.com/${accountId}/pages/view/${projectName}/${deploymentId}`,
@ -22166,11 +22167,11 @@ try {
(async () => { (async () => {
const project = await getProject(); const project = await getProject();
const productionEnvironment = githubBranch === project.production_branch || branch === project.production_branch; const productionEnvironment = githubBranch === project.production_branch || branch === project.production_branch;
const environmentName = `${projectName} (${productionEnvironment ? "Production" : "Preview"})`; const githubEnvironmentName = environmentName ? environmentName : `${projectName} (${productionEnvironment ? "Production" /* PRODUCTION */ : "Preview" /* PREVIEW */})`;
let gitHubDeployment; let gitHubDeployment;
if (gitHubToken && gitHubToken.length) { if (gitHubToken && gitHubToken.length) {
const octokit = (0, import_github.getOctokit)(gitHubToken); const octokit = (0, import_github.getOctokit)(gitHubToken);
gitHubDeployment = await createGitHubDeployment(octokit, productionEnvironment, environmentName); gitHubDeployment = await createGitHubDeployment(octokit, productionEnvironment, githubEnvironmentName);
} }
const pagesDeployment = await createPagesDeployment(); const pagesDeployment = await createPagesDeployment();
(0, import_core.setOutput)("id", pagesDeployment.id); (0, import_core.setOutput)("id", pagesDeployment.id);
@ -22188,7 +22189,7 @@ try {
id: gitHubDeployment.id, id: gitHubDeployment.id,
url: pagesDeployment.url, url: pagesDeployment.url,
deploymentId: pagesDeployment.id, deploymentId: pagesDeployment.id,
environmentName, environmentName: githubEnvironmentName,
productionEnvironment, productionEnvironment,
octokit octokit
}); });

@ -7,6 +7,10 @@ import { env } from "process";
import path from "node:path"; import path from "node:path";
type Octokit = ReturnType<typeof getOctokit>; type Octokit = ReturnType<typeof getOctokit>;
enum CloudflarePagesEnvironment {
PRODUCTION = "Production",
PREVIEW = "Preview",
}
try { try {
const apiToken = getInput("apiToken", { required: true }); const apiToken = getInput("apiToken", { required: true });
@ -15,6 +19,7 @@ try {
const directory = getInput("directory", { required: true }); const directory = getInput("directory", { required: true });
const gitHubToken = getInput("gitHubToken", { required: false }); const gitHubToken = getInput("gitHubToken", { required: false });
const branch = getInput("branch", { required: false }); const branch = getInput("branch", { required: false });
const environmentName = getInput("environmentName", { required: false });
const workingDirectory = getInput("workingDirectory", { required: false }); const workingDirectory = getInput("workingDirectory", { required: false });
const wranglerVersion = getInput("wranglerVersion", { required: false }); const wranglerVersion = getInput("wranglerVersion", { required: false });
@ -139,13 +144,16 @@ try {
const project = await getProject(); const project = await getProject();
const productionEnvironment = githubBranch === project.production_branch || branch === project.production_branch; const productionEnvironment = githubBranch === project.production_branch || branch === project.production_branch;
const environmentName = `${projectName} (${productionEnvironment ? "Production" : "Preview"})`; const githubEnvironmentName = environmentName
? environmentName
: `${projectName} (${
productionEnvironment ? CloudflarePagesEnvironment.PRODUCTION : CloudflarePagesEnvironment.PREVIEW})`;
let gitHubDeployment: Awaited<ReturnType<typeof createGitHubDeployment>>; let gitHubDeployment: Awaited<ReturnType<typeof createGitHubDeployment>>;
if (gitHubToken && gitHubToken.length) { if (gitHubToken && gitHubToken.length) {
const octokit = getOctokit(gitHubToken); const octokit = getOctokit(gitHubToken);
gitHubDeployment = await createGitHubDeployment(octokit, productionEnvironment, environmentName); gitHubDeployment = await createGitHubDeployment(octokit, productionEnvironment, githubEnvironmentName);
} }
const pagesDeployment = await createPagesDeployment(); const pagesDeployment = await createPagesDeployment();
@ -168,7 +176,7 @@ try {
id: gitHubDeployment.id, id: gitHubDeployment.id,
url: pagesDeployment.url, url: pagesDeployment.url,
deploymentId: pagesDeployment.id, deploymentId: pagesDeployment.id,
environmentName, environmentName: githubEnvironmentName,
productionEnvironment, productionEnvironment,
octokit, octokit,
}); });

Loading…
Cancel
Save