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
branch: main
# 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
# Optional: Change the Wrangler version, allows you to point to a specific version or a tag such as `beta`
wranglerVersion: '3'

@ -22,6 +22,9 @@ inputs:
branch:
description: "The name of the branch you want to deploy to"
required: false
environmentName:
description: "The name of the GitHub environment you want to associate with the deployment"
required: false
workingDirectory:
description: "The working directory in which to run Wrangler"
required: false

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

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

Loading…
Cancel
Save