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

Automerge PRs action #1823

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

yarikoptic
Copy link
Collaborator

@yarikoptic yarikoptic commented May 16, 2024

xref:

Inspired by

TODOs

  • create automerge label (created, we didn't have any)
  • fix that crap chatgpt produced... or just find a working example of such workflow elsewhere...
  • see if all desired outputs actually produce what is needed
  • may be test on some other repo where we can trick the dates of commits etc
  • uncomment and do provide GITHUB_TOKEN

Created from https://github.com/pascalgn/automerge-action/ example with
5 days delay coded up with chatgpt
Copy link

codecov bot commented May 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 87.92%. Comparing base (3fd21ff) to head (ab35dd2).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1823   +/-   ##
=======================================
  Coverage   87.92%   87.92%           
=======================================
  Files          16       16           
  Lines        1375     1375           
=======================================
  Hits         1209     1209           
  Misses        166      166           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

name: automerge
on:
schedule:
- cron: '4 5 * * *' # Runs at 04:05 (random) UTC every day
Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, the expression is for 5:04.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

;-) thanks

Suggested change
- cron: '4 5 * * *' # Runs at 04:05 (random) UTC every day
- cron: '4 5 * * *' # Runs at 05:04 (random) UTC every day

automerge:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
- uses: actions/checkout@v3
- uses: actions/checkout@v4

run: |
LAST_COMMIT_DATE=$(git log -1 --format=%cI)
echo "Last commit date: $LAST_COMMIT_DATE"
echo "::set-output name=last_commit_date::$LAST_COMMIT_DATE"
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
echo "::set-output name=last_commit_date::$LAST_COMMIT_DATE"
echo "last_commit_date=$LAST_COMMIT_DATE" >> "$GITHUB_OUTPUT"

The ::set-output method is deprecated; you need to write to $GITHUB_OUTPUT now.


- name: Calculate days since last commit
id: days_since_last_commit
run: |
Copy link
Contributor

Choose a reason for hiding this comment

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

You need to add shell: python for this.

delta = now - last_commit_datetime
days_since = delta.days
echo "Days since last commit: $days_since"
echo "::set-output name=days_since::$days_since"
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
echo "::set-output name=days_since::$days_since"
echo "days_since=$days_since" >> "$GITHUB_OUTPUT"

- name: Get date of the last commit
id: last_commit_date
run: |
LAST_COMMIT_DATE=$(git log -1 --format=%cI)
Copy link
Contributor

Choose a reason for hiding this comment

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

This can be faked by the Git user. It'd be better to fetch the head.pushed_at timestamp for the PR from the GitHub API.

- id: automerge
name: automerge
uses: "pascalgn/automerge-action@v0.16.3"
if: steps.days_since_last_commit.outputs.days_since > 5 && ((github.event_name == 'pull_request' && github.event.action == 'labeled') || github.event_name == 'schedule')
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't you add some sort of check that tests have passed, or does the action take care of that?

@@ -0,0 +1,60 @@
name: automerge
on:
schedule:
Copy link
Contributor

Choose a reason for hiding this comment

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

Problem: Scheduled runs only happen against the default branch, not against PRs.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

oh, that's a boomer... So the only way would be for a dedicated action to go through open PRs and see if any need to be triggered to be reran or do you see some other way?

Copy link
Contributor

Choose a reason for hiding this comment

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

Do you mean "merged" instead of "reran"?

Aside from that, yes, that's pretty much the only way.

@jwodder
Copy link
Contributor

jwodder commented May 20, 2024

Even if this succeeds in merging PRs after 5 days, it won't prevent merging before the 5 days are up, which seems like the more important qualification to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants