Skip to content

Commit

Permalink
Merge pull request #753 from conda-forge/add-automerge-task
Browse files Browse the repository at this point in the history
feat: add dispatch integration for automerge
  • Loading branch information
beckermr authored Nov 1, 2024
2 parents dc290d4 + dc96040 commit e1c7f88
Show file tree
Hide file tree
Showing 2 changed files with 132 additions and 1 deletion.
66 changes: 66 additions & 0 deletions .github/workflows/automerge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: automerge

on:
workflow_dispatch:
inputs:
repo:
description: 'the repository to run on'
required: true
type: string
sha:
description: 'the commit SHA to possibly merge'
required: true
type: string

env:
PY_COLORS: 1

defaults:
run:
shell: bash -leo pipefail {0}

jobs:
automerge:
name: automerge
runs-on: "ubuntu-latest"
steps:
- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4
with:
fetch-depth: 0
ref: ${{ github.ref }}

- name: setup conda
uses: mamba-org/setup-micromamba@f8b8a1e23a26f60a44c853292711bacfd3eac822 # v1
with:
environment-file: conda-lock.yml
environment-name: webservices
condarc: |
show_channel_urls: true
channel_priority: strict
channels:
- conda-forge
- name: generate token
id: generate_token
uses: actions/create-github-app-token@5d869da34e18e7287c1daad50e0b8ea0f506ce69 # v1
with:
app-id: ${{ secrets.CF_CURATOR_APP_ID }}
private-key: ${{ secrets.CF_CURATOR_PRIVATE_KEY }}
owner: ${{ github.repository_owner }}

- name: install code
run: |
pip install --no-deps --no-build-isolation -e .
- name: automerge
run: |
git config --global user.email "79913779+conda-forge-curator[bot]@users.noreply.github.com"
git config --global user.name "conda-forge-curator[bot]"
git config --global pull.rebase false
conda-forge-webservices-automerge \
--repo=${{ inputs.repo }} \
--sha=${{ inputs.sha }}
env:
GH_TOKEN: ${{ steps.generate_token.outputs.token }}

67 changes: 66 additions & 1 deletion conda_forge_webservices/webapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import conda_forge_webservices.feedstocks_service as feedstocks_service
import conda_forge_webservices.update_teams as update_teams
import conda_forge_webservices.commands as commands
from conda_forge_webservices._version import __version__
from conda_forge_webservices.update_me import WEBSERVICE_PKGS
from conda_forge_webservices.feedstock_outputs import (
validate_feedstock_outputs,
Expand All @@ -35,6 +36,7 @@
from conda_forge_webservices import status_monitor
from conda_forge_webservices.tokens import (
get_app_token_for_webservices_only,
get_gh_client,
inject_app_token_into_feedstock,
inject_app_token_into_feedstock_readonly,
)
Expand Down Expand Up @@ -731,6 +733,31 @@ async def post(self):
# return


def _dispatch_automerge_job(repo, sha):
if repo != "cf-autotick-bot-test-package-feedstock":
LOGGER.info(
" skipping automerge job dispatch for conda-forge/%s@%s", repo, sha
)
return

gh = get_gh_client()
ref = __version__.replace("+", ".")
workflow = gh.get_repo("conda-forge/conda-forge-webservices").get_workflow(
"automerge.yml"
)
running = workflow.create_dispatch(
ref=ref,
inputs={
"repo": repo,
"sha": sha,
},
)
if running:
LOGGER.info(" automerge job dispatched: conda-forge/%s@%s", repo, sha)
else:
LOGGER.info(" automerge job dispatch failed")


class StatusMonitorPayloadHookHandler(tornado.web.RequestHandler):
async def post(self):
headers = self.request.headers
Expand Down Expand Up @@ -763,7 +790,22 @@ async def post(self):
elif event == "check_suite":
inject_app_token_into_feedstock(body["repository"]["full_name"])
inject_app_token_into_feedstock_readonly(body["repository"]["full_name"])
self.write(event)

LOGGER.info("")
LOGGER.info("===================================================")
LOGGER.info("check suite: %s", body["repository"]["full_name"])
LOGGER.info("===================================================")

if body["action"] == "completed" and body["repository"][
"full_name"
].endswith("-feedstock"):
await tornado.ioloop.IOLoop.current().run_in_executor(
_worker_pool(),
_dispatch_automerge_job,
body["repository"]["name"],
body["check_suite"]["head_sha"],
)

return
elif event == "status":
LOGGER.info("")
Expand All @@ -775,7 +817,30 @@ async def post(self):
async with STATUS_DATA_LOCK:
status_monitor.update_data_status(body)

if body["repository"]["full_name"].endswith("-feedstock"):
await tornado.ioloop.IOLoop.current().run_in_executor(
_worker_pool(),
_dispatch_automerge_job,
body["repository"]["name"],
body["sha"],
)

return
elif event in ["pull_request", "pull_request_review"]:
LOGGER.info("")
LOGGER.info("===================================================")
LOGGER.info(
"pull request/pull request review: %s", body["repository"]["full_name"]
)
LOGGER.info("===================================================")

if body["repository"]["full_name"].endswith("-feedstock"):
await tornado.ioloop.IOLoop.current().run_in_executor(
_worker_pool(),
_dispatch_automerge_job,
body["repository"]["name"],
body["pull_request"]["head"]["sha"],
)
else:
LOGGER.info(f'Unhandled event "{event}".')

Expand Down

0 comments on commit e1c7f88

Please sign in to comment.