From 12fe1a6f892ee3ba3cc342218c241fc086a2ca7f Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Thu, 16 May 2024 11:43:31 -0400 Subject: [PATCH 1/3] Prototype for automerge PRs action Created from https://github.com/pascalgn/automerge-action/ example with 5 days delay coded up with chatgpt --- .github/workflows/automerge.yml | 63 +++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 .github/workflows/automerge.yml diff --git a/.github/workflows/automerge.yml b/.github/workflows/automerge.yml new file mode 100644 index 0000000000..d264a36d91 --- /dev/null +++ b/.github/workflows/automerge.yml @@ -0,0 +1,63 @@ +name: automerge +on: + schedule: + - cron: '4 5 * * *' # Runs at 04:05 (random) UTC every day + 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 + with: + ref: ${{ github.head_ref }} + 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) + echo "Last commit date: $LAST_COMMIT_DATE" + echo "::set-output name=last_commit_date::$LAST_COMMIT_DATE" + + - name: Calculate days since last commit + id: days_since_last_commit + run: | + 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" + + - 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') + permissions: + contents: write + 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 From 3d1ef1a2c265886e7de6ff3be8693f51031384e4 Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Thu, 16 May 2024 11:47:15 -0400 Subject: [PATCH 2/3] remove out of place "permissions" -- may be not needed unless we restrict the rest? --- .github/workflows/automerge.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/automerge.yml b/.github/workflows/automerge.yml index d264a36d91..9b5b92a1ee 100644 --- a/.github/workflows/automerge.yml +++ b/.github/workflows/automerge.yml @@ -52,8 +52,6 @@ jobs: 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') - permissions: - contents: write env: # TODO: temporarily disabled to see if all above works # GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" From ab35dd2ef79db2f3b98584b63cfed73da16af704 Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Thu, 16 May 2024 12:09:29 -0400 Subject: [PATCH 3/3] remove explicit ref -- I think it is not needed? (might need for cron?) --- .github/workflows/automerge.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/automerge.yml b/.github/workflows/automerge.yml index 9b5b92a1ee..60bbb7d949 100644 --- a/.github/workflows/automerge.yml +++ b/.github/workflows/automerge.yml @@ -26,7 +26,6 @@ jobs: steps: - uses: actions/checkout@v3 with: - ref: ${{ github.head_ref }} fetch-depth: 0 # Ensures all history is fetched - name: Get date of the last commit