|
1 | 1 | # replace-comment |
2 | 2 |
|
3 | | -A GitHub Action that finds, deletes, and recreates a comment to move it to the bottom of the conversation. This is perfect for CI/CD status updates, bot notifications, and any content you want to keep highly visible. |
4 | | - |
5 | | -## Why Replace Instead of Update? |
6 | | - |
7 | | -When you **update** a comment, it stays in its original chronological position. When you **delete and recreate**, the new comment appears at the bottom of the conversation - much more visible! |
8 | | - |
9 | | -**Perfect for:** |
10 | | -- ✅ CI/CD test results |
11 | | -- ✅ Build status updates |
12 | | -- ✅ Bot notifications |
13 | | -- ✅ Status reports |
14 | | -- ✅ Any content that should stay at the bottom for visibility |
| 3 | +GitHub Action that finds, deletes, and recreates comments to keep them at the bottom of PR conversations. Perfect for CI/CD status updates and bot notifications. |
15 | 4 |
|
16 | 5 | ## Usage |
17 | 6 |
|
18 | | -### Basic Example |
19 | | - |
20 | 7 | ```yaml |
21 | | -- name: Replace E2E Test Results Comment |
| 8 | +- name: Replace Comment |
22 | 9 | uses: johanwulf/replace-comment@v1.0.0 |
23 | 10 | with: |
24 | 11 | issue-number: ${{ github.event.pull_request.number }} |
25 | | - body-includes: '<!-- e2e-test-results -->' |
26 | | - comment-author: 'github-actions[bot]' |
| 12 | + body-includes: '<!-- test-results -->' |
27 | 13 | body: | |
28 | | - <!-- e2e-test-results --> |
29 | | - ## 🧪 E2E Test Results |
30 | | - |
| 14 | + <!-- test-results --> |
| 15 | + ## Test Results |
31 | 16 | ✅ All tests passed! |
32 | | - |
33 | | - - **Total tests:** 42 |
34 | | - - **Duration:** 3m 24s |
35 | | - - **Browser:** Chrome 120 |
36 | | -``` |
37 | | -
|
38 | | -### Advanced Example with File Body |
39 | | -
|
40 | | -```yaml |
41 | | -- name: Replace Build Report |
42 | | - uses: johanwulf/replace-comment@v1.0.0 |
43 | | - with: |
44 | | - token: ${{ secrets.GITHUB_TOKEN }} |
45 | | - repository: ${{ github.repository }} |
46 | | - issue-number: ${{ github.event.pull_request.number }} |
47 | | - body-regex: '<!-- build-report-\\d+ -->' |
48 | | - comment-author: 'build-bot[bot]' |
49 | | - body-path: './build-report.md' |
50 | | - reactions: 'rocket,eyes' |
51 | 17 | ``` |
52 | 18 |
|
53 | 19 | ## Inputs |
@@ -80,152 +46,10 @@ When you **update** a comment, it stays in its original chronological position. |
80 | 46 |
|
81 | 47 | ## How It Works |
82 | 48 |
|
83 | | -1. **🔍 Find**: Uses [peter-evans/find-comment](https://github.com/peter-evans/find-comment) to search for existing comments |
84 | | -2. **🗑️ Delete**: Removes the found comment using GitHub's REST API (if any) |
85 | | -3. **✨ Create**: Uses [peter-evans/create-or-update-comment](https://github.com/peter-evans/create-or-update-comment) to create a new comment at the bottom |
86 | | - |
87 | | -This action is a **composite action** that combines the excellent work of Peter Evans into a simple "find-delete-create" workflow. |
88 | | - |
89 | | -## Examples |
90 | | - |
91 | | -### CI/CD Test Results |
92 | | - |
93 | | -```yaml |
94 | | -name: Tests |
95 | | -on: [push, pull_request] |
96 | | -
|
97 | | -jobs: |
98 | | - test: |
99 | | - runs-on: ubuntu-latest |
100 | | - steps: |
101 | | - - uses: actions/checkout@v4 |
102 | | - |
103 | | - - name: Run tests |
104 | | - id: tests |
105 | | - run: | |
106 | | - # Your test commands here |
107 | | - echo "result=✅ All tests passed!" >> $GITHUB_OUTPUT |
108 | | - |
109 | | - - name: Update test results comment |
110 | | - if: github.event_name == 'pull_request' |
111 | | - uses: johanwulf/replace-comment@v1.0.0 |
112 | | - with: |
113 | | - issue-number: ${{ github.event.pull_request.number }} |
114 | | - body-includes: '<!-- test-results -->' |
115 | | - comment-author: 'github-actions[bot]' |
116 | | - body: | |
117 | | - <!-- test-results --> |
118 | | - ## 🧪 Test Results |
119 | | - |
120 | | - ${{ steps.tests.outputs.result }} |
121 | | - |
122 | | - **Commit:** ${{ github.sha }} |
123 | | - **Workflow:** [${{ github.run_id }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) |
124 | | -``` |
125 | | - |
126 | | -### Deployment Status |
127 | | - |
128 | | -```yaml |
129 | | -- name: Update deployment status |
130 | | - uses: johanwulf/replace-comment@v1.0.0 |
131 | | - with: |
132 | | - issue-number: ${{ github.event.pull_request.number }} |
133 | | - body-regex: '<!-- deploy-status-.*? -->' |
134 | | - body: | |
135 | | - <!-- deploy-status-${{ github.run_id }} --> |
136 | | - ## 🚀 Deployment Status |
137 | | - |
138 | | - **Environment:** staging |
139 | | - **Status:** ${{ job.status }} |
140 | | - **URL:** https://staging-${{ github.event.pull_request.number }}.example.com |
141 | | - **Deploy time:** $(date) |
142 | | - reactions: 'rocket' |
143 | | -``` |
144 | | - |
145 | | -### Build Artifacts Report |
146 | | - |
147 | | -```yaml |
148 | | -- name: Generate build report |
149 | | - run: | |
150 | | - echo "## 📦 Build Artifacts" > build-report.md |
151 | | - echo "" >> build-report.md |
152 | | - echo "| File | Size |" >> build-report.md |
153 | | - echo "|------|------|" >> build-report.md |
154 | | - ls -la dist/ | awk '{print "| " $9 " | " $5 " |"}' >> build-report.md |
155 | | -
|
156 | | -- name: Post build report |
157 | | - uses: johanwulf/replace-comment@v1.0.0 |
158 | | - with: |
159 | | - issue-number: ${{ github.event.pull_request.number }} |
160 | | - body-includes: '<!-- build-artifacts -->' |
161 | | - body-path: './build-report.md' |
162 | | -``` |
163 | | - |
164 | | -## Tips |
165 | | - |
166 | | -### Unique Comment Identification |
167 | | - |
168 | | -Use HTML comments to uniquely identify your comments: |
169 | | - |
170 | | -```yaml |
171 | | -body: | |
172 | | - <!-- my-unique-identifier --> |
173 | | - Your visible content here |
174 | | -``` |
175 | | - |
176 | | -### Multiple Bot Comments |
177 | | - |
178 | | -Use different identifiers for different types of comments: |
179 | | - |
180 | | -```yaml |
181 | | -# Test results |
182 | | -body-includes: '<!-- test-results -->' |
183 | | -
|
184 | | -# Build status |
185 | | -body-includes: '<!-- build-status -->' |
186 | | -
|
187 | | -# Deploy status |
188 | | -body-includes: '<!-- deploy-status -->' |
189 | | -``` |
190 | | - |
191 | | -### Conditional Comments |
192 | | - |
193 | | -Only create comments when needed: |
194 | | - |
195 | | -```yaml |
196 | | -- name: Replace comment |
197 | | - if: github.event_name == 'pull_request' && failure() |
198 | | - uses: johanwulf/replace-comment@v1.0.0 |
199 | | - with: |
200 | | - # ... your config |
201 | | -``` |
202 | | - |
203 | | -## Comparison with Other Actions |
204 | | - |
205 | | -| Action | Find | Update | Delete+Create | Use Case | |
206 | | -|--------|------|--------|---------------|----------| |
207 | | -| `peter-evans/create-or-update-comment` | ✅ | ✅ | ❌ | Update existing content | |
208 | | -| `edumserrano/find-create-or-update-comment` | ✅ | ✅ | ❌ | Simplified find+update | |
209 | | -| `replace-comment` (this action) | ✅ | ❌ | ✅ | Keep comments at bottom | |
210 | | - |
211 | | -## Development |
212 | | - |
213 | | -This is a composite GitHub Action that leverages: |
214 | | -- [peter-evans/find-comment](https://github.com/peter-evans/find-comment) for finding comments |
215 | | -- [peter-evans/create-or-update-comment](https://github.com/peter-evans/create-or-update-comment) for creating comments |
216 | | -- GitHub REST API for deleting comments |
217 | | - |
218 | | -No build step required! The action runs directly from the `action.yml` file. |
219 | | - |
220 | | -## Contributing |
221 | | - |
222 | | -Contributions are welcome! Please feel free to submit a Pull Request. |
| 49 | +1. Find existing comment using search criteria |
| 50 | +2. Delete the found comment (if any) |
| 51 | +3. Create new comment at the bottom |
223 | 52 |
|
224 | 53 | ## License |
225 | 54 |
|
226 | | -This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. |
227 | | - |
228 | | -## Acknowledgments |
229 | | - |
230 | | -- Inspired by the excellent work of [Peter Evans](https://github.com/peter-evans) on GitHub Actions for comments |
231 | | -- Built to fill the gap for delete+create comment workflows |
| 55 | +MIT License - see [LICENSE](LICENSE) file for details. |
0 commit comments