-
Notifications
You must be signed in to change notification settings - Fork 170
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
base: master
Are you sure you want to change the base?
Automerge PRs action #1823
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,60 @@ | ||||||
name: automerge | ||||||
on: | ||||||
schedule: | ||||||
- cron: '4 5 * * *' # Runs at 04:05 (random) UTC every day | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, the expression is for 5:04. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ;-) thanks
Suggested change
|
||||||
pull_request: | ||||||
types: | ||||||
- labeled | ||||||
- unlabeled | ||||||
- synchronize | ||||||
- opened | ||||||
- edited | ||||||
- ready_for_review | ||||||
- reopened | ||||||
- unlocked | ||||||
pull_request_review: | ||||||
types: | ||||||
- submitted | ||||||
- dismissed | ||||||
check_suite: | ||||||
types: | ||||||
- completed | ||||||
status: {} | ||||||
jobs: | ||||||
automerge: | ||||||
runs-on: ubuntu-latest | ||||||
steps: | ||||||
- uses: actions/checkout@v3 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
with: | ||||||
fetch-depth: 0 # Ensures all history is fetched | ||||||
|
||||||
- name: Get date of the last commit | ||||||
id: last_commit_date | ||||||
run: | | ||||||
LAST_COMMIT_DATE=$(git log -1 --format=%cI) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||||||
echo "Last commit date: $LAST_COMMIT_DATE" | ||||||
echo "::set-output name=last_commit_date::$LAST_COMMIT_DATE" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
The |
||||||
|
||||||
- name: Calculate days since last commit | ||||||
id: days_since_last_commit | ||||||
run: | | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You need to add |
||||||
from datetime import datetime | ||||||
last_commit_date = "${{ steps.last_commit_date.outputs.last_commit_date }}" | ||||||
last_commit_datetime = datetime.strptime(last_commit_date, "%Y-%m-%dT%H:%M:%S%z") | ||||||
now = datetime.now(last_commit_datetime.tzinfo) | ||||||
delta = now - last_commit_datetime | ||||||
days_since = delta.days | ||||||
echo "Days since last commit: $days_since" | ||||||
echo "::set-output name=days_since::$days_since" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
- id: automerge | ||||||
name: automerge | ||||||
uses: "pascalgn/[email protected]" | ||||||
if: steps.days_since_last_commit.outputs.days_since > 5 && ((github.event_name == 'pull_request' && github.event.action == 'labeled') || github.event_name == 'schedule') | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? |
||||||
env: | ||||||
# TODO: temporarily disabled to see if all above works | ||||||
# GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" | ||||||
MERGE_LABELS: automerge | ||||||
MERGE_METHOD_LABEL_REQUIRED: true | ||||||
MERGE_COMMIT_MESSAGE: automatic | ||||||
MERGE_REQUIRED_APPROVALS: 3 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.