From 06e15683f6bc4911b0c8749f33cb065fbd8547bc Mon Sep 17 00:00:00 2001 From: Nader Eloshaiker Date: Fri, 19 Jan 2024 16:16:09 +1100 Subject: [PATCH] add github environment option --- README.md | 2 ++ action.yml | 3 +++ index.js | 11 ++++++----- src/index.ts | 14 +++++++++++--- 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 290919d..4fc73f5 100644 --- a/README.md +++ b/README.md @@ -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' diff --git a/action.yml b/action.yml index 61e3f56..68ec74b 100644 --- a/action.yml +++ b/action.yml @@ -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 diff --git a/index.js b/index.js index 7df67c8..2ae60b4 100644 --- a/index.js +++ b/index.js @@ -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 }); diff --git a/src/index.ts b/src/index.ts index a63f38e..cbaaadc 100644 --- a/src/index.ts +++ b/src/index.ts @@ -7,6 +7,10 @@ import { env } from "process"; import path from "node:path"; type Octokit = ReturnType; +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>; 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, });