diff --git a/.gitea/CI_PERFORMANCE.md b/.gitea/CI_PERFORMANCE.md index 01a1ccf..e77a192 100644 --- a/.gitea/CI_PERFORMANCE.md +++ b/.gitea/CI_PERFORMANCE.md @@ -38,6 +38,15 @@ preserves nested and hidden runtime assets, and excludes the same debug files an optional workers omitted by packaging. The saved app, platform packages, compact metadata and validated release artifact all retain 30 days. +This host runs both Gitea and the runner. The workflows set +`CUTDEX_GITEA_INTERNAL_URL=http://127.0.0.1:3000` and override `ACTIONS_RESULTS_URL` +on artifact upload/download steps, so those transfers stay on the host instead of +looping through the public FRP tunnel. Release API uploads and byte verification +also use this loopback endpoint; tooling rewrites only the validated public Gitea +origin. The server's public URL remains `https://git.orangraph.com`, and the runner +registration is unchanged. These workflow labels require this shared-host layout; +configure a reachable private endpoint before using runners on other hosts. + Compare warm CI runs after the first cache fill. Measure checks, Android compile, Windows compile, packaging and artifact transfer separately. Total duration follows the slower platform branch, plus checks and final assembly; no fixed speedup is diff --git a/.gitea/actions/upload-artifact/action.yml b/.gitea/actions/upload-artifact/action.yml index 645bf42..a52892c 100644 --- a/.gitea/actions/upload-artifact/action.yml +++ b/.gitea/actions/upload-artifact/action.yml @@ -20,6 +20,8 @@ runs: id: first continue-on-error: true uses: https://github.com/actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 + env: + ACTIONS_RESULTS_URL: ${{ env.CUTDEX_GITEA_INTERNAL_URL }} with: name: ${{ inputs.name }} path: ${{ inputs.path }} @@ -37,6 +39,8 @@ runs: if: ${{ !cancelled() && steps.first.outcome == 'failure' }} continue-on-error: true uses: https://github.com/actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 + env: + ACTIONS_RESULTS_URL: ${{ env.CUTDEX_GITEA_INTERNAL_URL }} with: name: ${{ inputs.name }} path: ${{ inputs.path }} @@ -53,6 +57,8 @@ runs: id: third if: ${{ !cancelled() && steps.first.outcome == 'failure' && steps.second.outcome == 'failure' }} uses: https://github.com/actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 + env: + ACTIONS_RESULTS_URL: ${{ env.CUTDEX_GITEA_INTERNAL_URL }} with: name: ${{ inputs.name }} path: ${{ inputs.path }} diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 0471aae..d958953 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -13,6 +13,7 @@ concurrency: cancel-in-progress: true env: PYTHONUTF8: '1' + CUTDEX_GITEA_INTERNAL_URL: http://127.0.0.1:3000 GIT_CONFIG_COUNT: '2' GIT_CONFIG_KEY_0: core.autocrlf GIT_CONFIG_VALUE_0: 'false' @@ -142,6 +143,8 @@ jobs: persist-credentials: false - name: Download saved Windows app uses: https://github.com/actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 + env: + ACTIONS_RESULTS_URL: ${{ env.CUTDEX_GITEA_INTERNAL_URL }} with: name: cutdex-windows-app path: build/windows/x64/production/runner/Release/ @@ -177,11 +180,15 @@ jobs: persist-credentials: false - name: Download Android CI artifact uses: https://github.com/actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 + env: + ACTIONS_RESULTS_URL: ${{ env.CUTDEX_GITEA_INTERNAL_URL }} with: name: cutdex-android-build path: build/app/outputs/flutter-apk/ - name: Download Windows CI artifact uses: https://github.com/actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 + env: + ACTIONS_RESULTS_URL: ${{ env.CUTDEX_GITEA_INTERNAL_URL }} with: name: cutdex-windows-build path: .build/windows-packages/ diff --git a/.gitea/workflows/release.yml b/.gitea/workflows/release.yml index 536b701..a735b25 100644 --- a/.gitea/workflows/release.yml +++ b/.gitea/workflows/release.yml @@ -18,6 +18,7 @@ defaults: shell: pwsh env: PYTHONUTF8: '1' + CUTDEX_GITEA_INTERNAL_URL: http://127.0.0.1:3000 GIT_CONFIG_COUNT: '2' GIT_CONFIG_KEY_0: core.autocrlf GIT_CONFIG_VALUE_0: 'false' diff --git a/tool/gitea/release_transport.py b/tool/gitea/release_transport.py index 5bc819a..d9e0f2b 100644 --- a/tool/gitea/release_transport.py +++ b/tool/gitea/release_transport.py @@ -15,6 +15,19 @@ SERVER = 'https://git.orangraph.com' RETRY_DELAYS = (5, 15) +def transport_url(url): + """Route this host's Gitea traffic locally when the runner opts in.""" + internal = os.environ.get('CUTDEX_GITEA_INTERNAL_URL', '').rstrip('/') + if not internal: + return url + if internal != 'http://127.0.0.1:3000': + raise ValueError('Unexpected internal Gitea endpoint') + parsed = urllib.parse.urlparse(url) + if parsed.scheme != 'https' or parsed.netloc != 'git.orangraph.com': + raise ValueError('Unexpected Gitea transport origin') + return urllib.parse.urlunparse(parsed._replace(scheme='http', netloc='127.0.0.1:3000')) + + def transient(error): if isinstance(error, urllib.error.HTTPError): if error.code == 404 and error.headers.get('Content-Type', '').split(';')[0].lower() == 'text/html': @@ -45,7 +58,7 @@ def request(url, data=None, method=None, content_type='application/json'): headers['Content-Type'] = content_type if isinstance(data, dict): data = json.dumps(data).encode() - req = urllib.request.Request(url, data=data, headers=headers, method=method) + req = urllib.request.Request(transport_url(url), data=data, headers=headers, method=method) with urllib.request.urlopen(req, timeout=300) as response: body = response.read() return json.loads(body) if body and 'application/json' in response.headers.get('Content-Type', '') else body @@ -61,7 +74,7 @@ def attachment_url(asset): def fingerprint(asset): """Hash one remote attachment in chunks, keeping memory usage bounded.""" sha256, sha1, size = hashlib.sha256(), hashlib.sha1(), 0 - req = urllib.request.Request(attachment_url(asset), + req = urllib.request.Request(transport_url(attachment_url(asset)), headers={'Authorization': 'token ' + os.environ['GITEA_TOKEN']}) with urllib.request.urlopen(req, timeout=300) as response: while chunk := response.read(1024 * 1024): diff --git a/tool/gitea/test_transfer_tools.py b/tool/gitea/test_transfer_tools.py index 39798bd..2545d13 100644 --- a/tool/gitea/test_transfer_tools.py +++ b/tool/gitea/test_transfer_tools.py @@ -9,6 +9,51 @@ import release_transport as transfers class TransferToolsTests(unittest.TestCase): + def setUp(self): + environment = patch.dict('os.environ', {'CUTDEX_GITEA_INTERNAL_URL': ''}) + environment.start() + self.addCleanup(environment.stop) + + def test_local_api_transport_preserves_authenticated_request_and_public_identity(self): + class Response(io.BytesIO): + headers = {'Content-Type': 'application/json'} + + with patch.dict('os.environ', {'CUTDEX_GITEA_INTERNAL_URL': 'http://127.0.0.1:3000/', + 'GITEA_TOKEN': 'test-token'}), \ + patch.object(transfers.urllib.request, 'urlopen', return_value=Response(b'{"id":3}')) as open_url: + result = transfers.request(transfers.SERVER + '/api/v1/releases?name=a%20b', + data=b'package', method='POST', content_type='application/octet-stream') + request = open_url.call_args.args[0] + self.assertEqual(result, {'id': 3}) + self.assertEqual(request.full_url, 'http://127.0.0.1:3000/api/v1/releases?name=a%20b') + self.assertEqual(request.get_method(), 'POST') + self.assertEqual(request.get_header('Authorization'), 'token test-token') + self.assertEqual(request.data, b'package') + self.assertEqual(transfers.SERVER, 'https://git.orangraph.com') + + def test_local_verification_routes_validated_attachment_without_changing_its_public_url(self): + asset = {'browser_download_url': 'https://git.orangraph.com/attachments/example'} + with patch.dict('os.environ', {'CUTDEX_GITEA_INTERNAL_URL': 'http://127.0.0.1:3000', + 'GITEA_TOKEN': 'test-token'}), \ + patch.object(transfers.urllib.request, 'urlopen', return_value=io.BytesIO(b'app')) as open_url: + result = transfers.fingerprint(asset) + self.assertEqual(open_url.call_args.args[0].full_url, 'http://127.0.0.1:3000/attachments/example') + self.assertEqual(result['sha256'], hashlib.sha256(b'app').hexdigest()) + self.assertEqual(asset['browser_download_url'], 'https://git.orangraph.com/attachments/example') + + def test_local_transport_rejects_unexpected_endpoint_or_origin_before_sending_credentials(self): + for internal, url, message in [ + ('http://example.com:3000', transfers.SERVER + '/api/v1/releases', 'internal Gitea endpoint'), + ('http://127.0.0.1:3000', 'https://example.com/file', 'transport origin'), + ('http://127.0.0.1:3000', 'http://git.orangraph.com/file', 'transport origin'), + ]: + with self.subTest(internal=internal, url=url), \ + patch.dict('os.environ', {'CUTDEX_GITEA_INTERNAL_URL': internal, 'GITEA_TOKEN': 'test-token'}), \ + patch.object(transfers.urllib.request, 'urlopen') as open_url: + with self.assertRaisesRegex(ValueError, message): + transfers.request(url) + open_url.assert_not_called() + def test_frp_tunnel_not_found_page_is_retried_as_a_temporary_failure(self): calls = 0