Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change review apps PR workflow to leave only one comment #1804

Merged
merged 1 commit into from
Feb 27, 2025

Conversation

lfdebrux
Copy link
Member

@lfdebrux lfdebrux commented Feb 25, 2025

What problem does this pull request solve?

The way we work with GitHub in this repo means we need to rebase our PRs often; this on top of the usual back and forth when reviewing means that review apps might get deployed several times before a PR is merged. This is fine, except that every time the review apps are deployed there is a new comment left by the workflow, which is a bit noisy.

This PR changes the workflow to first delete any existing comments about review apps (similar to what our other sonarqube cloud bot does), so that there should only be one comment about review apps on a PR at a time, but it keeps its useful place in the timeline.

Things to consider when reviewing

  • Ensure that you consider the wider context.
  • Does it work when run on your machine?
  • Is it clear what the code is doing?
  • Do the commit messages explain why the changes were made?
  • Are there all the unit tests needed?
  • Has all relevant documentation been updated?

@lfdebrux lfdebrux force-pushed the ldeb-change-review-apps-comment-delete-old-comments branch 2 times, most recently from 790cabd to 7d90641 Compare February 26, 2025 06:10
@lfdebrux lfdebrux marked this pull request as ready for review February 26, 2025 06:25
@lfdebrux lfdebrux requested a review from AP-Hunt February 26, 2025 06:25
@lfdebrux lfdebrux force-pushed the ldeb-change-review-apps-comment-delete-old-comments branch from 7d90641 to 6f845d2 Compare February 26, 2025 11:13
@alphagov alphagov deleted a comment from github-actions bot Feb 26, 2025
@lfdebrux lfdebrux force-pushed the ldeb-change-review-apps-comment-delete-old-comments branch 2 times, most recently from 83b89df to a90f2f1 Compare February 27, 2025 06:44
@AP-Hunt
Copy link
Member

AP-Hunt commented Feb 27, 2025

It's interesting that you thought of this too. Sarah and I thought about it as we built this and concluded "if it's needed it'll become evident".

The failing deployment is a permissions issue I need to fix from the forms-deploy side

@AP-Hunt
Copy link
Member

AP-Hunt commented Feb 27, 2025

This script isn't quite working, evidenced by the (currently!) two comments in this thread. I ran the script through Shellcheck and it pointed out why

old_comment_ids=$(gh api "repos/{owner}/{repo}/issues/${{github.event.pull_request.number}}/comments" --jq 'map(select((.user.login == "github-actions[bot]") and (.body | endswith($ENV.COMMENT_MARKER)))) | .[].id')
                                                                                                           ^-- SC2016: Expressions don't expand in single quotes, use double quotes for that.

For more information:
  https://www.shellcheck.net/wiki/SC2016 -- Expressions don't expand in singl...

If you want an env var available in a JQ expression you should do.

jq --arg name "${ENV_VAR}" 'expression using $name' input.json

Shellcheck says to use double quotes, but we generally avoid double quotes around JQ expressions because of the frequency with which we use double quotes in them.

@lfdebrux
Copy link
Member Author

lfdebrux commented Feb 27, 2025

This script isn't quite working, evidenced by the (currently!) two comments in this thread. I ran the script through Shellcheck and it pointed out why

old_comment_ids=$(gh api "repos/{owner}/{repo}/issues/${{github.event.pull_request.number}}/comments" --jq 'map(select((.user.login == "github-actions[bot]") and (.body | endswith($ENV.COMMENT_MARKER)))) | .[].id')
                                                                                                           ^-- SC2016: Expressions don't expand in single quotes, use double quotes for that.

For more information:
  https://www.shellcheck.net/wiki/SC2016 -- Expressions don't expand in singl...

If you want an env var available in a JQ expression you should do.

jq --arg name "${ENV_VAR}" 'expression using $name' input.json

Shellcheck says to use double quotes, but we generally avoid double quotes around JQ expressions because of the frequency with which we use double quotes in them.

That's weird, it was working before 🤔

@AP-Hunt
Copy link
Member

AP-Hunt commented Feb 27, 2025

Looking at $ENV.COMMENT_MARKER were you perhaps using GitHub Actions interpolation before? That would be ${{env.COMMENT_MARKER}}. $ENV. isn't valid syntax for env vars in a POSIX shell afaik

@lfdebrux
Copy link
Member Author

Looking at $ENV.COMMENT_MARKER were you perhaps using GitHub Actions interpolation before? That would be ${{env.COMMENT_MARKER}}. $ENV. isn't valid syntax for env vars in a POSIX shell afaik

I was trying to use the special $ENV variable in jq (https://jqlang.org/manual/#$env-env), rather than do a parameter expansion. Is there any reason not to do that?

@AP-Hunt
Copy link
Member

AP-Hunt commented Feb 27, 2025

None at all. I wasn't aware that existed!

@lfdebrux lfdebrux force-pushed the ldeb-change-review-apps-comment-delete-old-comments branch from a90f2f1 to 6a39b7b Compare February 27, 2025 10:17
Copy link

🎉 A review copy of this PR has been deployed! You can reach it at https://pr-1804.review.forms.service.gov.uk/.

It may take 5 minutes or so for the application to be fully deployed and working. If it still isn't ready
after 5 minutes, there may be something wrong with the ECS task. You will need to go to the integration AWS account
to debug, or otherwise ask an infrastructure person.

For more details please see the review app wiki page

@lfdebrux
Copy link
Member Author

@AP-Hunt fixed now (I was missing a newline)

@AP-Hunt
Copy link
Member

AP-Hunt commented Feb 27, 2025

Nice one! I can see there's only one comments from the bot now.

@lfdebrux lfdebrux merged commit 64886e2 into main Feb 27, 2025
6 checks passed
@lfdebrux lfdebrux deleted the ldeb-change-review-apps-comment-delete-old-comments branch February 27, 2025 10:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants