Skip to content

File Based Post Deploy Messages #174

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

Merged
merged 37 commits into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
8df80c5
add 'tmp' input
GrantBirki Jul 27, 2023
74539ea
testing tmp path with a custom deploy message
GrantBirki Jul 27, 2023
7cdd52f
add deploy_message_filename input option
GrantBirki Jul 27, 2023
3ebf2e1
update tmp path
GrantBirki Jul 27, 2023
64c34c9
remove runner.temp
GrantBirki Jul 27, 2023
3825f9b
check if file path exists with existsSync
GrantBirki Jul 27, 2023
060029d
remove 'tmp' input from main.js
GrantBirki Jul 27, 2023
2bfeb3e
dont need to call .trim()
GrantBirki Jul 27, 2023
6fe0845
add 'checkInput' helper function
GrantBirki Jul 27, 2023
9e0fcd0
improve 'post.js'
GrantBirki Jul 27, 2023
ca2b0f9
add check-input tests
GrantBirki Jul 27, 2023
e4c38f4
text updates
GrantBirki Jul 27, 2023
45d4ee1
environment_url is parsed with checkInput() now
GrantBirki Jul 27, 2023
be82d59
add post test coverage
GrantBirki Jul 27, 2023
16905ee
moving post deploy comment logic to its own file
GrantBirki Jul 27, 2023
cf6262c
create post deploy comment file
GrantBirki Jul 27, 2023
e8800ce
cleanup
GrantBirki Jul 27, 2023
fb5d7d6
add vars and format
GrantBirki Jul 27, 2023
8267de6
update docstring
GrantBirki Jul 27, 2023
1052e2e
add logic to check for the custom deploy message file
GrantBirki Jul 27, 2023
e9f645f
dedent() formatting
GrantBirki Jul 27, 2023
c6377c4
adding post deploy tests
GrantBirki Jul 27, 2023
cadf4a5
add custom env var test
GrantBirki Jul 27, 2023
7e8763e
bundle
GrantBirki Jul 27, 2023
6fccca3
add deployment failure comment test
GrantBirki Jul 27, 2023
ec40030
deployment with an unknown status test
GrantBirki Jul 27, 2023
e7d6ca2
defaults during a "noop" deploy test
GrantBirki Jul 27, 2023
661eb10
remove tmp and rename to deploy_message_path
GrantBirki Jul 27, 2023
05098ab
add nunjucks package
GrantBirki Jul 27, 2023
dd84c4b
custom markdown file test
GrantBirki Jul 27, 2023
0ade492
100% test coverage
GrantBirki Jul 27, 2023
44c6add
lint and bundle
GrantBirki Jul 27, 2023
5299a73
noop state in post should be a Boolean
GrantBirki Jul 27, 2023
178f29d
make the unit test self documenting
GrantBirki Jul 27, 2023
766d6fa
bundle
GrantBirki Jul 27, 2023
799ce91
add input vars to postDeployMessage()
GrantBirki Jul 27, 2023
6862baa
add 'noop' to tests
GrantBirki Jul 27, 2023
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ As seen above, we have two steps. One for a noop deploy, and one for a regular d
| `merge_deploy_mode` | `false` | `"false"` | Advanced configuration option for operations on merge commits. See the [merge commit docs](#merge-commit-workflow-strategy) below |
| `unlock_on_merge_mode` | `false` | `"false"` | Advanced configuration option for automatically releasing locks associated with a pull request when that pull request is merged. See the [unlock on merge mode](docs/unlock-on-merge.md) documentation for more details |
| `skip_completing` | `false` | `"false"` | If set to "true", skip the process of completing a deployment. You must manually create a deployment status after the deployment is complete. Default is "false" |
| `deploy_message_path` | `false` | `".github/deployment_message.md"` | The path to a markdown file which is used as a template for custom deployment messages. Example: `".github/deployment_message.md"` |

## Outputs 📤

Expand Down
23 changes: 23 additions & 0 deletions __tests__/functions/check-input.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {checkInput} from '../../src/functions/check-input'

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

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

expect(await checkInput('false')).toStrictEqual('false')
})

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

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

test('checks a string of null input an finds that it is invalid', async () => {
expect(await checkInput('null')).toStrictEqual(null)
})
183 changes: 183 additions & 0 deletions __tests__/functions/post-deploy-message.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
import {postDeployMessage} from '../../src/functions/post-deploy-message'
import * as core from '@actions/core'
import dedent from 'dedent-js'

