Skip to content

Commit fd88c77

Browse files
korenyonigoruha
andauthored
feat: add pr-comment-on-release functionality. (#1)
* Initial commit * Add contents from composite-template. * Add pr-comment-on-release functionality. * Rebuild docs. * Fix hardcoded retries value. * Drop draft-release.yml in order to fall back to config used by cloudposse-github-actions/.github/.github/workflows/shared-release-branches.yml@main. * Add ability to filter for releases. * Add positive test. * Fix tag name. * Fix release creation. * Fix release name (SHA too long?). * Attempt to satisfy name restrictions. * Conform to semver spec for release name. * Attempt to make gh release create command non-interactive. * Update tag pattern. * fix: fix tests. * fix: fix release names in order to conform to organizational tag rulesets. * fix: checkout repo in order to use gh cli. * fix: fix test-release.yml. * fix: fix test-release.yml; update startsWith search token to be more precise (even though it's currently working). * fix conditional release workflow logic. * test: add debug step. * fix: update trigger for test-release.yml; update gh cli flags for test-include, test-exclude workflows. * fix: revert change to test-release.yml trigger (not necessary, needs to be moved to different PR to get it into the main branch). * fix: allow test suite to run via PR workflow. * fix: handle warnings and errors using the javascript toolkit for GHA. * Remove invalid and unnecessary error handling for release_id being missing when event is pull_request. * fix var name for releaseID. * fix reference to releaseID. * Add additional log and remove unused var. * debug: add additional logs. * Remove nonexistant core.log with console.log. * Attempt to pass in value. * Set inputs using process.env. * fix variable name. * fix location of env block. * fix reference to INPUT_RELEASE_ID. * fix templating in log. * fix: fix value of release_id being passed to action.yml * fix release id output from create-release job. * switch to tag for pull requests. * remove old reference to INPUT_RELEASE_NAME. * fix var initiliazation. * Add additional logs. * fix: fix syntax. * Make logging more verbose regarding tag. * Fix input cases and messages. * fix switch cases. * fix conditionals on TAG. * Remove old reference to currentReleaseResponse. * fix tag variable passed to getReleaseByTag. * fix: fix case switches and release response assignment. * refactor * fix filter call. * fix filter call on releases. * fix match call. * Add INCLUDE_REGEX input via process.env; add debug log. * fix filter and include_regex description. * fix filter function call. * fix syntax. * Move debug logs around. * Add debug log to filter function. * fix include_regex. * Fix regex escaping. * expand debug log. * fix: fix regexp. * fix syntax. * fix syntax. * test: remove some debug logs. * Add debug log. * add debug log. * fix log line. * fix debug log line. * fix syntax. * fix name of release (in some prereleases name is not present, but tag_name is). * fix teardown. * fix: use correct output in teardown. * fix: use checkout in teardown before calling gh cli. * fix: also delete the tag in teardown. * fix: delete comment in teardown. * fix reference to repo name and owner. * fix step and job outcomes. * fix conditional expressions. * fix: fix regex. * fix: fix regex. * fix: use body-includes instead of body-regex. * fix: templating syntax. * fix: secret input. * fix: permissions * fix: permissions. * fix: repo owner. * fix: repo owner name. * fix: owner name. * fix: owner name. * fix: fix repo owner (fallback to hardcoding). * fix: use correct endpoint for deleting non-PR-review comments. * fix: fix main branch and feature branch workflows (remove now unused-secret); update settings.yml. * fix: change tests to workflow_dispatch so they can be triggered by feature-branch.yaml. * fix: fix supported events. * fix: fix permissions. * fix: add additional permission scope to allow for called reusable workflow. * fix tests in workflow_dispatch context. * fix: fix owner and repo. * debug: add debug logs. * test: add debug logs. * fix debug log. * fix logic. * fix logic. * fix syntax. * fix action logic and flow. * fix uninstantiated var use. * fix: instantiate missing vars. * fix currentReleaseFound logic when there are two releases pointing to the same commit SHA. * fix var reference and add inline comment on code quality. * fix: add return object. * fix result encoding; fix returns; expand description. * test: add debug log. * fix return output. * fix output and simplify assertion and teardown. * fix action outputs. * fix reference to action outputs. * Add debug output in test workflow. * Set outputs in the composite action definition. * fix: do not run fromJSON() as outputs are already decoded. * fix output * fix output * fix output. * test: debug outputs * fix: decode json. * fix output. * fix output * fix output * fix output when noop. * simplify positive test case; update readme and run 'make readme'. * reorder negative test case steps. * fix: fix continue-on-error placement. * chore: add mergify config. --------- Co-authored-by: Igor Rodionov <[email protected]>
1 parent e56993d commit fd88c77

File tree

16 files changed

+1086
-1
lines changed

16 files changed

+1086
-1
lines changed

.github/mergify.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
extends: .github

.github/settings.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
_extends: .github
2+
repository:
3+
# A URL with more information about the repository
4+
homepage: https://cloudposse.com
5+
# Either `true` to enable projects for this repository, or `false` to disable them.
6+
# If projects are disabled for the organization, passing `true` will cause an API error.
7+
has_projects: false
8+
# Either `true` to enable the wiki for this repository, `false` to disable it.
9+
has_wiki: false
10+
name: pr-comment-on-release
11+
description: "An action that comments on PRs when their changes have been released."
12+
topics: "github-actions,pull-requests,releases"

.github/workflows/auto-readme.yml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: "auto-readme"
2+
on:
3+
workflow_dispatch: {}
4+
5+
## Added pull_request to register workflow from the PR.
6+
## Read more https://stackoverflow.com/questions/63362126/github-actions-how-to-run-a-workflow-created-on-a-non-master-branch-from-the-wo
7+
pull_request:
8+
branches-ignore: ['*']
9+
10+
schedule:
11+
# Example of job definition:
12+
# .---------------- minute (0 - 59)
13+
# | .------------- hour (0 - 23)
14+
# | | .---------- day of month (1 - 31)
15+
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
16+
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
17+
# | | | | |
18+
# * * * * * user-name command to be executed
19+
20+
# Update README.md nightly at 4am UTC
21+
- cron: '0 4 * * *'
22+
23+
jobs:
24+
update:
25+
runs-on: ubuntu-latest
26+
steps:
27+
- uses: actions/checkout@v3
28+
29+
- name: Find default branch name
30+
id: defaultBranch
31+
shell: bash
32+
env:
33+
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
34+
run: |
35+
default_branch=$(gh repo view --json defaultBranchRef --jq .defaultBranchRef.name)
36+
printf "::set-output name=defaultBranch::%s\n" "${default_branch}"
37+
printf "defaultBranchRef.name=%s\n" "${default_branch}"
38+
39+
- name: Update readme
40+
shell: bash
41+
id: update
42+
env:
43+
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
44+
DEF: "${{ steps.defaultBranch.outputs.defaultBranch }}"
45+
run: |
46+
make init
47+
make readme/build
48+
# Ignore changes if they are only whitespace
49+
if ! git diff --quiet README.md && git diff --ignore-all-space --ignore-blank-lines --quiet README.md; then
50+
git restore README.md
51+
echo Ignoring whitespace-only changes in README
52+
fi
53+
54+
- name: Create Pull Request
55+
# This action will not create or change a pull request if there are no changes to make.
56+
# If a PR of the auto-update/readme branch is open, this action will just update it, not create a new PR.
57+
uses: cloudposse/actions/github/[email protected]
58+
with:
59+
token: ${{ secrets.PUBLIC_REPO_ACCESS_TOKEN }}
60+
commit-message: Update README.md and docs
61+
title: Update README.md and docs
62+
body: |-
63+
## what
64+
This is an auto-generated PR that updates the README.md and docs
65+
66+
## why
67+
To have most recent changes of README.md and doc from origin templates
68+
69+
branch: auto-update/readme
70+
base: ${{ steps.defaultBranch.outputs.defaultBranch }}
71+
delete-branch: true
72+
labels: |
73+
auto-update
74+
no-release
75+
readme
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Feature branch
2+
on:
3+
pull_request:
4+
branches: [main]
5+
types: [opened, synchronize, reopened]
6+
7+
permissions:
8+
contents: write
9+
pull-requests: write
10+
actions: write
11+
12+
jobs:
13+
perform:
14+
uses: cloudposse/github-actions-workflows-github-action-composite/.github/workflows/feature-branch.yml@main
15+
with:
16+
organization: "${{ github.event.repository.owner.login }}"
17+
repository: "${{ github.event.repository.name }}"
18+
ref: "${{ github.event.pull_request.head.ref }}"

.github/workflows/main-branch.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Main branch
2+
on:
3+
push:
4+
branches: [main]
5+
6+
permissions:
7+
contents: write
8+
pull-requests: write
9+
actions: write
10+
11+
jobs:
12+
perform:
13+
uses: cloudposse/github-actions-workflows-github-action-composite/.github/workflows/main-branch.yml@main
14+
with:
15+
organization: "${{ github.event.repository.owner.login }}"
16+
repository: "${{ github.event.repository.name }}"

.github/workflows/release.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: Release
2+
on:
3+
release:
4+
types: [published]
5+
6+
permissions:
7+
id-token: write
8+
contents: write
9+
pull-requests: write
10+
11+
jobs:
12+
github-action:
13+
if: "!startsWith(github.event.release.name, 'v0.0.0-test.')" # Do not run for test releases created by test-include.yml and test-exclude.yml
14+
uses: cloudposse-github-actions/.github/.github/workflows/shared-release-branches.yml@main
15+
secrets: inherit
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
name: Test Negative
2+
on:
3+
workflow_dispatch: {}
4+
5+
permissions:
6+
contents: write
7+
pull-requests: write
8+
9+
jobs:
10+
setup:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Setup
14+
run: echo "Do setup"
15+
16+
create-release:
17+
runs-on: ubuntu-latest
18+
continue-on-error: true
19+
needs: [setup]
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@v3
23+
24+
- id: create-release
25+
run: |
26+
release_name="${PREFIX}$(git rev-parse --short HEAD)"
27+
gh release create ${release_name} --prerelease --target ${{ github.sha }} --notes "Created by ${{ github.workflow }} (will be automatically deleted)."
28+
echo "name=${release_name}" > $GITHUB_OUTPUT
29+
echo "tag=$(gh release view ${release_name} --json tagName -q '.tagName')" >> $GITHUB_OUTPUT
30+
env:
31+
# Below is the main difference between this workflow's positive counterpart.
32+
# The action will not pick up a comment because the provided 'include_regex' will not be able to match it.
33+
PREFIX: "v0.0.0-test.exclude."
34+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
35+
36+
outputs:
37+
name: ${{ steps.create-release.outputs.name }}
38+
tag: ${{ steps.create-release.outputs.tag }}
39+
40+
assert:
41+
runs-on: ubuntu-latest
42+
needs: [create-release]
43+
outputs:
44+
comment-id: ${{ steps.fc.outputs.comment-id }}
45+
steps:
46+
- uses: actions/checkout@v4
47+
48+
- uses: ./
49+
id: action
50+
with:
51+
tag: ${{ needs.create-release.outputs.tag }}
52+
include_regex: 'v0\.0\.0-test\.include\..*' # Should NOT find a comment
53+
54+
- name: debug
55+
run: |
56+
echo "${{ fromJSON(steps.action.outputs.result) }}"
57+
58+
- name: Find Comment
59+
uses: peter-evans/find-comment@v3
60+
id: fc
61+
continue-on-error: true
62+
with:
63+
issue-number: ${{ fromJSON(steps.action.outputs.result).comments[0].pull_request }}
64+
body-includes: ${{ needs.create-release.outputs.tag }}
65+
66+
- name: Fail if comment was found
67+
if: ${{ always() && steps.fc.outputs.comment-id != 0 }}
68+
run: |
69+
exit 1
70+
71+
- name: Succeed if comment was not found
72+
if: ${{ always() && steps.fc.outputs.comment-id == 0 }}
73+
run: |
74+
exit 0
75+
76+
teardown:
77+
runs-on: ubuntu-latest
78+
needs: [create-release, assert]
79+
if: ${{ always() }}
80+
steps:
81+
- name: Checkout
82+
uses: actions/checkout@v3
83+
84+
- name: Delete Test Release + Tag
85+
if: needs.create-release.result == 'success'
86+
run: gh release delete ${{ needs.create-release.outputs.name }} --cleanup-tag
87+
env:
88+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
89+
90+
- uses: octokit/[email protected]
91+
name: Delete Test Release Comment
92+
if: ${{ always() && needs.assert.outputs.comment-id != 0 }}
93+
with:
94+
route: DELETE /repos/{owner}/{repo}/issues/comments/{comment_id}
95+
owner: "${{ github.event.repository.owner.login }}"
96+
repo: "${{ github.event.repository.name }}"
97+
comment_id: ${{ needs.assert.outputs.comment-id }}
98+
env:
99+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
name: Test Positive
2+
on:
3+
workflow_dispatch: {}
4+
5+
permissions:
6+
contents: write
7+
pull-requests: write
8+
9+
jobs:
10+
setup:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Setup
14+
run: echo "Do setup"
15+
16+
create-release:
17+
runs-on: ubuntu-latest
18+
continue-on-error: true
19+
needs: [setup]
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@v3
23+
24+
- id: create-release
25+
run: |
26+
release_name="${PREFIX}$(git rev-parse --short HEAD)"
27+
gh release create ${release_name} --prerelease --target ${{ github.sha }} --notes "Created by ${{ github.workflow }} (will be automatically deleted)."
28+
echo "name=${release_name}" > $GITHUB_OUTPUT
29+
echo "tag=$(gh release view ${release_name} --json tagName -q '.tagName')" >> $GITHUB_OUTPUT
30+
env:
31+
# Below is the main difference between this workflow's negative counterpart.
32+
# The action _will_ pick up a comment because the provided 'include_regex' will be able to match it.
33+
PREFIX: "v0.0.0-test.include."
34+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
35+
36+
outputs:
37+
name: ${{ steps.create-release.outputs.name }}
38+
tag: ${{ steps.create-release.outputs.tag }}
39+
40+
assert:
41+
runs-on: ubuntu-latest
42+
needs: [create-release]
43+
outputs:
44+
comment-id: ${{ steps.fc.outputs.comment-id }}
45+
steps:
46+
- uses: actions/checkout@v4
47+
48+
- uses: ./
49+
id: action
50+
with:
51+
tag: ${{ needs.create-release.outputs.tag }}
52+
include_regex: 'v0\.0\.0-test\.include\..*' # Should find a comment
53+
54+
- name: debug
55+
run: |
56+
echo "${{ fromJSON(steps.action.outputs.result) }}"
57+
58+
- name: Find Comment
59+
uses: peter-evans/find-comment@v3
60+
id: fc
61+
with:
62+
issue-number: ${{ fromJSON(steps.action.outputs.result).comments[0].pull_request }}
63+
body-includes: ${{ needs.create-release.outputs.tag }}
64+
65+
teardown:
66+
runs-on: ubuntu-latest
67+
needs: [create-release, assert]
68+
if: ${{ always() }}
69+
steps:
70+
- name: Checkout
71+
uses: actions/checkout@v3
72+
73+
- name: Delete Test Release + Tag
74+
if: needs.create-release.result == 'success'
75+
run: gh release delete ${{ needs.create-release.outputs.name }} --cleanup-tag
76+
env:
77+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
78+
79+
- uses: octokit/[email protected]
80+
name: Delete Test Release Comment
81+
if: ${{ always() && needs.assert.outputs.comment-id != 0 }}
82+
with:
83+
route: DELETE /repos/{owner}/{repo}/issues/comments/{comment_id}
84+
owner: "${{ github.event.repository.owner.login }}"
85+
repo: "${{ github.event.repository.name }}"
86+
comment_id: ${{ needs.assert.outputs.comment-id }}
87+
env:
88+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.build-harness
2+
build-harness

0 commit comments

Comments
 (0)