Skip to content

Commit a321f07

Browse files
authored
Merge pull request #272 from github/post-deploy-features
Post Deploy Feature Improvements
2 parents 0b9d287 + 16a4d90 commit a321f07

24 files changed

+785
-88
lines changed

README.md

+9
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,10 @@ As seen above, we have two steps. One for a noop deploy, and one for a regular d
289289
| `sticky_locks_for_noop` | `false` | `"false"` | If set to `"true"`, then sticky_locks will also be used for noop deployments. This can be useful in some cases but it often leads to locks being left behind when users test noop deployments. |
290290
| `allow_sha_deployments` | `false` | `"false"` | If set to `"true"`, then you can deploy a specific sha instead of a branch. Example: `".deploy 1234567890abcdef1234567890abcdef12345678 to production"` - This is dangerous and potentially unsafe, [view the docs](docs/sha-deployments.md) to learn more |
291291
| `disable_naked_commands` | `false` | `"false"` | If set to `"true"`, then naked commands will be disabled. Example: `.deploy` will not trigger a deployment. Instead, you must use `.deploy to production` to trigger a deployment. This is useful if you want to prevent accidental deployments from happening. View the [docs](docs/naked-commands.md) to learn more |
292+
| `successful_deploy_labels` | `false` | `""` | A comma separated list of labels to add to the pull request when a deployment is successful. Example: `"deployed,success"` |
293+
| `successful_noop_labels` | `false` | `""` | A comma separated list of labels to add to the pull request when a noop deployment is successful. Example: `"noop,success"` |
294+
| `failed_deploy_labels` | `false` | `""` | A comma separated list of labels to add to the pull request when a deployment fails. Example: `"failed,deploy-failed"` |
295+
| `failed_noop_labels` | `false` | `""` | A comma separated list of labels to add to the pull request when a noop deployment fails. Example: `"failed,noop-failed"` |
292296

293297
## Outputs 📤
294298

@@ -320,6 +324,11 @@ As seen above, we have two steps. One for a noop deploy, and one for a regular d
320324
| `global_lock_released` | The string "true" if the global lock was released |
321325
| `unlocked_environments` | Only exposed when using the "unlock on merge" mode - This output variable will contain a comma separated list of the environments that were unlocked - See the [unlock on merge mode](docs/unlock-on-merge.md) documentation for more details |
322326
| `sha_deployment` | If `allow_sha_deployments` is enabled, and a sha deployment is performed instead of a branch deployment, this output variable will contain the sha that was deployed. Otherwise, this output variable will be empty |
327+
| `review_decision` | The pull request review status. Can be one of a few values - examples: `APPROVED`, `skip_reviews`, `REVIEW_REQUIRED`, `null` |
328+
| `is_outdated` | The string `"true"` if the branch is out-of-date, otherwise `"false"` |
329+
| `merge_state_status` | The status of the merge state. Can be one of a few values - examples: `"DIRTY"`, `"DRAFT"`, `"CLEAN"`, etc |
330+
| `commit_status` | The status of the commit. Can be one of a few values - examples: `"SUCCESS"`, `null`, `"skip_ci"`, `"PENDING"`, `"FAILURE"` etc |
331+
| `approved_reviews_count` | The number of approved reviews on the pull request |
323332

324333
## Custom Deployment Messages ✏️
325334

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
import {checkInput} from '../../src/functions/check-input'
22

33
test('checks an input an finds that it is valid', async () => {
4-
expect(await checkInput('production')).toStrictEqual('production')
4+
expect(checkInput('production')).toStrictEqual('production')
55
})
66

77
test('checks an input an finds that it is valid with true/false strings', async () => {
8-
expect(await checkInput('true')).toStrictEqual('true')
8+
expect(checkInput('true')).toStrictEqual('true')
99

10-
expect(await checkInput('false')).toStrictEqual('false')
10+
expect(checkInput('false')).toStrictEqual('false')
1111
})
1212

1313
test('checks an empty string input an finds that it is invalid', async () => {
14-
expect(await checkInput('')).toStrictEqual(null)
14+
expect(checkInput('')).toStrictEqual(null)
1515
})
1616

1717
test('checks a null object input an finds that it is invalid', async () => {
18-
expect(await checkInput(null)).toStrictEqual(null)
18+
expect(checkInput(null)).toStrictEqual(null)
1919
})
2020

2121
test('checks a string of null input an finds that it is invalid', async () => {
22-
expect(await checkInput('null')).toStrictEqual(null)
22+
expect(checkInput('null')).toStrictEqual(null)
2323
})

