-
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #754 from conda-forge/add-live-automerge-test
test: add live test for automerge
- Loading branch information
Showing
6 changed files
with
276 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
bot: | ||
automerge: true | ||
conda_forge_output_validation: true | ||
github: | ||
branch_name: main | ||
tooling_branch_name: main | ||
azure: | ||
store_build_artifacts: true | ||
conda_build: | ||
pkg_format: 2 | ||
provider: | ||
linux_64: azure | ||
osx_64: github_actions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{% set name = "cf-autotick-bot-test-package" %} | ||
{% set version = "0.14" %} | ||
|
||
package: | ||
name: {{ name|lower }} | ||
version: {{ version }} | ||
|
||
source: | ||
url: https://github.com/regro/cf-autotick-bot-test-package/archive/v{{ version }}.tar.gz | ||
sha256: f6c45d5788f51dbe1cc55e1010f3e9ebd18b6c0f21907fc35499468a59827eef | ||
|
||
build: | ||
number: 0 | ||
skip: true # [py != 39 or win or aarch64 or ppc64le or s390x] | ||
|
||
requirements: | ||
host: | ||
- python | ||
- pip | ||
- setuptools | ||
run: | ||
- python | ||
|
||
test: | ||
commands: | ||
- echo "works!" | ||
|
||
about: | ||
home: https://github.com/regro/cf-scripts | ||
license: BSD-3-Clause | ||
license_family: BSD | ||
license_file: LICENSE | ||
summary: testing feedstock for the regro-cf-autotick-bot | ||
|
||
extra: | ||
recipe-maintainers: | ||
- conda-forge-daemon |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
import os | ||
import subprocess | ||
import tempfile | ||
import time | ||
import uuid | ||
|
||
import github | ||
from conda_forge_webservices.utils import pushd | ||
|
||
TEST_BASE_BRANCH = "automerge-live-test-base-branch" | ||
TEST_HEAD_BRANCH = f"automerge-live-test-head-branch-h{uuid.uuid4().hex[:6]}" | ||
DEBUG = False | ||
|
||
|
||
def _run_git_cmd(*args): | ||
subprocess.run(["git", *list(args)], check=True) | ||
|
||
|
||
def test_live_automerge(pytestconfig): | ||
branch = pytestconfig.getoption("branch") | ||
|
||
print("making an edit to the head ref...", flush=True) | ||
with tempfile.TemporaryDirectory() as tmpdir: | ||
with pushd(tmpdir): | ||
print("cloning...", flush=True) | ||
_run_git_cmd( | ||
"clone", | ||
f"https://x-access-token:{os.environ['GH_TOKEN']}@github.com/conda-forge/" | ||
"cf-autotick-bot-test-package-feedstock.git", | ||
) | ||
|
||
with pushd("cf-autotick-bot-test-package-feedstock"): | ||
pr = None | ||
try: | ||
print("checkout branch...", flush=True) | ||
_run_git_cmd("checkout", TEST_BASE_BRANCH) | ||
_run_git_cmd("checkout", "-b", TEST_HEAD_BRANCH) | ||
|
||
print("adding a correct recipe and conda-forge.yml...", flush=True) | ||
test_dir = os.path.dirname(__file__) | ||
subprocess.run( | ||
["cp", f"{test_dir}/conda-forge.yml", "."], | ||
check=True, | ||
) | ||
subprocess.run( | ||
["cp", f"{test_dir}/meta.yaml", "recipe/meta.yaml"], | ||
check=True, | ||
) | ||
|
||
print("rerendering...", flush=True) | ||
subprocess.run( | ||
[ | ||
"conda", | ||
"smithy", | ||
"rerender", | ||
"-c", | ||
"auto", | ||
"--no-check-uptodate", | ||
], | ||
check=True, | ||
) | ||
|
||
print("making a commit...", flush=True) | ||
_run_git_cmd("add", ".") | ||
_run_git_cmd( | ||
"commit", "--allow-empty", "-m", "test commit for automerge" | ||
) | ||
|
||
print("push to branch...", flush=True) | ||
_run_git_cmd("push", "-u", "origin", TEST_HEAD_BRANCH) | ||
|
||
print("making a PR...", flush=True) | ||
gh = github.Github(auth=github.Auth.Token(os.environ["GH_TOKEN"])) | ||
repo = gh.get_repo( | ||
"conda-forge/cf-autotick-bot-test-package-feedstock" | ||
) | ||
|
||
pr = repo.create_pull( | ||
TEST_BASE_BRANCH, | ||
TEST_HEAD_BRANCH, | ||
title="[DO NOT TOUCH] test pr for automerge", | ||
body=( | ||
"This is a test PR for automerge from " | ||
f"GHA run {os.environ['GHA_URL']}. " | ||
"Please do not make any changes!" | ||
), | ||
maintainer_can_modify=True, | ||
draft=False, | ||
) | ||
pr.add_to_labels("automerge") | ||
|
||
print("waiting for the PR to be merged...", flush=True) | ||
tot = 0 | ||
merged = False | ||
while tot < 600: | ||
time.sleep(10) | ||
tot += 10 | ||
print(f" slept {tot} seconds out of 600", flush=True) | ||
if tot % 30 == 0: | ||
if pr.is_merged(): | ||
print("PR was merged!", flush=True) | ||
merged = True | ||
break | ||
elif tot > 0: | ||
cfws_repo = gh.get_repo( | ||
"conda-forge/conda-forge-webservices" | ||
) | ||
workflow = cfws_repo.get_workflow("automerge.yml") | ||
workflow.create_dispatch( | ||
ref=branch, | ||
inputs={ | ||
"repo": ( | ||
"cf-autotick-bot-test-package-feedstock" | ||
), | ||
"sha": pr.head.sha, | ||
}, | ||
) | ||
|
||
if not merged: | ||
raise RuntimeError(f"PR {pr.number} was not merged!") | ||
|
||
finally: | ||
if not DEBUG: | ||
print("closing PR if it is open...", flush=True) | ||
if pr is not None and not pr.is_merged(): | ||
pr.edit(state="closed") | ||
|
||
print("deleting the test branch...", flush=True) | ||
_run_git_cmd("checkout", TEST_BASE_BRANCH) | ||
_run_git_cmd("branch", "-d", TEST_HEAD_BRANCH) | ||
_run_git_cmd("push", "-d", "origin", TEST_HEAD_BRANCH) |