Skip to content

Commit

Permalink
Test PR workflows (#1)
Browse files Browse the repository at this point in the history
* Test PR workflows

* ignore editor profile files

* Test environment and workflow
  • Loading branch information
F-WRunTime authored Jan 24, 2024
1 parent 651e3f7 commit c15791a
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/basic-validation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Basic validation
on:
push:
branches:
- main
- master
paths-ignore:
- '**.md'
pull_request:
Expand Down
32 changes: 32 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Test Workflow

on: [push, pull_request, workflow_dispatch]

jobs:
list:
name: 'List Repos'
runs-on: [ubuntu-latest]
outputs:
matrix: ${{ steps.list.outputs.value }}
steps:
- name: 'Check out devops repo'
uses: actions/checkout@v3
- id: list
name: 'List automerge repos'
run: echo "value=$(cat test/automerge.json | tr -d '\n')" >> $GITHUB_OUTPUT

automerge-test:
name: 'Automerge'
runs-on: [ubuntu-latest]
needs: list
strategy:
fail-fast: false
matrix:
value: ${{fromJson(needs.list.outputs.matrix)}}
steps:
- name: 'Automerge runtimeverification/${{ matrix.value }}'
uses: ./ # This uses the action in the root directory
with:
org: 'runtimeverification'
repo: ${{ matrix.value }}
token: ${{ secrets.JENKINS_GITHUB_PAT }}
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Ignore vscode files

.vscode

# Ignore Test Environment Files
tmp-*
4 changes: 0 additions & 4 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ name: "Automerge"
author: "Runtime Verification Inc"
description: "Automatically merge pull requests meeting the requiresments of All Checks Pass, Review Approved, and Up-to-date. This action is a substituion for Github merge queues. Merge queues fails to adhere to passing checks. Automerge helps support a linear well tested PR before it is merged."
inputs:
list-of-repos:
description: 'List of repos to merge'
required: true
org:
description: 'Organization name under which to run on'
required: true
Expand Down Expand Up @@ -49,7 +46,6 @@ runs:
shell: bash {0}
env:
GITHUB_TOKEN: ${{ inputs.token }}
# TODO: for some reason, even though the script fails, the workflow doesn't
working-directory: tmp-${{ inputs.repo }}
run: python3 ../src/automerge.py --org ${{ inputs.org }} --repo ${{ inputs.repo }}

27 changes: 16 additions & 11 deletions src/automerge.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,22 @@
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.')
args = parser.parse_args()

_LOGGER: Final = logging.getLogger(__name__)
_LOG_FORMAT: Final = '%(levelname)s %(asctime)s %(name)s - %(message)s'
logging.basicConfig(level=logging.INFO)

def pr_to_display_string(pr):
return f'- {pr.number}: {pr.title}'
return f'- {pr.number}: {pr.title}\n\t\t{pr.html_url}'

def run_git_command(args: str) -> subprocess.CompletedProcess:
command = ['git'] + args.split(' ')
def run_git_command(command_args: str) -> subprocess.CompletedProcess:
command = ['git'] + command_args.split(' ')
_LOGGER.debug(f'Running: {" ".join(command)}')
if args.dry_run:
_LOGGER.info(f'Would have run: {" ".join(command)}')
return subprocess.CompletedProcess(args=command, returncode=0)
try:
res = subprocess.run(command, stdout=None, stderr=None, check=False, text=True)
except subprocess.CalledProcessError as err:
Expand All @@ -33,7 +37,7 @@ def run_git_command(args: str) -> subprocess.CompletedProcess:
return res

github = Github(login_or_token=os.environ['GITHUB_TOKEN'])
repo = args.org/args.repo
repo = args.org + "/" + args.repo

# 1. Get PRs that are:
# - Open.
Expand Down Expand Up @@ -90,11 +94,14 @@ def run_git_command(args: str) -> subprocess.CompletedProcess:
# - Labelled as `automerge`,
# - Approved, and
# - Up-to-date.
# If so, merge one.
# If so, merge
if automerge_up_to_date_prs:
pr = automerge_up_to_date_prs[0]
_LOGGER.info(f' Merging PR:\n{pr_to_display_string(pr)}\n')
pr.merge(merge_method='squash')
if args.dry_run:
_LOGGER.info(f'Would have merged PR:\n{pr_to_display_string(pr)}\n')
else:
pr.merge(merge_method='squash')
automerge_up_to_date_prs.pop(0)

# 5. Get PRs that are:
Expand All @@ -103,7 +110,7 @@ def run_git_command(args: str) -> subprocess.CompletedProcess:
# - Approved,
# - Up-to-date, and
# - Pending tests.
# If so, quit (reduce build pressure).
#
automerge_up_to_date_pending_prs = []
for pr in automerge_prs:
is_up_to_date = run_git_command(f'merge-base --is-ancestor {pr.base.sha} {pr.head.sha}').returncode == 0
Expand All @@ -113,10 +120,8 @@ def run_git_command(args: str) -> subprocess.CompletedProcess:
print(commit.get_combined_status())
automerge_up_to_date_pending_prs.append(pr)
pr_string = '\n'.join(map(pr_to_display_string, automerge_up_to_date_pending_prs))
_LOGGER.info(f' Automerge approved up-to-date pending PRs:\n{pr_string}\n')
if automerge_up_to_date_pending_prs:
_LOGGER.info(' Quitting.')
sys.exit(0)
_LOGGER.info(f' Waiting on approved up-to-date pending/failing PRs:\n{pr_string}\n')


# 6. Get PRs that are:
# - Open,
Expand Down
17 changes: 1 addition & 16 deletions test/automerge.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
[
"algorand-sc-semantics"
, "amp"
, "audit-kontrol-template"
, "avm-semantics"
, "blockchain-k-plugin"
, "blockswap-server"
, "casper-cbc-proofs"
, "c-semantics"
, "erc20-verification"
, "ercx"
, "evm-semantics"
, "firefly"
, "firefly-web"
, "foundry-tests"
, "haskell-backend"
, "homebrew-k"
"devops-actions"
]

0 comments on commit c15791a

Please sign in to comment.