Skip to content

Commit 256fba9

Browse files
committed
Add support for auto_merge and required_contexts
1 parent 8a87bc3 commit 256fba9

File tree

8 files changed

+142
-100
lines changed

8 files changed

+142
-100
lines changed

README.md

Lines changed: 96 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -5,73 +5,75 @@ Instead of exposing convoluted Action configuration that mirrors that of the [Gi
55

66
> 📢 This project is in need of additional maintainers - if you are interested in helping out please [let me know](https://github.com/bobheadxi/deployments/discussions/103)!
77
8-
- [Configuration](#configuration)
9-
- [`step: start`](#step-start)
10-
- [`step: finish`](#step-finish)
11-
- [`step: deactivate-env`](#step-deactivate-env)
12-
- [`step: delete-env`](#step-delete-env)
13-
- [Debugging](#debugging)
14-
- [Migrating to v1](#migrating-to-v1)
8+
- [GitHub Deployments ](#github-deployments--)
9+
- [Configuration](#configuration)
10+
- [`step: start`](#step-start)
11+
- [`step: finish`](#step-finish)
12+
- [`step: deactivate-env`](#step-deactivate-env)
13+
- [`step: delete-env`](#step-delete-env)
14+
- [Debugging](#debugging)
15+
- [Migrating to v1](#migrating-to-v1)
16+
- [Migrating to v1.2.0](#migrating-to-v120)
1517

1618
A simple example:
1719

1820
```yml
1921
on:
2022
push:
2123
branches:
22-
- main
24+
- main
2325

2426
jobs:
2527
deploy:
2628
runs-on: ubuntu-latest
2729
steps:
28-
- name: start deployment
29-
uses: bobheadxi/deployments@v1
30-
id: deployment
31-
with:
32-
step: start
33-
token: ${{ secrets.GITHUB_TOKEN }}
34-
env: release
35-
36-
- name: do my deploy
37-
# ...
38-
39-
- name: update deployment status
40-
uses: bobheadxi/deployments@v1
41-
if: always()
42-
with:
43-
step: finish
44-
token: ${{ secrets.GITHUB_TOKEN }}
45-
status: ${{ job.status }}
46-
env: ${{ steps.deployment.outputs.env }}
47-
deployment_id: ${{ steps.deployment.outputs.deployment_id }}
30+
- name: start deployment
31+
uses: bobheadxi/deployments@v1
32+
id: deployment
33+
with:
34+
step: start
35+
token: ${{ secrets.GITHUB_TOKEN }}
36+
env: release
37+
38+
- name: do my deploy
39+
# ...
40+
41+
- name: update deployment status
42+
uses: bobheadxi/deployments@v1
43+
if: always()
44+
with:
45+
step: finish
46+
token: ${{ secrets.GITHUB_TOKEN }}
47+
status: ${{ job.status }}
48+
env: ${{ steps.deployment.outputs.env }}
49+
deployment_id: ${{ steps.deployment.outputs.deployment_id }}
4850
```
4951
5052
You can also refer to other projects that also use this action - you can find [more usages of this action on Sourcegraph](https://sourcegraph.com/search?q=context:global+uses:+bobheadxi/deployments%40.*+file:%5E%5C.github/workflows+-repo:bobheadxi+count:all&patternType=regexp), or check out the following examples:
5153
5254
- [`github/super-linter`](https://sourcegraph.com/search?q=context:global+repo:%5Egithub%5C.com/github/super-linter%24+file:%5E%5C.github/workflows+bobheadxi/deployments&patternType=literal) [![GitHub Repo stars](https://img.shields.io/github/stars/github/super-linter?style=social)](https://github.com/github/super-linter) - [GitHub's all-in-one linter Action](https://github.blog/2020-06-18-introducing-github-super-linter-one-linter-to-rule-them-all/)
5355
- [`mxcl/PromiseKit`](https://sourcegraph.com/search?q=context:global+repo:%5Egithub%5C.com/mxcl/PromiseKit%24+file:%5E%5C.github/workflows+bobheadxi/deployments&patternType=literal) [![GitHub Repo stars](https://img.shields.io/github/stars/mxcl/PromiseKit?style=social)](https://github.com/mxcl/PromiseKit) - promises for Swift and Objective-C
54-
- [`saleor/saleor`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/saleor/saleor%24+bobheadxi/deployments\&patternType=literal) [![GitHub Repo stars](https://img.shields.io/github/stars/saleor/saleor?style=social)](https://github.com/saleor/saleor) - modular, high performance, headless e-commerce storefront
56+
- [`saleor/saleor`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/saleor/saleor%24+bobheadxi/deployments&patternType=literal) [![GitHub Repo stars](https://img.shields.io/github/stars/saleor/saleor?style=social)](https://github.com/saleor/saleor) - modular, high performance, headless e-commerce storefront
5557
- [`sharetribe/sharetribe`](https://sourcegraph.com/search?q=context:global+repo:%5Egithub%5C.com/sharetribe/sharetribe%24+file:%5E%5C.github/workflows+bobheadxi/deployments&patternType=literal) [![GitHub Repo stars](https://img.shields.io/github/stars/sharetribe/sharetribe?style=social)](https://github.com/sharetribe/sharetribe) - marketplace software
56-
- [`skylines-project/skylines`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/skylines-project/skylines%24+bobheadxi/deployments\&patternType=literal) [![GitHub Repo stars](https://img.shields.io/github/stars/skylines-project/skylines?style=social)](https://github.com/skylines-project/skylines) - live tracking, flight database and competition web platform
58+
- [`skylines-project/skylines`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/skylines-project/skylines%24+bobheadxi/deployments&patternType=literal) [![GitHub Repo stars](https://img.shields.io/github/stars/skylines-project/skylines?style=social)](https://github.com/skylines-project/skylines) - live tracking, flight database and competition web platform
5759

5860
Also feel free to chime in on the [show and tell discussion](https://github.com/bobheadxi/deployments/discussions/84) to share your usages of this Action!
5961

6062
Check out [this blog post](https://dev.to/bobheadxi/branch-previews-with-google-app-engine-and-github-actions-3pco) for a bit of background on the origins of this project.
6163

6264
## Configuration
6365

64-
The following [`inputs`](https://help.github.com/en/articles/workflow-syntax-for-github-actions#jobsjob_idstepswith) configuration options are for *all steps*:
66+
The following [`inputs`](https://help.github.com/en/articles/workflow-syntax-for-github-actions#jobsjob_idstepswith) configuration options are for _all steps_:
6567

6668
| Variable | Default | Purpose |
6769
| ------------ | ---------------------------- | -------------------------------------------------------------------------------------------------------------------------------------- |
6870
| `step` | | One of [`start`](#step-start), [`finish`](#step-finish), [`deactivate-env`](#step-deactivate-env), or [`delete-env`](#step-delete-env) |
69-
| `token` | `${{ github.token }}` | provide your `${{ github.token }}` or `${{ secrets.GITHUB_TOKEN }}` for API access |
71+
| `token` | `${{ github.token }}` | provide your `${{ github.token }}` or `${{ secrets.GITHUB_TOKEN }}` for API access |
7072
| `env` | | identifier for environment to deploy to (e.g. `staging`, `prod`, `main`) |
7173
| `repository` | Current repository | target a specific repository for updates, e.g. `owner/repo` |
7274
| `logs` | URL to GitHub commit checks | URL of your deployment logs |
7375
| `desc` | GitHub-generated description | description for this deployment |
74-
| `ref` | `github.ref` | Specify a particular git ref to use, (e.g. `${{ github.head_ref }}`) |
76+
| `ref` | `github.ref` | Specify a particular git ref to use, (e.g. `${{ github.head_ref }}`) |
7577

7678
### `step: start`
7779

@@ -82,13 +84,14 @@ This is best used on the `push: { branches: [ ... ] }` event, but you can also h
8284

8385
In addition to the [core configuration](#configuration), the following [`inputs`](https://help.github.com/en/articles/workflow-syntax-for-github-actions#jobsjob_idstepswith) are available:
8486

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

9396
The following [`outputs`](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/contexts-and-expression-syntax-for-github-actions#steps-context) are available:
9497

@@ -106,20 +109,20 @@ The following [`outputs`](https://help.github.com/en/actions/automating-your-wor
106109
on:
107110
push:
108111
branches:
109-
- main
112+
- main
110113
111114
jobs:
112115
deploy:
113116
steps:
114-
- name: start deployment
115-
uses: bobheadxi/deployments@v1
116-
id: deployment
117-
with:
118-
step: start
119-
env: release
120-
121-
- name: do my deploy
122-
# ...
117+
- name: start deployment
118+
uses: bobheadxi/deployments@v1
119+
id: deployment
120+
with:
121+
step: start
122+
env: release
123+
124+
- name: do my deploy
125+
# ...
123126
```
124127

125128
</p>
@@ -139,15 +142,15 @@ jobs:
139142
deploy:
140143
runs-on: ubuntu-latest
141144
steps:
142-
- name: start deployment
143-
uses: bobheadxi/deployments@v1
144-
id: deployment
145-
with:
146-
step: start
147-
env: integration
148-
149-
- name: do my deploy
150-
# ...
145+
- name: start deployment
146+
uses: bobheadxi/deployments@v1
147+
id: deployment
148+
with:
149+
step: start
150+
env: integration
151+
152+
- name: do my deploy
153+
# ...
151154
```
152155

153156
</p>
@@ -182,21 +185,21 @@ In addition to the [core configuration](#configuration), the following [`inputs`
182185
jobs:
183186
deploy:
184187
steps:
185-
- name: start deployment
186-
# ... see previous example
187-
188-
- name: do my deploy
189-
# ...
190-
191-
- name: update deployment status
192-
uses: bobheadxi/deployments@v1
193-
if: always()
194-
with:
195-
step: finish
196-
token: ${{ secrets.GITHUB_TOKEN }}
197-
status: ${{ job.status }}
198-
env: ${{ steps.deployment.outputs.env }}
199-
deployment_id: ${{ steps.deployment.outputs.deployment_id }}
188+
- name: start deployment
189+
# ... see previous example
190+
191+
- name: do my deploy
192+
# ...
193+
194+
- name: update deployment status
195+
uses: bobheadxi/deployments@v1
196+
if: always()
197+
with:
198+
step: finish
199+
token: ${{ secrets.GITHUB_TOKEN }}
200+
status: ${{ job.status }}
201+
env: ${{ steps.deployment.outputs.env }}
202+
deployment_id: ${{ steps.deployment.outputs.deployment_id }}
200203
```
201204

202205
</p>
@@ -220,29 +223,29 @@ Refer to the [core configuration](#configuration) for available [`inputs`](https
220223
```yml
221224
on:
222225
pull_request:
223-
types: [ closed ]
226+
types: [closed]
224227
225228
jobs:
226229
prune:
227230
steps:
228-
# see https://dev.to/bobheadxi/branch-previews-with-google-app-engine-and-github-actions-3pco
229-
- name: extract branch name
230-
id: get_branch
231-
shell: bash
232-
env:
233-
PR_HEAD: ${{ github.head_ref }}
234-
run: echo "##[set-output name=branch;]$(echo ${PR_HEAD#refs/heads/} | tr / -)"
235-
236-
- name: do my deployment shutdown
237-
# ...
238-
239-
- name: mark environment as deactivated
240-
uses: bobheadxi/deployments@v1
241-
with:
242-
step: deactivate-env
243-
token: ${{ secrets.GITHUB_TOKEN }}
244-
env: ${{ steps.get_branch.outputs.branch }}
245-
desc: Environment was pruned
231+
# see https://dev.to/bobheadxi/branch-previews-with-google-app-engine-and-github-actions-3pco
232+
- name: extract branch name
233+
id: get_branch
234+
shell: bash
235+
env:
236+
PR_HEAD: ${{ github.head_ref }}
237+
run: echo "##[set-output name=branch;]$(echo ${PR_HEAD#refs/heads/} | tr / -)"
238+
239+
- name: do my deployment shutdown
240+
# ...
241+
242+
- name: mark environment as deactivated
243+
uses: bobheadxi/deployments@v1
244+
with:
245+
step: deactivate-env
246+
token: ${{ secrets.GITHUB_TOKEN }}
247+
env: ${{ steps.get_branch.outputs.branch }}
248+
desc: Environment was pruned
246249
```
247250

248251
</p>

action.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ inputs:
3434
task:
3535
required: false
3636
description: The task to assign to the deployment, defaults to 'deploy'
37+
auto_merge:
38+
required: false
39+
description: Attempts to automatically merge the default branch into the requested ref, if it's behind the default branch. Defaults to `false`
40+
required_contexts:
41+
required: false
42+
description: The status contexts to verify against commit status checks, separated by newlines. If you omit this parameter, GitHub verifies all unique contexts before creating a deployment. To bypass checking entirely, pass an empty string. Defaults to `""`.
3743

3844
debug:
3945
required: false

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lib/context.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import { context } from "@actions/github";
2-
import { getBooleanInput, getOptionalInput, getRequiredInput } from "./input";
2+
import {
3+
getBooleanInput,
4+
getOptionalInput,
5+
getRequiredInput,
6+
parseOptionalStringArrayInput,
7+
} from "./input";
38
import Logger from "./log";
49

510
export interface DeploymentContext {

src/lib/input.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,22 @@ export function getRequiredInput(key: string): string {
1919
export function getOptionalInput(key: string): string | undefined {
2020
return getInput(key, { required: false, trimWhitespace: true }) || undefined;
2121
}
22+
23+
export function parseOptionalStringArrayInput(
24+
key: string
25+
): string[] | undefined {
26+
const input = getOptionalInput(key);
27+
28+
if (input === undefined) {
29+
return [];
30+
} else if (input === "null") {
31+
return undefined;
32+
}
33+
34+
const strings: string[] = [];
35+
for (const line of input.split(/\r|\n/)) {
36+
strings.push(line);
37+
}
38+
39+
return strings;
40+
}

src/steps/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
getBooleanInput,
99
getOptionalInput,
1010
getRequiredInput,
11+
parseOptionalStringArrayInput,
1112
} from "../lib/input";
1213

1314
import createStart, { StartArgs } from "./start";
@@ -39,6 +40,9 @@ export async function run(
3940
const stepArgs: StartArgs = {
4041
deploymentID: getOptionalInput("deployment_id"),
4142
override: getBooleanInput("override", false), // default to false on start
43+
auto_merge: getBooleanInput("auto_merge", false),
44+
required_contexts:
45+
parseOptionalStringArrayInput("required_contexts"),
4246
payload,
4347
};
4448
log.debug(`'${step}' arguments`, {

src/steps/start.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import deactivateEnvironment from "../lib/deactivate";
66
export type StartArgs = {
77
deploymentID?: string;
88
override: boolean;
9+
auto_merge: boolean;
10+
required_contexts: string[] | undefined;
911
payload?: { [key: string]: any };
1012
};
1113

@@ -30,18 +32,21 @@ async function createStart(
3032
let deploymentID = -1;
3133
if (!stepArgs.deploymentID) {
3234
log.info(`initializing new deployment for ${environment} @ ${ref}`);
33-
const deployment = await github.rest.repos.createDeployment({
35+
let options = {
3436
owner: owner,
3537
repo: repo,
3638
ref: ref,
3739
task: task,
38-
required_contexts: [],
3940
environment: environment,
4041
description: description,
41-
auto_merge: false,
42+
auto_merge: stepArgs.auto_merge,
4243
transient_environment: true,
4344
payload: stepArgs.payload,
44-
});
45+
};
46+
if (stepArgs.required_contexts !== undefined) {
47+
options["required_contexts"] = stepArgs.required_contexts;
48+
}
49+
const deployment = await github.rest.repos.createDeployment(options);
4550
if (deployment.status == 201) {
4651
deploymentID = deployment.data.id;
4752
} else {

0 commit comments

Comments
 (0)