Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for auto_merge and required_contexts #152

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ inputs:
task:
required: false
description: The task to assign to the deployment, defaults to 'deploy'
auto_merge:
required: false
description: Attempts to automatically merge the default branch into the requested ref, if it's behind the default branch. Defaults to `false`
required_contexts:
required: false
description: The status contexts to verify against commit status checks, separated by commas. If this argument is `"*"`, all checks are run. If this argument is omitted, or if it's set to `""`, checking is bypassed entirely. Defaults to `""`.

debug:
required: false
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions src/lib/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,21 @@ export function getRequiredInput(key: string): string {
export function getOptionalInput(key: string): string | undefined {
return getInput(key, { required: false, trimWhitespace: true }) || undefined;
}

export function parseOptionalRequiredContexts(
key: string
): string[] | undefined {
const required_contexts = getOptionalInput(key);

if (required_contexts !== "*") {
if (
required_contexts == undefined ||
required_contexts === "" ||
required_contexts === "[]"
) {
return [];
} else {
return required_contexts.split(",");
}
}
}
7 changes: 6 additions & 1 deletion src/steps/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
getBooleanInput,
getOptionalInput,
getRequiredInput,
parseOptionalRequiredContexts,
} from "../lib/input";

import createStart, { StartArgs } from "./start";
Expand Down Expand Up @@ -36,11 +37,15 @@ export async function run(
if (rawPayload) {
payload = JSON.parse(rawPayload);
}
const stepArgs: StartArgs = {
let start_args = {
deploymentID: getOptionalInput("deployment_id"),
override: getBooleanInput("override", false), // default to false on start
auto_merge: getBooleanInput("auto_merge", false),
required_contexts:
parseOptionalRequiredContexts("required_contexts"),
payload,
};
const stepArgs: StartArgs = start_args;
log.debug(`'${step}' arguments`, {
stepArgs,
coreArgs,
Expand Down
11 changes: 7 additions & 4 deletions src/steps/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import deactivateEnvironment from "../lib/deactivate";
export type StartArgs = {
deploymentID?: string;
override: boolean;
auto_merge: boolean;
required_contexts?: string[];
payload?: { [key: string]: any };
};

Expand All @@ -30,18 +32,19 @@ async function createStart(
let deploymentID = -1;
if (!stepArgs.deploymentID) {
log.info(`initializing new deployment for ${environment} @ ${ref}`);
const deployment = await github.rest.repos.createDeployment({
let options = {
owner: owner,
repo: repo,
ref: ref,
task: task,
required_contexts: [],
environment: environment,
description: description,
auto_merge: false,
auto_merge: stepArgs.auto_merge,
required_contexts: stepArgs.required_contexts,
transient_environment: true,
payload: stepArgs.payload,
});
};
const deployment = await github.rest.repos.createDeployment(options);
if (deployment.status == 201) {
deploymentID = deployment.data.id;
} else {
Expand Down