diff --git a/action.yml b/action.yml index 791d61b6..131ceb7f 100644 --- a/action.yml +++ b/action.yml @@ -17,6 +17,9 @@ inputs: environment: description: "The name of the environment for the deployment" default: "production" + transient_environment: + description: "Specifies if the given environment is specific to the deployment and will no longer exist at some point in the future" + default: "false" outputs: deployment_id: description: "The ID of the created deployment" diff --git a/lib/main.js b/lib/main.js new file mode 100644 index 00000000..04b904f4 --- /dev/null +++ b/lib/main.js @@ -0,0 +1,59 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; + result["default"] = mod; + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const core = __importStar(require("@actions/core")); +const github = __importStar(require("@actions/github")); +function run() { + return __awaiter(this, void 0, void 0, function* () { + try { + const context = github.context; + const defaultUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/commit/${context.sha}/checks`; + const token = core.getInput("token", { required: true }); + const url = core.getInput("target_url", { required: false }) || defaultUrl; + const environment = core.getInput("environment", { required: false }) || "production"; + const description = core.getInput("description", { required: false }); + const initialStatus = core.getInput("initial_status", { + required: false + }) || "pending"; + const autoMergeStringInput = core.getInput("auto_merge", { + required: false + }); + const auto_merge = autoMergeStringInput === "true"; + const transient_environment = core.getInput("transient_environment", { + required: false + }) === "true"; + const client = new github.GitHub(token, { previews: ["flash", "ant-man"] }); + const deployment = yield client.repos.createDeployment({ + owner: context.repo.owner, + repo: context.repo.repo, + ref: context.ref, + required_contexts: [], + environment, + transient_environment, + auto_merge, + description + }); + yield client.repos.createDeploymentStatus(Object.assign({}, context.repo, { deployment_id: deployment.data.id, state: initialStatus, log_url: defaultUrl })); + core.setOutput("deployment_id", deployment.data.id.toString()); + } + catch (error) { + core.error(error); + core.setFailed(error.message); + } + }); +} +run(); diff --git a/src/main.ts b/src/main.ts index 68e55a3a..f39bdb01 100644 --- a/src/main.ts +++ b/src/main.ts @@ -30,6 +30,11 @@ async function run() { const auto_merge: boolean = autoMergeStringInput === "true"; + const transient_environment: boolean = + core.getInput("transient_environment", { + required: false + }) === "true"; + const client = new github.GitHub(token, { previews: ["flash", "ant-man"] }); const deployment = await client.repos.createDeployment({ @@ -38,7 +43,7 @@ async function run() { ref: context.ref, required_contexts: [], environment, - transient_environment: true, + transient_environment, auto_merge, description }); @@ -47,8 +52,7 @@ async function run() { ...context.repo, deployment_id: deployment.data.id, state: initialStatus, - log_url: defaultUrl, - target_url: url + log_url: defaultUrl }); core.setOutput("deployment_id", deployment.data.id.toString());