ci: shift checks left (check-json, script tests, image pins) and name the meta-dependency check #527
No files matched your search
@@ -0,0 +1,12 @@
|
||||
# SPDX-FileCopyrightText: Defame1297 and contributors
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
"""The environment for a test's git fixture: no caller GIT_* and no user or system config."""
|
||||
|
||||
import os
|
||||
|
||||
|
||||
def isolated(**extra):
|
||||
"""A copy of os.environ for git: a hook exports GIT_DIR, which would point it at the real repo."""
|
||||
env = {k: v for k, v in os.environ.items() if not k.startswith("GIT_")}
|
||||
env.update(GIT_CONFIG_GLOBAL="/dev/null", GIT_CONFIG_NOSYSTEM="1", **extra)
|
||||
return env
|
||||
@@ -13,6 +13,7 @@ from unittest import mock
|
||||
SCRIPTS = pathlib.Path(__file__).resolve().parents[2] / "scripts"
|
||||
sys.path.insert(0, str(SCRIPTS))
|
||||
import check_bot_pr_diff as cbd
|
||||
import git_env
|
||||
from test_check_uv_lock import APM_NEW, APM_OLD, CLICK_OLD, UV_LOCK, uv_files
|
||||
|
||||
D1, D2 = "sha256:" + "a" * 64, "sha256:" + "b" * 64
|
||||
@@ -51,11 +52,7 @@ def run(cwd, *cmd):
|
||||
check=True,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
env={
|
||||
**os.environ,
|
||||
"GIT_CONFIG_GLOBAL": "/dev/null",
|
||||
"GIT_CONFIG_SYSTEM": "/dev/null",
|
||||
},
|
||||
env=git_env.isolated(),
|
||||
)
|
||||
|
||||
|
||||
@@ -475,6 +472,10 @@ class RuleTest(unittest.TestCase):
|
||||
|
||||
class RepoTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
# The gate runs git in-process, in the fixture's directory.
|
||||
patcher = mock.patch.dict(os.environ, git_env.isolated(), clear=True)
|
||||
patcher.start()
|
||||
self.addCleanup(patcher.stop)
|
||||
self.tmp = tempfile.TemporaryDirectory()
|
||||
self.repo = pathlib.Path(self.tmp.name)
|
||||
self.addCleanup(self.tmp.cleanup)
|
||||
@@ -579,7 +580,7 @@ class RepoTest(unittest.TestCase):
|
||||
def test_empty_head_ref_on_a_pull_request_fails_closed(self):
|
||||
self.write("roles/x/main.yml", "a\n")
|
||||
self.commit("anything")
|
||||
env = {**os.environ, "EVENT_NAME": "pull_request"}
|
||||
env = git_env.isolated(EVENT_NAME="pull_request")
|
||||
proc = subprocess.run(
|
||||
[sys.executable, str(SCRIPTS / "check_bot_pr_diff.py"), "", "main"],
|
||||
cwd=self.repo,
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
"""Run with: python3 -m unittest discover -s tests/scripts"""
|
||||
|
||||
import os
|
||||
import pathlib
|
||||
import subprocess
|
||||
import sys
|
||||
@@ -12,6 +11,7 @@ import unittest
|
||||
SCRIPTS = pathlib.Path(__file__).resolve().parents[2] / "scripts"
|
||||
sys.path.insert(0, str(SCRIPTS))
|
||||
import check_image_versions as civ
|
||||
import git_env
|
||||
|
||||
DIGEST = "sha256:" + "a" * 64
|
||||
JOB = f"ubuntu:24.04@{DIGEST}"
|
||||
@@ -67,11 +67,7 @@ def run(cwd, *cmd):
|
||||
check=True,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
env={
|
||||
**os.environ,
|
||||
"GIT_CONFIG_GLOBAL": "/dev/null",
|
||||
"GIT_CONFIG_SYSTEM": "/dev/null",
|
||||
},
|
||||
env=git_env.isolated(),
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
import git_env
|
||||
import yaml
|
||||
|
||||
REPO = pathlib.Path(__file__).resolve().parents[2]
|
||||
@@ -44,7 +45,11 @@ class CheckScenariosLoadCheckoutTest(unittest.TestCase):
|
||||
self.checkout = collection(self.ac_root)
|
||||
(self.checkout / "scripts").mkdir()
|
||||
# molecule's CLI finds the base config from the repository root, as in the real checkout
|
||||
subprocess.run(["git", "init", "-q", str(self.checkout)], check=True)
|
||||
subprocess.run(
|
||||
["git", "init", "-q", str(self.checkout)],
|
||||
check=True,
|
||||
env=git_env.isolated(),
|
||||
)
|
||||
self.base_config = self.checkout / ".config" / "molecule" / "config.yml"
|
||||
self.base_config.parent.mkdir(parents=True)
|
||||
self.base_config.write_text("prerun: false\n")
|
||||
|
||||
@@ -17,6 +17,7 @@ import yaml
|
||||
|
||||
REPO = pathlib.Path(__file__).resolve().parents[2]
|
||||
sys.path.insert(0, str(REPO / "scripts"))
|
||||
import git_env
|
||||
import select_molecule_scenarios as sel
|
||||
|
||||
ROLE_KEYS = {
|
||||
@@ -409,9 +410,6 @@ class MainTest(unittest.TestCase):
|
||||
(d / "molecule.yml").write_text("---\n")
|
||||
|
||||
def git(self, root, *args):
|
||||
# No GIT_* from the caller (a hook exports GIT_DIR), no user or system config.
|
||||
env = {k: v for k, v in os.environ.items() if not k.startswith("GIT_")}
|
||||
env.update(GIT_CONFIG_GLOBAL="/dev/null", GIT_CONFIG_NOSYSTEM="1")
|
||||
subprocess.run(
|
||||
[
|
||||
"git",
|
||||
@@ -427,7 +425,7 @@ class MainTest(unittest.TestCase):
|
||||
],
|
||||
check=True,
|
||||
capture_output=True,
|
||||
env=env,
|
||||
env=git_env.isolated(),
|
||||
)
|
||||
|
||||
def topic_repo(self, root, files):
|
||||
|
||||
Reference in new issue
Block a user