__tests__/functions/label.test.js

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import {label} from '../../src/functions/label'
2+
import * as core from '@actions/core'
3+
4+
var context
5+
var octokit
6+
beforeEach(() => {
7+
jest.spyOn(core, 'info').mockImplementation(() => {})
8+
jest.spyOn(core, 'debug').mockImplementation(() => {})
9+
jest.clearAllMocks()
10+
11+
context = {
12+
repo: {
13+
owner: 'corp',
14+
repo: 'test'
15+
},
16+
issue: {
17+
number: 1
18+
}
19+
}
20+
21+
octokit = {
22+
rest: {
23+
issues: {
24+
addLabels: jest.fn().mockReturnValueOnce({
25+
data: {}
26+
}),
27+
removeLabel: jest.fn().mockReturnValueOnce({
28+
data: {}
29+
}),
30+
listLabelsOnIssue: jest.fn().mockReturnValueOnce({
31+
data: [
32+
{
33+
name: 'deploy-failed'
34+
},
35+
{
36+
name: 'noop'
37+
}
38+
]
39+
})
40+
}
41+
}
42+
}
43+
})
44+
45+
test('adds a single label to a pull request and removes none', async () => {
46+
expect(await label(context, octokit, ['read-for-review'], [])).toStrictEqual({
47+
added: ['read-for-review'],
48+
removed: []
49+
})
50+
})
51+
52+
test('adds two labels to a pull request and removes none', async () => {
53+
expect(
54+
await label(context, octokit, ['read-for-review', 'cool-label'], [])
55+
).toStrictEqual({
56+
added: ['read-for-review', 'cool-label'],
57+
removed: []
58+
})
59+
})
60+
61+
test('does not add or remove any labels', async () => {
62+
expect(await label(context, octokit, [], [])).toStrictEqual({
63+
added: [],
64+
removed: []
65+
})
66+
})
67+
68+
test('adds a single label to a pull request and removes a single label', async () => {
69+
expect(
70+
await label(context, octokit, ['deploy-success'], ['deploy-failed'])
71+
).toStrictEqual({
72+
added: ['deploy-success'],
73+
removed: ['deploy-failed']
74+
})
75+
})
76+
77+
test('adds two labels to a pull request and removes two labels', async () => {
78+
expect(
79+
await label(
80+
context,
81+
octokit,
82+
['deploy-success', 'read-for-review'],
83+
['deploy-failed', 'noop']
84+
)
85+
).toStrictEqual({
86+
added: ['deploy-success', 'read-for-review'],
87+
removed: ['deploy-failed', 'noop']
88+
})
89+
})
90+
91+
test('does not add any labels and removes a single label', async () => {
92+
expect(await label(context, octokit, [], ['noop'])).toStrictEqual({
93+
added: [],
94+
removed: ['noop']
95+
})
96+
})

__tests__/functions/post-deploy-message.test.js

+17-6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ var environment_url_simple
1111
var status
1212
var noop
1313
var ref
14+
var approved_reviews_count
1415

1516
beforeEach(() => {
1617
jest.clearAllMocks()
@@ -27,6 +28,7 @@ beforeEach(() => {
2728
status = 'success'
2829
noop = false
2930
ref = 'test-ref'
31+
approved_reviews_count = '4'
3032

3133
context = {
3234
actor: 'monalisa',
@@ -52,7 +54,8 @@ test('successfully constructs a post deploy message with the defaults', async ()
5254
environment_url, // environment_url
5355
status, // status
5456
noop, // noop
55-
ref // ref
57+
ref, // ref
58+
approved_reviews_count // approved_reviews_count
5659
)
5760
).toStrictEqual(
5861
dedent(`
@@ -72,7 +75,8 @@ test('successfully constructs a post deploy message with the defaults during a "
7275
environment_url, // environment_url
7376
status, // status
7477
true, // noop
75-
ref // ref
78+
ref, // ref
79+
approved_reviews_count // approved_reviews_count
7680
)
7781
).toStrictEqual(
7882
dedent(`
@@ -90,7 +94,8 @@ test('successfully constructs a post deploy message with the defaults during a d
9094
environment_url, // environment_url
9195
'failure', // status
9296
noop, // noop
93-
ref // ref
97+
ref, // ref
98+
approved_reviews_count // approved_reviews_count
9499
)
95100
).toStrictEqual(
96101
dedent(`
@@ -108,7 +113,8 @@ test('successfully constructs a post deploy message with the defaults during a d
108113
environment_url, // environment_url
109114
'unknown', // status
110115
noop, // noop
111-
ref // ref
116+
ref, // ref
117+
approved_reviews_count // approved_reviews_count
112118
)
113119
).toStrictEqual(
114120
dedent(`
@@ -128,7 +134,8 @@ test('successfully constructs a post deploy message with a custom env var', asyn
128134
environment_url, // environment_url
129135
status, // status
130136
noop, // noop
131-
ref // ref
137+
ref, // ref
138+
approved_reviews_count // approved_reviews_count
132139
)
133140
).toStrictEqual(
134141
dedent(`
@@ -156,7 +163,8 @@ test('successfully constructs a post deploy message with a custom markdown file'
156163
environment_url, // environment_url
157164
status, // status
158165
noop, // noop
159-
ref // ref
166+
ref, // ref
167+
approved_reviews_count // approved_reviews_count
160168
)
161169
).toStrictEqual(
162170
dedent(`### Deployment Results :rocket:
@@ -169,6 +177,7 @@ test('successfully constructs a post deploy message with a custom markdown file'
169177
- \`noop\` - Whether or not the deployment is a noop (Boolean)
170178
- \`ref\` - The ref of the deployment (String)
171179
- \`actor\` - The GitHub username of the actor who triggered the deployment (String)
180+
- \`approved_reviews_count\` - The number of approved reviews on the pull request at the time of deployment (String of a number)
172181
173182
Here is an example:
174183
@@ -178,6 +187,8 @@ test('successfully constructs a post deploy message with a custom markdown file'
178187
179188
180189
190+
> This deployment had \`4\` approvals.
191+
181192
`)
182193
)
183194
})

0 commit comments

Comments
 (0)