// const debugMock = jest.spyOn(core, 'debug')

var context
var environment
var environment_url
var environment_url_simple
var status
var noop
var ref

beforeEach(() => {
jest.clearAllMocks()
jest.spyOn(core, 'info').mockImplementation(() => {})
jest.spyOn(core, 'debug').mockImplementation(() => {})

process.env.DEPLOY_MESSAGE = null
process.env.INPUT_ENVIRONMENT_URL_IN_COMMENT = 'true'
process.env.INPUT_DEPLOY_MESSAGE_PATH = '.github/deployment_message.md'

environment = 'production'
environment_url = 'https://example.com'
environment_url_simple = 'example.com'
status = 'success'
noop = false
ref = 'test-ref'

context = {
actor: 'monalisa',
eventName: 'issue_comment',
workflow: 'test-workflow',
repo: {
owner: 'corp',
repo: 'test'
},
payload: {
comment: {
id: '1'
}
}
}
})

test('successfully constructs a post deploy message with the defaults', async () => {
expect(
await postDeployMessage(
context, // context
environment, // environment
environment_url, // environment_url
status, // status
noop, // noop
ref // ref
)
).toStrictEqual(
dedent(`
### Deployment Results ✅

**${context.actor}** successfully deployed branch \`${ref}\` to **${environment}**

> **Environment URL:** [${environment_url_simple}](${environment_url})`)
)
})

test('successfully constructs a post deploy message with the defaults during a "noop" deploy', async () => {
expect(
await postDeployMessage(
context, // context
environment, // environment
environment_url, // environment_url
status, // status
true, // noop
ref // ref
)
).toStrictEqual(
dedent(`
### Deployment Results ✅

**${context.actor}** successfully **noop** deployed branch \`${ref}\` to **${environment}**`)
)
})

test('successfully constructs a post deploy message with the defaults during a deployment failure', async () => {
expect(
await postDeployMessage(
context, // context
environment, // environment
environment_url, // environment_url
'failure', // status
noop, // noop
ref // ref
)
).toStrictEqual(
dedent(`
### Deployment Results ❌

**${context.actor}** had a failure when deploying branch \`${ref}\` to **${environment}**`)
)
})

test('successfully constructs a post deploy message with the defaults during a deployment with an unknown status', async () => {
expect(
await postDeployMessage(
context, // context
environment, // environment
environment_url, // environment_url
'unknown', // status
noop, // noop
ref // ref
)
).toStrictEqual(
dedent(`
### Deployment Results ⚠️

Warning: deployment status is unknown, please use caution`)
)
})

test('successfully constructs a post deploy message with a custom env var', async () => {
process.env.DEPLOY_MESSAGE = 'Deployed 1 shiny new server'

expect(
await postDeployMessage(
context, // context
environment, // environment
environment_url, // environment_url
status, // status
noop, // noop
ref // ref
)
).toStrictEqual(
dedent(`
### Deployment Results ✅

**${context.actor}** successfully deployed branch \`${ref}\` to **${environment}**

<details><summary>Show Results</summary>

Deployed 1 shiny new server

</details>

> **Environment URL:** [${environment_url_simple}](${environment_url})`)
)
})

test('successfully constructs a post deploy message with a custom markdown file', async () => {
process.env.INPUT_DEPLOY_MESSAGE_PATH =
'__tests__/templates/test_deployment_message.md'
expect(
await postDeployMessage(
context, // context
environment, // environment
environment_url, // environment_url
status, // status
noop, // noop
ref // ref
)
).toStrictEqual(
dedent(`### Deployment Results :rocket:

The following variables are available to use in this template:

- \`environment\` - The name of the environment (String)
- \`environment_url\` - The URL of the environment (String) {Optional}
- \`status\` - The status of the deployment (String) - \`success\`, \`failure\`, or \`unknown\`
- \`noop\` - Whether or not the deployment is a noop (Boolean)
- \`ref\` - The ref of the deployment (String)
- \`actor\` - The GitHub username of the actor who triggered the deployment (String)

Here is an example:

monalisa deployed branch \`test-ref\` to the **production** environment. This deployment was a success :rocket:.

You can view the deployment [here](https://example.com).



`)
)
})
Loading