Repository navigation
Cut release-test wait time and recover Maven downloads #1166
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
997c586
Shard release-mode CI tests across three runners
mikolalysenko 398b5d1
Fall back to Apache when Maven Central downloads fail
mikolalysenko e903d7f
Pin Maven download checksums before using either mirror
mikolalysenko e78ad36
Avoid the release-job insertion conflict with CI scheduling
mikolalysenko 5c780cf
Keep Maven pin path filter separate from queued Gradle installer
mikolalysenko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,9 @@ | ||
| { | ||
| "3.6.3": "c35a1803a6e70a126e80b2b3ae33eed961f83ed74d18fcd16909b2d44d7dada3203f1ffe726c17ef8dcca2dcaa9fca676987befeadc9b9f759967a8cb77181c0", | ||
| "3.8.9": "4a490b7f331a0e7869b61da24600241e445339f2801ed94e32f835b63ed78597ad05ef8c1cce2501b4c2c3dcde30030eb395cd5756be739c20ac687ad6f82f0e", | ||
| "3.9.2": "900bdeeeae550d2d2b3920fe0e00e41b0069f32c019d566465015bdd1b3866395cbe016e22d95d25d51d3a5e614af2c83ec9b282d73309f644859bbad08b63db", | ||
| "3.9.3": "400fc5b6d000c158d5ee7937543faa06b6bda8408caa2444a9c947c21472fde0f0b64ac452b8cec8855d528c0335522ed5b6c8f77085811c7e29e1bedbb5daa2", | ||
| "3.9.4": "deaa39e16b2cf20f8cd7d232a1306344f04020e1f0fb28d35492606f647a60fe729cc40d3cba33e093a17aed41bd161fe1240556d0f1b80e773abd408686217e", | ||
| "3.9.16": "831a8591fe20c8243b1dbe7d71e3244f31d1665b0804b2e825e38cbbe5ce0cafb8338851f90780735568773e0a6cd07bbec107cda0b896b008b861075358b6f6", | ||
| "4.0.0-rc-6": "3fba58e1c345a5aa1dbacfa7aceaf7b1a0fa9626e368eec4814fa7a7ebf0fe74f0e41481faef77f95d8738f9c1365f918c8b8c94d7c28656f067db61a8af7f2e" | ||
| } |
This file contains hidden or 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,130 @@ | ||
| """Exercise the workflow installers against a fake CDN and Apache archive. | ||
|
|
||
| The archive bytes must match the committed pin before extraction, even if | ||
| the download origin serves a matching checksum for substituted bytes. | ||
| """ | ||
|
|
||
| import hashlib | ||
| import importlib.util | ||
| import io | ||
| import json | ||
| import os | ||
| from pathlib import Path | ||
| import re | ||
| import subprocess | ||
| import sys | ||
| import tarfile | ||
| import tempfile | ||
| import textwrap | ||
| import unittest | ||
|
|
||
| ROOT = Path(__file__).parents[2] | ||
| WORKFLOWS = ("ci.yml", "gradle-compatibility.yml") | ||
| VERSION = "3.9.16" | ||
| spec = importlib.util.spec_from_file_location("ci_maven_rows", Path(__file__).with_name("test_ci_vlt_rows.py")) | ||
| rows = importlib.util.module_from_spec(spec) | ||
| spec.loader.exec_module(rows) | ||
|
|
||
|
|
||
| def installer(workflow): | ||
| jobs = rows.jobs((ROOT / ".github/workflows" / workflow).read_text()) | ||
| step = next(text for job in jobs.values() for name, text in rows.steps(job) | ||
| if name.startswith("Install Maven")) | ||
| match = re.search(r"(?m)^ run: \|\n((?: .*\n|\n)+)", step + "\n") | ||
| return textwrap.dedent(match[1]) | ||
|
|
||
|
|
||
| def archive_bytes(contents): | ||
| data = io.BytesIO() | ||
| with tarfile.open(fileobj=data, mode="w:gz") as archive: | ||
| for name in ("mvn", "mvn.cmd"): | ||
| info = tarfile.TarInfo(f"apache-maven-{VERSION}/bin/{name}") | ||
| info.size = len(contents) | ||
| info.mode = 0o755 | ||
| archive.addfile(info, io.BytesIO(contents)) | ||
| return data.getvalue() | ||
|
|
||
|
|
||
| CURL = r''' | ||
| import hashlib, os, pathlib, sys | ||
| root = pathlib.Path(os.environ["FIXTURE_ROOT"]) | ||
| mode = os.environ["FIXTURE_MODE"] | ||
| url = next(a for a in sys.argv if a.startswith("https://")) | ||
| dest = pathlib.Path(sys.argv[sys.argv.index("-o") + 1]) | ||
| with (root / "requests").open("a") as log: | ||
| log.write(url + "\n") | ||
| if mode == "both-fail" or ("repo.maven.apache.org" in url and mode in ("fallback", "corrupt-fallback")): | ||
| dest.write_bytes(b"partial download") | ||
| sys.exit(22) | ||
| payload = (root / ("tampered.tgz" if mode.startswith("corrupt-") else "fixture.tgz")).read_bytes() | ||
| if url.endswith(".sha512"): | ||
| # An origin can replace both its tarball and its online digest. | ||
| payload = hashlib.sha512(payload).hexdigest().encode() | ||
| dest.write_bytes(payload) | ||
| ''' | ||
|
|
||
|
|
||
| class MavenDownload(unittest.TestCase): | ||
| def test_every_matrix_version_has_a_sha512_pin(self): | ||
| pins = json.loads((ROOT / "scripts/maven-sha512.json").read_text()) | ||
| for workflow in WORKFLOWS: | ||
| text = (ROOT / ".github/workflows" / workflow).read_text() | ||
| versions = re.findall(r"(?:maven|MAVEN_VERSION): '([^']+)'", text) | ||
| self.assertTrue(versions) | ||
| self.assertFalse(set(versions) - pins.keys(), f"unpinned Maven version in {workflow}") | ||
| for version, digest in pins.items(): | ||
| self.assertRegex(digest, r"^[0-9a-f]{128}$", version) | ||
|
|
||
| def test_workflow_downloads_fail_closed_before_extraction(self): | ||
| for workflow in WORKFLOWS: | ||
| script = installer(workflow) | ||
| for runner_os in ("Linux", "Windows"): | ||
| for mode in ("primary", "fallback", "corrupt-primary", "corrupt-fallback", "both-fail", "unpinned"): | ||
| with self.subTest(workflow=workflow, runner_os=runner_os, mode=mode): | ||
| self.check_installer(script, workflow, runner_os, mode) | ||
|
|
||
| def check_installer(self, script, workflow, runner_os, mode): | ||
| with tempfile.TemporaryDirectory(prefix="maven-download-") as directory: | ||
| work = Path(directory) | ||
| trusted = archive_bytes(b"trusted launcher\n") | ||
| (work / "fixture.tgz").write_bytes(trusted) | ||
|
mikolalysenko marked this conversation as resolved.
Dismissed
|
||
| (work / "tampered.tgz").write_bytes(archive_bytes(b"substituted launcher\n")) | ||
| (work / "scripts").mkdir() | ||
| pins = {} if mode == "unpinned" else {VERSION: hashlib.sha512(trusted).hexdigest()} | ||
| (work / "scripts/maven-sha512.json").write_text(json.dumps(pins)) | ||
| (work / "curl").write_text("#!" + sys.executable + "\n" + CURL) | ||
| (work / "curl").chmod(0o755) | ||
| (work / "python").symlink_to(sys.executable) | ||
| github_env = work / "github-env" | ||
| github_env.touch() | ||
| env = dict(os.environ, PATH=str(work) + os.pathsep + os.environ["PATH"], | ||
| FIXTURE_ROOT=str(work), FIXTURE_MODE=mode, RUNNER_TEMP=str(work), | ||
| RUNNER_OS=runner_os, MAVEN_VERSION=VERSION, GITHUB_ENV=str(github_env), | ||
| PYTHONOPTIMIZE="1") # Verification must not rely on assert. | ||
| result = subprocess.run(["bash", "--noprofile", "--norc", "-e", "-o", "pipefail", "-c", script], | ||
| cwd=work, env=env, capture_output=True, text=True, timeout=30) | ||
| requests = (work / "requests").read_text().splitlines() | ||
| self.assertTrue(requests[0].startswith("https://repo.maven.apache.org/")) | ||
| self.assertFalse(any(url.endswith(".sha512") for url in requests), requests) | ||
| fallback = mode in ("fallback", "corrupt-fallback", "both-fail") | ||
| self.assertEqual(len(requests), 2 if fallback else 1, requests) | ||
| if fallback: | ||
| self.assertEqual(requests[1], f"https://archive.apache.org/dist/maven/maven-3/{VERSION}/binaries/apache-maven-{VERSION}-bin.tar.gz") | ||
| if mode in ("primary", "fallback"): | ||
| self.assertEqual(result.returncode, 0, result.stdout + result.stderr) | ||
| launcher = work / f"apache-maven-{VERSION}/bin" / ("mvn.cmd" if runner_os == "Windows" else "mvn") | ||
| self.assertEqual(launcher.read_bytes(), b"trusted launcher\n") | ||
| self.assertIn(f"SOCKET_PATCH_MAVEN_E2E_MVN={launcher}\n", github_env.read_text()) | ||
| if workflow == "gradle-compatibility.yml": | ||
| self.assertIn(f"SOCKET_PATCH_MAVEN_E2E_VERSION={VERSION}\n", github_env.read_text()) | ||
| self.assertIn("SOCKET_PATCH_MAVEN_E2E_REQUIRED=1\n", github_env.read_text()) | ||
| else: | ||
| self.assertNotEqual(result.returncode, 0, result.stdout) | ||
| self.assertFalse((work / f"apache-maven-{VERSION}").exists()) | ||
| self.assertFalse(github_env.read_text()) | ||
| if mode.startswith("corrupt-"): | ||
| self.assertIn("SHA512 mismatch", result.stderr) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.