Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c992bf71bd
|
||
|
|
a14e8f9b24 | ||
|
|
83611872a3 | ||
|
|
30c4e0e85c |
No files matched your search
@@ -12,7 +12,7 @@ on:
|
||||
required: true
|
||||
type: string
|
||||
smoke_evidence:
|
||||
description: github (legacy default) or circle (requires consumer adapter and Circle credential)
|
||||
description: github (legacy default) or circle (public API evidence; optional credential)
|
||||
type: string
|
||||
default: github
|
||||
circle_workflow_id:
|
||||
@@ -494,9 +494,12 @@ jobs:
|
||||
|
||||
def circle(path):
|
||||
token = os.environ.get('CIRCLECI_TOKEN')
|
||||
require(token, 'CIRCLECI_TOKEN is required for Circle evidence mode')
|
||||
# Public projects expose these records without authentication.
|
||||
headers = {'Accept': 'application/json'}
|
||||
if token:
|
||||
headers['Circle-Token'] = token
|
||||
request = urllib.request.Request('https://circleci.com/api/v2/' + path,
|
||||
headers={'Circle-Token': token, 'Accept': 'application/json'})
|
||||
headers=headers)
|
||||
with urllib.request.build_opener(NoRedirect).open(request, timeout=30) as response:
|
||||
raw = response.read(2_000_001)
|
||||
require(len(raw) <= 2_000_000, 'Evidence response exceeds bound')
|
||||
|
||||
@@ -318,7 +318,7 @@
|
||||
"smoke_evidence": {
|
||||
"description": "Evidence provider; github preserves the original Smoke workflow validation",
|
||||
"type": "choice",
|
||||
"default": "github",
|
||||
"default": "circle",
|
||||
"options": [
|
||||
"github",
|
||||
"circle"
|
||||
|
||||
@@ -86,9 +86,12 @@ class NoRedirect(urllib.request.HTTPRedirectHandler):
|
||||
|
||||
def circle(path):
|
||||
token = os.environ.get('CIRCLECI_TOKEN')
|
||||
require(token, 'CIRCLECI_TOKEN is required for Circle evidence mode')
|
||||
# Public projects expose these records without authentication.
|
||||
headers = {'Accept': 'application/json'}
|
||||
if token:
|
||||
headers['Circle-Token'] = token
|
||||
request = urllib.request.Request('https://circleci.com/api/v2/' + path,
|
||||
headers={'Circle-Token': token, 'Accept': 'application/json'})
|
||||
headers=headers)
|
||||
with urllib.request.build_opener(NoRedirect).open(request, timeout=30) as response:
|
||||
raw = response.read(2_000_001)
|
||||
require(len(raw) <= 2_000_000, 'Evidence response exceeds bound')
|
||||
|
||||
@@ -35,7 +35,8 @@ class AllReleaseCallerTests(unittest.TestCase):
|
||||
for name in inputs:
|
||||
self.assertEqual('${{ inputs.' + name + ' }}', passed[name])
|
||||
self.assertEqual('string', self.contract['inputs'][name]['type'])
|
||||
self.assertEqual('github', inputs['smoke_evidence']['default'])
|
||||
# Migrated consumers no longer own a separate GitHub Smoke workflow.
|
||||
self.assertEqual('circle', inputs['smoke_evidence']['default'])
|
||||
self.assertEqual(['github', 'circle'], inputs['smoke_evidence']['options'])
|
||||
self.assertFalse(inputs['smoke_run_id']['required'])
|
||||
self.assertFalse(inputs['circle_workflow_id']['required'])
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
"""Run the workflow's publication shell with a recording CLI, never GitHub."""
|
||||
|
||||
import json
|
||||
import os
|
||||
import subprocess
|
||||
import tempfile
|
||||
import yaml
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parent.parent
|
||||
|
||||
|
||||
def workflow_shell(name):
|
||||
worker = yaml.safe_load((ROOT / ".github/workflows/qqq-all-release.yml").read_text())
|
||||
return next(step["run"] for step in worker["jobs"]["release"]["steps"]
|
||||
if step.get("name") == name)
|
||||
|
||||
|
||||
class ReleaseWorkflowTest(unittest.TestCase):
|
||||
def test_rc_is_prerelease_never_latest_and_ga_keeps_existing_release_behavior(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
root = Path(directory)
|
||||
gh = root / "gh"
|
||||
gh.write_text("#!/usr/bin/env python3\nimport json, os, sys\n"
|
||||
"with open(os.environ['CALLS'], 'w') as f: json.dump(sys.argv[1:], f)\n")
|
||||
gh.chmod(0o755)
|
||||
calls = root / "calls.json"
|
||||
for version in ("4.1.0", "4.1.0-RC.1", "4.1.0-RC.2"):
|
||||
calls.unlink(missing_ok=True)
|
||||
environment = {**os.environ, "PATH": directory + os.pathsep + os.environ["PATH"],
|
||||
"CALLS": str(calls), "VERSION": version, "TAG": version,
|
||||
"RUNNER_TEMP": directory, "GITHUB_REPOSITORY": "QRun-IO/qqq-all"}
|
||||
result = subprocess.run(["bash", "-c", workflow_shell("Publish GitHub release with Compose bundle")],
|
||||
env=environment, capture_output=True, text=True)
|
||||
if version == "4.1.0-RC.2":
|
||||
self.assertNotEqual(0, result.returncode)
|
||||
self.assertFalse(calls.exists())
|
||||
continue
|
||||
self.assertEqual(0, result.returncode, result.stderr)
|
||||
args = json.loads(calls.read_text())
|
||||
self.assertEqual(["release", "create", version], args[:3])
|
||||
self.assertIn(str(root / ("qqq-all-" + version + ".tar.gz")), args)
|
||||
self.assertIn("--verify-tag", args)
|
||||
if version == "4.1.0-RC.1":
|
||||
self.assertIn("--prerelease", args)
|
||||
self.assertIn("--latest=false", args)
|
||||
else:
|
||||
self.assertNotIn("--prerelease", args)
|
||||
self.assertNotIn("--latest=false", args)
|
||||
@@ -1,7 +1,11 @@
|
||||
import copy
|
||||
import importlib.util
|
||||
import io
|
||||
import os
|
||||
from pathlib import Path
|
||||
import unittest
|
||||
from unittest import mock
|
||||
import urllib.error
|
||||
import yaml
|
||||
|
||||
ROOT = Path(__file__).parents[1]
|
||||
@@ -25,6 +29,27 @@ def fixture():
|
||||
|
||||
|
||||
class EvidenceTests(unittest.TestCase):
|
||||
def test_public_evidence_needs_no_credential_and_optional_token_stays_on_circle(self):
|
||||
for token in ('', 'fixture-token'):
|
||||
opener = mock.Mock()
|
||||
opener.open.return_value = io.BytesIO(b'{"status":"success"}')
|
||||
with mock.patch.dict(os.environ, {'CIRCLECI_TOKEN': token}), \
|
||||
mock.patch.object(v.urllib.request, 'build_opener', return_value=opener):
|
||||
self.assertEqual(v.circle('workflow/' + W), {'status': 'success'})
|
||||
request = opener.open.call_args.args[0]
|
||||
self.assertEqual(request.full_url, 'https://circleci.com/api/v2/workflow/' + W)
|
||||
self.assertEqual(request.get_header('Circle-token'), token or None)
|
||||
|
||||
def test_unavailable_public_evidence_is_not_a_success(self):
|
||||
opener = mock.Mock()
|
||||
opener.open.side_effect = urllib.error.HTTPError('https://circleci.com', 403, 'Forbidden', {}, None)
|
||||
with mock.patch.dict(os.environ, {'CIRCLECI_TOKEN': ''}), \
|
||||
mock.patch.object(v.urllib.request, 'build_opener', return_value=opener), \
|
||||
self.assertRaises(OSError):
|
||||
v.circle('workflow/' + W)
|
||||
with self.assertRaises(v.EvidenceError):
|
||||
v.NoRedirect().redirect_request(None, None, 302, '', {}, 'https://other.example/')
|
||||
|
||||
def test_success_returns_real_circle_evidence_not_fake_github_run(self):
|
||||
evidence = v.validate(SHA, W, *fixture())
|
||||
self.assertEqual('qqq-all-circle-smoke/v1', evidence['schema'])
|
||||
|
||||
Reference in new issue
Block a user