From e91699b367a70e55471cc4c8e2bf4c32a4044d4c Mon Sep 17 00:00:00 2001 From: devops Date: Tue, 13 Feb 2024 15:11:33 -0700 Subject: [PATCH 1/5] Update workflow to use debug mode by choice, not required. Update action to include use of dry-run. Change test Yaml to point to special repository for testing --- .github/workflows/test.yaml | 1 + action.yaml | 6 +++++- src/automerge.py | 4 ++-- test/automerge.json | 2 +- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index c6e9137..e7eaf76 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -33,3 +33,4 @@ jobs: org: 'runtimeverification' repo: ${{ matrix.value }} token: ${{ secrets.JENKINS_GITHUB_PAT }} + debug: true diff --git a/action.yaml b/action.yaml index 40533e6..b65dbdd 100644 --- a/action.yaml +++ b/action.yaml @@ -14,6 +14,10 @@ inputs: token: description: 'Access token to be able to write to the repository' required: true + debug: + description: 'Debug mode' + required: false + default: 'false' outputs: merged: value: ${{ steps.automerge.outputs.merged }} @@ -49,5 +53,5 @@ runs: env: GITHUB_TOKEN: ${{ inputs.token }} working-directory: tmp-${{ inputs.repo }} - run: python3 ${{ github.action_path }}/src/automerge.py --org ${{ inputs.org }} --repo ${{ inputs.repo }} + run: python3 ${{ github.action_path }}/src/automerge.py --org ${{ inputs.org }} --repo ${{ inputs.repo }} --dry-run ${{ inputs.debug }} diff --git a/src/automerge.py b/src/automerge.py index 0ad687e..fe5c814 100755 --- a/src/automerge.py +++ b/src/automerge.py @@ -98,13 +98,13 @@ def run_git_command(command_args: str) -> subprocess.CompletedProcess: # - Approved, and # - Up-to-date. # If so, merge -if automerge_up_to_date_prs: +while automerge_up_to_date_prs: pr = automerge_up_to_date_prs[0] _LOGGER.info(f' Merging PR:\n{pr_to_display_string(pr)}\n') if args.dry_run: _LOGGER.info(f'Would have merged PR:\n{pr_to_display_string(pr)}\n') else: - pr.merge(merge_method='squash') + pr.merge(merge_method='squash', merge_title=f'Auto Mergerge: {pr.number}', merge_message='Title: {pr.title}\nURL: {pr.html_url}\n') automerge_up_to_date_prs.pop(0) # 5. Get PRs that are: diff --git a/test/automerge.json b/test/automerge.json index ad2b806..ed6b8b0 100644 --- a/test/automerge.json +++ b/test/automerge.json @@ -1,3 +1,3 @@ [ - "devops-actions" + "automerger-test" ] \ No newline at end of file From 00739580f40bb71f8886a218e45018e48bd7d358 Mon Sep 17 00:00:00 2001 From: devops Date: Tue, 13 Feb 2024 20:29:00 -0700 Subject: [PATCH 2/5] Test workflow now with dry-run as an option from the workflow action --- src/automerge.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/automerge.py b/src/automerge.py index fe5c814..15f407f 100755 --- a/src/automerge.py +++ b/src/automerge.py @@ -13,7 +13,7 @@ parser = argparse.ArgumentParser(description='Automerge approved PRs.') parser.add_argument('--repo', type=str, help='The repository to check.') parser.add_argument('--org', type=str, help='The GitHub organization to check.') -parser.add_argument('--dry-run', action='store_true', help='Enable DR run mode.') +parser.add_argument('--dry-run', action='store_true', default=False, help='Enable Debug/Dry-Run mode.') args = parser.parse_args() _LOGGER: Final = logging.getLogger(__name__) From 718b18323b7b525ef4127beda3aa711d21a43bd3 Mon Sep 17 00:00:00 2001 From: devops Date: Tue, 13 Feb 2024 20:31:25 -0700 Subject: [PATCH 3/5] remove basic validation, add test to pull request pass requirements --- .github/workflows/basic-validation.yaml | 36 ------------------------- .github/workflows/test.yaml | 6 ++++- 2 files changed, 5 insertions(+), 37 deletions(-) delete mode 100644 .github/workflows/basic-validation.yaml diff --git a/.github/workflows/basic-validation.yaml b/.github/workflows/basic-validation.yaml deleted file mode 100644 index 32261f7..0000000 --- a/.github/workflows/basic-validation.yaml +++ /dev/null @@ -1,36 +0,0 @@ -name: Basic validation - -on: - push: - branches: - - master - paths-ignore: - - '**.md' - pull_request: - paths-ignore: - - '**.md' - -jobs: - call-basic-validation: - # Setup basic python lint check - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4.0.0 - - name: Set up Python 3.10 - uses: actions/setup-python@v5.0.0 - with: - python-version: 3.10 - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install flake8 pytest - if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - - name: Lint with flake8 - run: | - # stop the build if there are Python syntax errors or undefined names - flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics - # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide - flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - # - name: Test with pytest - # run: | - # pytest diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index e7eaf76..f1dbf3a 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -1,6 +1,10 @@ name: Test Workflow -on: [workflow_dispatch] +on: + workflow_dispatch: + pull_request: + branches: + - master jobs: list: From aad8f48247aff9660055b5722c1c53384cfbf60b Mon Sep 17 00:00:00 2001 From: devops Date: Tue, 13 Feb 2024 20:47:36 -0700 Subject: [PATCH 4/5] pass flag --dry-run instead of bool --- .github/workflows/test.yaml | 2 +- action.yaml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index f1dbf3a..663a620 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -37,4 +37,4 @@ jobs: org: 'runtimeverification' repo: ${{ matrix.value }} token: ${{ secrets.JENKINS_GITHUB_PAT }} - debug: true + debug: --dry-run diff --git a/action.yaml b/action.yaml index b65dbdd..432b99e 100644 --- a/action.yaml +++ b/action.yaml @@ -17,7 +17,7 @@ inputs: debug: description: 'Debug mode' required: false - default: 'false' + default: '' outputs: merged: value: ${{ steps.automerge.outputs.merged }} @@ -53,5 +53,5 @@ runs: env: GITHUB_TOKEN: ${{ inputs.token }} working-directory: tmp-${{ inputs.repo }} - run: python3 ${{ github.action_path }}/src/automerge.py --org ${{ inputs.org }} --repo ${{ inputs.repo }} --dry-run ${{ inputs.debug }} + run: python3 ${{ github.action_path }}/src/automerge.py --org ${{ inputs.org }} --repo ${{ inputs.repo }} ${{ inputs.debug }} From bdce0cd668d4352254de3a6d2b8f2f61ff49e2ad Mon Sep 17 00:00:00 2001 From: devops Date: Tue, 13 Feb 2024 21:26:07 -0700 Subject: [PATCH 5/5] Updating instructions. Fixing usage of Github function merge() --- README.md | 17 +++++++++++++++++ src/automerge.py | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f529ed8..ed12999 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,7 @@ Any PR with the following criteria will be updated and test will be run before m - [Example workflow using Automerge across a Github Organization](#example-workflow-using-automerge-across-a-github-organization) - [The Workflow](#the-workflow) - [Reduce CI Pressure](#reduce-ci-pressure) + - [Run Locally](#run-locally) # Example workflow using Automerge across a Github Organization This example workflow will run every 20 minutes and will automerge PRs for tracked repositories in the organization. @@ -104,3 +105,19 @@ on: ... ... ``` + +# Run Locally +Checkout the repository you wish to run automerge on to a local directory. +```bash +git clone git@github.com:org/automerge.git +cd automerge +``` + +Now you need to run the command from this new directory +```bash +$(pwd)/../src/automerge.py --org runtimeverification --repo automerger-test --dry-run +``` + +Recommended to first review the actions before running without. Then remove the `--dry-run` flag to run the action. + + diff --git a/src/automerge.py b/src/automerge.py index 15f407f..91d2c2a 100755 --- a/src/automerge.py +++ b/src/automerge.py @@ -104,7 +104,7 @@ def run_git_command(command_args: str) -> subprocess.CompletedProcess: if args.dry_run: _LOGGER.info(f'Would have merged PR:\n{pr_to_display_string(pr)}\n') else: - pr.merge(merge_method='squash', merge_title=f'Auto Mergerge: {pr.number}', merge_message='Title: {pr.title}\nURL: {pr.html_url}\n') + pr.merge(merge_method='squash', commit_message=f'Automerge {pr.html_url}: {pr.title}') automerge_up_to_date_prs.pop(0) # 5. Get PRs that are: