Skip to content

Commit 3ed6122

Browse files
authored
feat(cleanup)!: replace update-pr-comment with delete-pr-comment (#6)
BREAKING CHANGE: The cleanup action now deletes PR comments instead of updating them with strikethrough text. - Rename `update-pr-comment` input to `delete-pr-comment` - Rename `pr-comment-updated` output to `pr-comment-deleted` - Change default from `false` to `true` (enabled by default) - Simplify implementation: delete comment instead of PATCH update Users upgrading from v1 should replace: update-pr-comment: true → delete-pr-comment: true The new default (true) means PR comments are deleted automatically when cleanup runs, matching the behavior of pr-preview-action.
1 parent 56ae5cc commit 3ed6122

3 files changed

Lines changed: 55 additions & 67 deletions

File tree

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
5252
- Automatically post/update a comment on PRs with the deployment URL
5353
- New inputs: `comment-on-pr`, `github-token`, `comment-header`
5454
- Upsert behavior: updates existing comment instead of creating duplicates
55+
- **cleanup** action: PR comment delete feature
56+
- Delete the deploy PR comment when PR is closed (default: enabled)
57+
- New inputs: `delete-pr-comment`, `comment-header`
58+
- New output: `pr-comment-deleted`
59+
5560
- CI/CD pipeline with ShellCheck, actionlint, and yamllint
5661
- Branch protection and governance files (CODEOWNERS, issue templates, PR template)
5762
- CONTRIBUTING.md with development guidelines
@@ -63,6 +68,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6368
- No longer necessary to explicitly pass `github-token: ${{ secrets.GITHUB_TOKEN }}`
6469
- Only needed when using a custom PAT for cross-repository operations
6570

71+
### Removed
72+
- **BREAKING** `cleanup` action: `update-pr-comment` input (use `delete-pr-comment` instead)
73+
- **BREAKING** `cleanup` action: `pr-comment-updated` output (use `pr-comment-deleted` instead)
74+
6675
### Internal
6776
- Added justfile for common development tasks
6877
- Added pre-commit.ci configuration (weekly autoupdates, skip duplicates with CI)

cleanup/README.md

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,18 @@ Removes a ZAD deployment and optionally cleans up associated GitHub resources (e
1818
| `github-token` | No | `github.token` | GitHub token for deployments/containers/PR (defaults to automatic token) |
1919
| `github-admin-token` | No | `''` | GitHub token for environment deletion (needs repo admin permission) |
2020
| `api-base-url` | No | `https://operations-manager.rig.prd1.gn2.quattro.rijksapps.nl/api` | ZAD Operations Manager API base URL |
21-
| `update-pr-comment` | No | `false` | Update the deploy PR comment to show cleanup status |
22-
| `comment-header` | No | `## 🚀 Preview Deployment` | Header of the deploy comment to find and update |
21+
| `delete-pr-comment` | No | `true` | Delete the deploy PR comment |
22+
| `comment-header` | No | `## 🚀 Preview Deployment` | Header of the deploy comment to find and delete |
2323

2424
## Outputs
2525

26-
| Name | Description |
27-
|------|-------------|
28-
| `zad-deleted` | Whether the ZAD deployment was deleted (`true`/`false`) |
29-
| `github-env-deleted` | Whether the GitHub environment was deleted (`true`/`false`) |
30-
| `github-deployments-deleted` | Whether GitHub deployments were deleted (`true`/`false`) |
31-
| `container-deleted` | Whether the container image was deleted (`true`/`false`) |
32-
| `pr-comment-updated` | Whether the PR comment was updated (`true`/`false`) |
26+
| Name | Description |
27+
|------------------------------|----------------------------------------------------------|
28+
| `zad-deleted` | Whether the ZAD deployment was deleted (`true`/`false`) |
29+
| `github-env-deleted` | Whether the GitHub environment was deleted |
30+
| `github-deployments-deleted` | Whether GitHub deployments were deleted |
31+
| `container-deleted` | Whether the container image was deleted |
32+
| `pr-comment-deleted` | Whether the PR comment was deleted |
3333

3434
## Example Usage
3535

@@ -71,7 +71,7 @@ cleanup-preview:
7171
permissions:
7272
deployments: write
7373
packages: write
74-
pull-requests: write # For update-pr-comment
74+
pull-requests: write # For delete-pr-comment
7575
steps:
7676
- name: Cleanup PR preview
7777
uses: RijksICTGilde/zad-actions/cleanup@v1
@@ -86,30 +86,24 @@ cleanup-preview:
8686
container-name: ${{ github.event.repository.name }}
8787
container-tag: pr-${{ github.event.number }}
8888
github-admin-token: ${{ secrets.GITHUB_ADMIN_TOKEN }}
89-
update-pr-comment: true
89+
delete-pr-comment: true
9090
```
9191
92-
### PR Comment Update
92+
### Delete PR Comment
9393
94-
When used with the deploy action's `comment-on-pr` feature, the cleanup action can update the PR comment to show that the deployment was cleaned up:
94+
When used with the deploy action's `comment-on-pr` feature, the cleanup action can remove the PR comment when the deployment is cleaned up:
9595

96-
**Before cleanup:**
97-
> ## 🚀 Preview Deployment
98-
>
99-
> Your changes have been deployed to a preview environment:
100-
>
101-
> **URL:** https://web-pr123-my-project.rig...
102-
>
103-
> This deployment will be automatically cleaned up when the PR is closed.
104-
105-
**After cleanup:**
106-
> ## 🧹 Preview Deployment (Cleaned Up)
107-
>
108-
> ~~https://editor-pr123-my-project.rig...~~
109-
>
110-
> This deployment was automatically cleaned up when the PR was closed.
96+
```yaml
97+
- uses: RijksICTGilde/zad-actions/cleanup@v1
98+
with:
99+
api-key: ${{ secrets.ZAD_API_KEY }}
100+
project-id: my-project
101+
deployment-name: pr${{ github.event.pull_request.number }}
102+
delete-pr-comment: true
103+
github-token: ${{ secrets.GITHUB_TOKEN }}
104+
```
111105

112-
To enable this, add `update-pr-comment: true` to your cleanup step. The action will find the existing deploy comment by its header and update it.
106+
The action finds the deploy comment by its header (`## 🚀 Preview Deployment` by default) and deletes it.
113107

114108
## Permissions
115109

@@ -119,7 +113,7 @@ To enable this, add `update-pr-comment: true` to your cleanup step. The action w
119113
permissions:
120114
deployments: write # For delete-github-deployments
121115
packages: write # For delete-container
122-
pull-requests: write # For update-pr-comment
116+
pull-requests: write # For delete-pr-comment
123117
```
124118

125119
### Token Requirements
@@ -130,7 +124,7 @@ permissions:
130124
| Delete GitHub deployments | `github-token` | `deployments: write` |
131125
| Delete GitHub environment | `github-admin-token` | Repository admin access |
132126
| Delete container image | `github-token` | `packages: delete` |
133-
| Update PR comment | `github-token` | `pull-requests: write` |
127+
| Delete PR comment | `github-token` | `pull-requests: write` |
134128

135129
**Note:** The default `GITHUB_TOKEN` cannot delete GitHub environments. You need a Personal Access Token (PAT) or GitHub App token with admin permissions for the repository.
136130

@@ -212,7 +206,7 @@ Check cleanup results and take action:
212206
2. **Delete GitHub Deployments** (optional): Marks all deployments for the environment as inactive, then deletes them
213207
3. **Delete GitHub Environment** (optional): Deletes the GitHub environment
214208
4. **Delete Container Image** (optional): Finds and deletes the container version with the specified tag
215-
5. **Update PR Comment** (optional): Updates the deploy comment to show cleanup status
209+
5. **Delete PR Comment** (optional): Removes the deploy comment from the PR
216210

217211
Each step runs independently and won't fail the action if it fails (cleanup is best-effort). Check the outputs to see what was actually deleted.
218212

cleanup/action.yml

Lines changed: 20 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ inputs:
5353
description: 'ZAD Operations Manager API base URL'
5454
required: false
5555
default: 'https://operations-manager.rig.prd1.gn2.quattro.rijksapps.nl/api'
56-
update-pr-comment:
57-
description: 'Update the deploy PR comment to show cleanup status (requires github-token with pull-requests:write)'
56+
delete-pr-comment:
57+
description: 'Delete the deploy PR comment (requires github-token with pull-requests:write)'
5858
required: false
59-
default: 'false'
59+
default: 'true'
6060
comment-header:
61-
description: 'Header of the deploy comment to find and update (default: "## 🚀 Preview Deployment")'
61+
description: 'Header of the deploy comment to find and delete (default: "## 🚀 Preview Deployment")'
6262
required: false
6363
default: '## 🚀 Preview Deployment'
6464

@@ -75,9 +75,9 @@ outputs:
7575
container-deleted:
7676
description: 'Whether the container image was deleted'
7777
value: ${{ steps.delete-container.outputs.deleted }}
78-
pr-comment-updated:
79-
description: 'Whether the PR comment was updated'
80-
value: ${{ steps.update-pr-comment.outputs.updated }}
78+
pr-comment-deleted:
79+
description: 'Whether the PR comment was deleted'
80+
value: ${{ steps.delete-pr-comment.outputs.deleted }}
8181

8282
runs:
8383
using: 'composite'
@@ -273,47 +273,32 @@ runs:
273273
274274
echo "deleted=$DELETED" >> "$GITHUB_OUTPUT"
275275
276-
- name: Update PR Comment
277-
id: update-pr-comment
278-
if: inputs.update-pr-comment == 'true' && github.event_name == 'pull_request'
276+
- name: Delete PR Comment
277+
id: delete-pr-comment
278+
if: inputs.delete-pr-comment == 'true' && github.event_name == 'pull_request'
279279
shell: bash
280280
env:
281281
GH_TOKEN: ${{ inputs.github-token }}
282282
COMMENT_HEADER: ${{ inputs.comment-header }}
283283
PR_NUMBER: ${{ github.event.pull_request.number }}
284284
GITHUB_REPOSITORY: ${{ github.repository }}
285-
DEPLOYMENT_NAME: ${{ inputs.deployment-name }}
286-
PROJECT_ID: ${{ inputs.project-id }}
287285
run: |
288-
# Build the updated comment body
289-
COMMENT_BODY="## 🧹 Preview Deployment (Cleaned Up)
290-
291-
~~https://editor-${DEPLOYMENT_NAME}-${PROJECT_ID}.rig.prd1.gn2.quattro.rijksapps.nl~~
292-
293-
This deployment was automatically cleaned up when the PR was closed."
294-
295286
# Find existing comment by header
296-
EXISTING_COMMENT=$(gh api "repos/${GITHUB_REPOSITORY}/issues/${PR_NUMBER}/comments" \
297-
--jq ".[] | select(.body | startswith(\"${COMMENT_HEADER}\")) | {id: .id, body: .body}" \
287+
COMMENT_ID=$(gh api "repos/${GITHUB_REPOSITORY}/issues/${PR_NUMBER}/comments" \
288+
--jq ".[] | select(.body | startswith(\"${COMMENT_HEADER}\")) | .id" \
298289
2>/dev/null | head -n1 || echo "")
299290
300-
if [ -z "$EXISTING_COMMENT" ]; then
291+
if [ -z "$COMMENT_ID" ]; then
301292
echo "No existing deploy comment found with header: ${COMMENT_HEADER}"
302-
echo "updated=false" >> "$GITHUB_OUTPUT"
293+
echo "deleted=false" >> "$GITHUB_OUTPUT"
303294
exit 0
304295
fi
305296
306-
COMMENT_ID=$(echo "$EXISTING_COMMENT" | jq -r '.id')
307-
308-
if [ -n "$COMMENT_ID" ] && [ "$COMMENT_ID" != "null" ]; then
309-
echo "Updating PR comment (ID: $COMMENT_ID)"
310-
gh api "repos/${GITHUB_REPOSITORY}/issues/comments/${COMMENT_ID}" \
311-
-X PATCH \
312-
-f body="$COMMENT_BODY" \
313-
--silent
314-
echo "PR comment updated to show cleanup status"
315-
echo "updated=true" >> "$GITHUB_OUTPUT"
297+
echo "Deleting PR comment (ID: $COMMENT_ID)"
298+
if gh api "repos/${GITHUB_REPOSITORY}/issues/comments/${COMMENT_ID}" -X DELETE 2>/dev/null; then
299+
echo "PR comment deleted successfully"
300+
echo "deleted=true" >> "$GITHUB_OUTPUT"
316301
else
317-
echo "Could not find comment ID"
318-
echo "updated=false" >> "$GITHUB_OUTPUT"
302+
echo "::warning::Failed to delete PR comment"
303+
echo "deleted=false" >> "$GITHUB_OUTPUT"
319304
fi

0 commit comments

Comments
 (0)