Skip to content

Commit 44c64cf

Browse files
committed
feat: comment on pull requests with the next version of the software, if it deploys
commit-id:08b4d420
1 parent 7bf3ef4 commit 44c64cf

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ jobs:
4545
if: github.event_name == 'pull_request' # Only run on PRs, otherwise we will trigger a deployment by accident.
4646
permissions:
4747
contents: read # only offer read permissions for dry-run to prevent accidental deployments
48+
pull-requests: write # allow commenting on PRs
4849
steps:
4950
- uses: actions/checkout@v4
5051
- name: Run deployment tool in dry-run mode

action.yml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ inputs:
1818
simulated_merge_type:
1919
description: 'When running in a pull request, what type of merge to simulate to run the tool in test mode. Note: This input option is planned to go away in favor of reading github repo settings. Options: merge, squash, rebase.'
2020
default: 'merge' # options: merge, squash, rebase
21+
pull_request_comment_body:
22+
description: 'The comment body to use when creating a pull request comment. This content is in markdown and can contain some variables. See: https://github.com/peter-evans/create-or-update-comment?tab=readme-ov-file#using-a-markdown-template'
23+
default: ''
24+
make_pull_request_comment:
25+
description: 'If a pull request comment should be made. Value is string values "true" or "false".'
26+
default: 'true'
2127

2228
outputs:
2329
new_release_version:
@@ -39,6 +45,28 @@ runs:
3945
run: git fetch
4046
shell: bash
4147

48+
- name: Find pull request comment previously created, if there is one.
49+
if: ${{ github.event_name == 'pull_request' }}
50+
uses: peter-evans/find-comment@v3
51+
id: find-comment
52+
with:
53+
issue-number: ${{ github.event.pull_request.number }}
54+
comment-author: 'github-actions[bot]'
55+
body-includes: '<!-- new-deployment-tool-deploy-run-output -->'
56+
token: ${{ inputs.github_token }}
57+
58+
- name: Create or update pull request comment with new deployment tool output
59+
uses: peter-evans/create-or-update-comment@v4
60+
if: ${{ github.event_name == 'pull_request' && inputs.make_pull_request_comment == 'true' }}
61+
with:
62+
comment-id: ${{ steps.find-comment.outputs.comment-id }}
63+
issue-number: ${{ github.event.pull_request.number }}
64+
body: |
65+
<!-- new-deployment-tool-deploy-run-output -->
66+
## New deployment tool results
67+
Running deployment...refresh webpage to see results when done.
68+
edit-mode: replace
69+
4270
- name: Run deployment tool
4371
# Deno's runtime permissions are a great feature. It would be nice to take advantage of it, however, it may not be possible with future features like running plugins.
4472
#
@@ -50,3 +78,40 @@ runs:
5078
INPUT_GITHUB_TOKEN: ${{ inputs.github_token }}
5179
INPUT_DEPLOY_COMMANDS: ${{ inputs.deploy_commands }}
5280
INPUT_ANALYZE_COMMITS_CONFIG: ${{ inputs.analyze_commits_config }}
81+
82+
- name: Pull request comment if the deployment failed
83+
uses: peter-evans/create-or-update-comment@v4
84+
if: ${{ inputs.make_pull_request_comment == 'true' && steps.deployment.outputs.test_mode_on == 'true' && steps.deployment.outcome != 'success' }}
85+
with:
86+
comment-id: ${{ steps.find-comment.outputs.comment-id }}
87+
issue-number: ${{ github.event.pull_request.number }}
88+
body: |
89+
<!-- new-deployment-tool-deploy-run-output -->
90+
## New deployment tool results
91+
There was a failure when running the deployment. Check [the logs](https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}) to see what went wrong.
92+
edit-mode: replace
93+
94+
- name: Pull request comment if there will be a release
95+
uses: peter-evans/create-or-update-comment@v4
96+
if: ${{ inputs.make_pull_request_comment == 'true' && steps.deployment.outputs.test_mode_on == 'true' && steps.deployment.outcome == 'success' && steps.deployment.outputs.new_release_version != '' }}
97+
with:
98+
comment-id: ${{ steps.find-comment.outputs.comment-id }}
99+
issue-number: ${{ github.event.pull_request.number }}
100+
body: |
101+
<!-- new-deployment-tool-deploy-run-output -->
102+
## New deployment tool results
103+
If this pull request is merged, the next version of the project will be: ${{ steps.deployment.outputs.new_release_version }}
104+
edit-mode: replace
105+
106+
- name: Pull request comment if there will not be a release
107+
uses: peter-evans/create-or-update-comment@v4
108+
if: ${{ inputs.make_pull_request_comment == 'true' && steps.deployment.outputs.test_mode_on == 'true' && steps.deployment.outcome == 'success' && steps.deployment.outputs.new_release_version == '' }}
109+
with:
110+
comment-id: ${{ steps.find-comment.outputs.comment-id }}
111+
issue-number: ${{ github.event.pull_request.number }}
112+
body: |
113+
<!-- new-deployment-tool-deploy-run-output -->
114+
## New deployment tool results
115+
If this pull request is merged, there will not be a new release.
116+
edit-mode: replace
117+

0 commit comments

Comments
 (0)