Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Changes were made to make the values cleaner and fix some incorrect
assumptions.
  • Loading branch information
halostatue committed Feb 29, 2024
1 parent 1737a32 commit 6a0fe58
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 19 deletions.
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,14 @@ a deployment as "started":
In addition to the [core configuration](#configuration), the following
[`inputs`][actions-input] are available:

| Variable | Default | Purpose |
| --------------- | ---------- | --------------------------------------------------------------------------------------------------- |
| `deployment_id` | | Use an existing deployment instead of creating a new one (e.g. `${{ github.event.deployment.id }}`) |
| `override` | `false` | whether to mark existing deployments of this environment as inactive |
| `payload` | | JSON-formatted dictionary with extra information about the deployment |
| `task` | `'deploy'` | change the task associated with this deployment, can be any string |
| Variable | Default | Purpose |
| ------------------- | ---------- | -------------------------------------------------------------------------------------------------------------------------- |
| `deployment_id` | | Use an existing deployment instead of creating a new one (e.g. `${{ github.event.deployment.id }}`) |
| `override` | `false` | whether to mark existing deployments of this environment as inactive |
| `auto_merge` | `false` | Attempts to automatically merge the default branch into the requested ref, if it's behind the default branch. |
| `required_contexts` | `''` | The names of any status contexts to verify against, separated by newlines. To bypass checking entirely, pass a string `''` |
| `payload` | | JSON-formatted dictionary with extra information about the deployment |
| `task` | `'deploy'` | change the task associated with this deployment, can be any string |

The following [`outputs`][actions-output] are available:

Expand Down
14 changes: 14 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,17 @@ inputs:
description: |
JSON-formatted dictionary with extra information about the deployment (for
`start` only)
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`
default: '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 `""`.
default: '""'
16 changes: 16 additions & 0 deletions src/lib/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,19 @@ 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 requiredContext = getOptionalInput(key)

if (requiredContext !== '*') {
if (
requiredContext == null ||
requiredContext === '' ||
(Array.isArray(requiredContext) && requiredContext.length === 0)
) {
return []
}

return requiredContext.split('\n').flatMap((s) => s.split(','))
}
}
10 changes: 4 additions & 6 deletions src/steps/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { GitHub } from '@actions/github/lib/utils'
import { DeploymentContext } from '../lib/context'
import deactivateEnvironment from '../lib/deactivate'
import deleteEnvironment from '../lib/delete'
import { getBooleanInput, getOptionalInput, getRequiredInput } from '../lib/input'
import { getBooleanInput, getOptionalInput, getRequiredInput, parseOptionalRequiredContexts } from '../lib/input'

import createFinish, { FinishArgs } from './finish'
import createStart, { StartArgs } from './start'
Expand All @@ -16,11 +16,7 @@ export enum Step {
DeleteEnv = 'delete-env',
}

export async function run(
step: Step,
github: InstanceType<typeof GitHub>,
context: DeploymentContext,
) {
export async function run(step: Step, github: InstanceType<typeof GitHub>, context: DeploymentContext) {
const { log, coreArgs } = context

try {
Expand All @@ -37,6 +33,8 @@ export async function run(
const stepArgs: StartArgs = {
deploymentID: getOptionalInput('deployment_id'),
override: getBooleanInput('override', false), // default to false on start
autoMerge: getBooleanInput('auto_merge', false),
requiredContexts: parseOptionalRequiredContexts('required_contexts'),
payload,
}

Expand Down
12 changes: 5 additions & 7 deletions src/steps/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@ import deactivateEnvironment from '../lib/deactivate'
export type StartArgs = {
deploymentID?: string
override: boolean
autoMerge: boolean
requiredContexts?: string[]
payload?: Record<string, unknown>
}

async function createStart(
github: InstanceType<typeof GitHub>,
context: DeploymentContext,
stepArgs: StartArgs,
) {
async function createStart(github: InstanceType<typeof GitHub>, context: DeploymentContext, stepArgs: StartArgs) {
if (stepArgs.override) {
await deactivateEnvironment(github, context)
}
Expand All @@ -35,10 +33,10 @@ async function createStart(
repo: repo,
ref: ref,
task: task,
required_contexts: [],
environment: environment,
description: description,
auto_merge: false,
auto_merge: stepArgs.autoMerge,
required_contexts: stepArgs.requiredContexts,
transient_environment: true,
payload: stepArgs.payload,
})
Expand Down

0 comments on commit 6a0fe58

Please sign in to comment.