Skip to content

Commit

Permalink
add commit_verified as a template message variable and include it i…
Browse files Browse the repository at this point in the history
…n post deploy messages
  • Loading branch information
GrantBirki committed Dec 9, 2024
1 parent 97ee0f7 commit cbced8b
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 14 deletions.
9 changes: 7 additions & 2 deletions __tests__/functions/post-deploy-message.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ function renderDeploymentMetadata(data) {
\t\t\t\t },
\t\t\t\t "git": {
\t\t\t\t "branch": "${data.ref}",
\t\t\t\t "commit": "${data.sha}"
\t\t\t\t "commit": "${data.sha}",
\t\t\t\t "verified": ${data.commit_verified}
\t\t\t\t },
\t\t\t\t "context": {
\t\t\t\t "actor": "${data.actor}",
Expand Down Expand Up @@ -130,7 +131,8 @@ beforeEach(() => {
parsed_params: parsed_params,
deployment_end_time: deployment_end_time,
actor: context.actor,
logs: logs
logs: logs,
commit_verified: false
}

deployment_metadata = renderDeploymentMetadata(data)
Expand Down Expand Up @@ -320,6 +322,7 @@ test('successfully constructs a post deploy message with a custom markdown file'
- \`parsed_params\` - The parsed parameters provided in the deploy command (String)
- \`deployment_end_time\` - The end time of the deployment - this value is not _exact_ but it is very close (String)
- \`logs\` - The url to the logs of the deployment (String)
- \`commit_verified\` - Whether or not the commit was verified (Boolean)
Here is an example:
Expand All @@ -339,6 +342,8 @@ test('successfully constructs a post deploy message with a custom markdown file'
Here are the deployment logs: https://github.com/corp/test/actions/runs/12345
The commit was not verified.
You can view the deployment [here](https://example.com).
Expand Down
3 changes: 2 additions & 1 deletion __tests__/functions/post-deploy.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ beforeEach(() => {
parsed_params: JSON.stringify({
config: {db: {host: 'localhost', port: 5432}},
_: ['LOG_LEVEL=debug']
})
}),
commit_verified: false
}
})

Expand Down
3 changes: 3 additions & 0 deletions __tests__/templates/test_deployment_message.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ The following variables are available to use in this template:
- `parsed_params` - The parsed parameters provided in the deploy command (String)
- `deployment_end_time` - The end time of the deployment - this value is not _exact_ but it is very close (String)
- `logs` - The url to the logs of the deployment (String)
- `commit_verified` - Whether or not the commit was verified (Boolean)

Here is an example:

Expand All @@ -35,6 +36,8 @@ The deployment process ended at `{{ deployment_end_time }}`.

Here are the deployment logs: {{ logs }}

{% if commit_verified %}The commit was verified.{% else %}The commit was not verified.{% endif %}

{% if environment_url %}You can view the deployment [here]({{ environment_url }}).{% endif %}

{% if noop %}This was a noop deployment.{% endif %}
Expand Down
17 changes: 12 additions & 5 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions src/functions/post-deploy-message.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import nunjucks from 'nunjucks'
// - attribute: params: The raw string of deployment parameters (String)
// - attribute: parsed_params: A string representation of the parsed deployment parameters (String)
// - attribute: deployment_end_time: The time the deployment ended - this value is not _exact_ but it is very close (String)
// - attribute: commit_verified: Indicates whether the commit is verified or not (Boolean)
// :returns: The formatted message (String)
export async function postDeployMessage(context, data) {
// fetch the inputs
Expand All @@ -45,7 +46,8 @@ export async function postDeployMessage(context, data) {
parsed_params: data.parsed_params || null,
deployment_end_time: data.deployment_end_time,
actor: context.actor,
logs: `${process.env.GITHUB_SERVER_URL}/${context.repo.owner}/${context.repo.repo}/actions/runs/${process.env.GITHUB_RUN_ID}`
logs: `${process.env.GITHUB_SERVER_URL}/${context.repo.owner}/${context.repo.repo}/actions/runs/${process.env.GITHUB_RUN_ID}`,
commit_verified: data.commit_verified
}

// this is kinda gross but wrangling dedent() and nunjucks is a pain
Expand All @@ -68,7 +70,8 @@ export async function postDeployMessage(context, data) {
\t\t\t\t },
\t\t\t\t "git": {
\t\t\t\t "branch": "${vars.ref}",
\t\t\t\t "commit": "${vars.sha}"
\t\t\t\t "commit": "${vars.sha}",
\t\t\t\t "verified": ${vars.commit_verified}
\t\t\t\t },
\t\t\t\t "context": {
\t\t\t\t "actor": "${vars.actor}",
Expand Down
7 changes: 5 additions & 2 deletions src/functions/post-deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const nonStickyMsg = `🧹 ${COLORS.highlight}non-sticky${COLORS.reset} lock det
// - attribute: fork: Indicates whether the deployment is from a forked repository (Boolean)
// - attribute: params: The raw string of deployment parameters (String)
// - attribute: parsed_params: A string representation of the parsed deployment parameters (String)
// - attribute: commit_verified: Indicates whether the commit is verified or not (Boolean)
// :returns: 'success' if the deployment was successful, 'success - noop' if a noop, throw error otherwise
export async function postDeploy(context, octokit, data) {
// check the inputs to ensure they are valid
Expand Down Expand Up @@ -62,7 +63,8 @@ export async function postDeploy(context, octokit, data) {
fork: data.fork,
params: data.params,
parsed_params: data.parsed_params,
deployment_end_time: deployment_end_time
deployment_end_time: deployment_end_time,
commit_verified: data.commit_verified
})

// update the action status to indicate the result of the deployment as a comment
Expand Down Expand Up @@ -236,7 +238,8 @@ function validateInputs(data) {
'ref',
'environment',
'reaction_id',
'sha'
'sha',
'commit_verified'
]
requiredInputs.forEach(input => validateInput(data[input], input))

Expand Down
3 changes: 2 additions & 1 deletion src/functions/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ export async function post() {
skip_successful_deploy_labels_if_approved: core.getBooleanInput(
'skip_successful_deploy_labels_if_approved'
)
}
},
commit_verified: core.getState('commit_verified') === 'true'
}

core.info(`🧑‍🚀 commit SHA: ${COLORS.highlight}${data.sha}${COLORS.reset}`)
Expand Down

0 comments on commit cbced8b

Please sign in to comment.