Skip to content

chore(ci): create pull request on changelog update #2224

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

Merged

Conversation

heitorlessa
Copy link
Contributor

Issue number: closes #2210

Summary

Creates a temporary branch with CHANGELOG changes, and a pull request tracing back to GitHub Actions that originated it.

Decided to use a shell script given how powerfull GitHub CLI is now vs re-create all lower level mechanism using
JavaScript. Since all commands are CLI it made more sense to use shell script.

Changes

Please provide a summary of what's being changed

  • Reusable shell script to create PR from specific staged files/dirs
  • Detect and close duplicate PRs
  • Delete orphaned branches from duplicate PRs
  • Create job report for GitHub Actions to ease debugging
  • Make each PR trace back to GitHub Actions that created it
  • Add debugging
  • Add clean up step to delete branch if previous PR failed to be created for any reason
  • Don't fail workflow if cleanup task failed... if branch wasn't even created in the first place
  • Lint with shellcheck

User experience

Please share what the user experience looks like before and after this change

Pull request created

Sample CI run

image

image

Close duplicate PRs

Sample CI run

image

Cleanup behaviour

Sample CI run

image

Checklist

If your change doesn't seem to apply, please leave them unchecked.

Is this a breaking change?

RFC issue number:

Checklist:

  • Migration process documented
  • Implement warnings (if it can live side by side)

Acknowledgment

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

@heitorlessa heitorlessa requested a review from a team as a code owner May 8, 2023 10:21
@heitorlessa heitorlessa requested review from leandrodamascena and removed request for a team May 8, 2023 10:21
@boring-cyborg boring-cyborg bot added the github-actions Pull requests that update Github_actions code label May 8, 2023
@pull-request-size pull-request-size bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label May 8, 2023
@github-actions github-actions bot added the internal Maintenance changes label May 8, 2023
Copy link
Contributor

@leandrodamascena leandrodamascena left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL that you are an expert in something else: shell scripting!

Very good @heitorlessa!!
image

Comment on lines 37 to 42
debug "Do we have required environment variables?"
test -z "${TEMP_BRANCH_PREFIX}" && raise_validation_error "TEMP_BRANCH_PREFIX env must be set to create a PR"
test -z "${GH_TOKEN}" && raise_validation_error "GH_TOKEN env must be set for GitHub CLI"
test -z "${GITHUB_RUN_ID}" && raise_validation_error "GITHUB_RUN_ID env must be set to trace Workflow Run ID back to PR"
test -z "${GITHUB_SERVER_URL}" && raise_validation_error "GITHUB_SERVER_URL env must be set to trace Workflow Run ID back to PR"
test -z "${GITHUB_REPOSITORY}" && raise_validation_error "GITHUB_REPOSITORY env must be set to trace Workflow Run ID back to PR"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth it adding the COMMIT_MSG and PR_TITLE variables in this check?

#required_env_vars :COMMIT_MSG, PR_TITLE, TEMP_BRANCH_PREFIX, GH_TOKEN, GITHUB_RUN_ID, GITHUB_SERVER_URL, GITHUB_REPOSITORY

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

YES, good catch! Doing it now

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DONE

Comment on lines +84 to +91
function close_duplicate_prs() {
debug "Do we have any duplicate PRs?"
DUPLICATE_PRS=$(gh pr list --search "${PR_TITLE}" --json number --jq ".[] | select(.number != ${NEW_PR_ID}) | .number") # e.g, 13\n14

debug "Closing duplicated PRs if any"
echo "${DUPLICATE_PRS}" | xargs -L1 gh pr close --delete-branch --comment "Superseded by #${NEW_PR_ID}"
export readonly DUPLICATE_PRS
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super cool this check to avoid orphans branches in the repository and getting messy. :D

Co-authored-by: Leandro Damascena <[email protected]>
Signed-off-by: Heitor Lessa <[email protected]>
@heitorlessa
Copy link
Contributor Author

Thanks @leandrodamascena for the catch and for the early approval! Merging so I can complete the related ones today.

@heitorlessa heitorlessa merged commit d599649 into aws-powertools:develop May 8, 2023
@heitorlessa heitorlessa deleted the chore/safer-changelog branch May 8, 2023 12:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
github-actions Pull requests that update Github_actions code internal Maintenance changes size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create PRs from workflows (e.g., changelog, docs layer, docs)
2 participants