9 Commits
  • Merge local CI archive redirect fix
    PR CI #61 passed; verified actual archive download remains on loopback. Keep unpublished version 0.1.1+2.
  • Merge CI optimization and Windows update release workflow
    Verified final PR CI #58; retain version 0.1.1+2 and publish v0.1.1 only after successful main CI.
7 changed files with 197 additions and 7 deletions

No files matched your search

+24
View File
@@ -14,6 +14,10 @@ enabled for CI. Do not clear these caches between runs. Each job must have its o
checkout; do not share a Flutter `build/` or `.dart_tool/` directory between jobs.
With an ephemeral runner, these user directories must be persisted separately.
Build commands keep Flutter's default Pub preparation after the explicit locked
resolution. Do not use `--no-pub`: Flutter also regenerates release plugin
registrants in that preparation, removing dev-only plugins such as integration_test.
The runner needs at least two execution slots. The local runner configuration at
`D:/workspace/gitea-stack/runner/config.yaml` currently has `capacity: 2`. The host
has 12 logical processors and approximately 16 GB RAM; the Android job retains its
@@ -24,6 +28,9 @@ the runner user's `%LOCALAPPDATA%/Cutdex/ci-tools/`. Later builds reuse them aft
version checks. Python interpreter identity and tool versions isolate the cache,
and a mutex protects installation across concurrent workflows. .NET setup remains
in the Windows packaging job to provide SDK 10 and the runtime required by `vpk`.
The .NET installation uses the runner user's `Cutdex/ci-tools/dotnet` directory
through `DOTNET_INSTALL_DIR` and `DOTNET_ROOT`, so setup needs no administrator
access and later jobs reuse the installed SDK and runtime.
The Windows build verifies that the resolved deskup native SDK matches the pinned
Velopack version before saving the app. Packaging imports no Flutter package
configuration and independently verifies the installed vpk version.
@@ -34,6 +41,21 @@ 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.
Checkout uses the same endpoint through its `github-server-url` input, retaining
the requested commit/tag and disabling persisted credentials. Release requests
retain the public Host header so Gitea response links pass the public-origin checks.
CI artifact ZIP download requests retain the loopback Host instead: Gitea returns
a signed redirect to the raw archive, and its Host must remain local for that
second request to avoid the public tunnel. Release attachment links stay public.
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
@@ -56,6 +78,8 @@ the build job must still be rerun; it has no saved app to restore.
Release attachment uploads retry temporary network errors, HTTP 408/429 and
500/502/503/504 up to three POST attempts per file, also with 5/15-second delays.
The specific FRP HTML "Not Found" page observed during tunnel reconnection is
also treated as temporary; ordinary Gitea API or HTML 404 responses still fail.
Before retrying a POST, the uploader checks whether Gitea already saved the named
attachment, including after the final response is lost. This avoids duplicate
uploads after a timeout. Authorization, invalid-input and other permanent errors
@@ -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 }}
+20 -2
View File
@@ -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'
@@ -30,6 +31,7 @@ jobs:
uses: https://github.com/actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
with:
persist-credentials: false
github-server-url: ${{ env.CUTDEX_GITEA_INTERNAL_URL }}
- name: Configure persistent build caches
run: ./tool/gitea/prepare-build-cache.ps1
- name: Verify Flutter version and configure Java
@@ -63,6 +65,7 @@ jobs:
uses: https://github.com/actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
with:
persist-credentials: false
github-server-url: ${{ env.CUTDEX_GITEA_INTERNAL_URL }}
- name: Configure persistent build caches
run: ./tool/gitea/prepare-build-cache.ps1
- name: Verify Flutter version and configure Java
@@ -79,7 +82,7 @@ jobs:
$properties = [IO.File]::ReadAllText($file).Replace('-Xmx8G', '-Xmx3G').Replace('MaxMetaspaceSize=4G', 'MaxMetaspaceSize=768m')
[IO.File]::WriteAllText($file, $properties + "`norg.gradle.workers.max=4`norg.gradle.caching=true`n")
- name: Build production Android APK
run: flutter build apk --no-pub --release --flavor production --target-platform android-arm64,android-x64
run: flutter build apk --release --flavor production --target-platform android-arm64,android-x64
- name: Upload Android CI artifact
uses: ./.gitea/actions/upload-artifact
with:
@@ -100,6 +103,7 @@ jobs:
uses: https://github.com/actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
with:
persist-credentials: false
github-server-url: ${{ env.CUTDEX_GITEA_INTERNAL_URL }}
- name: Configure persistent build caches
run: ./tool/gitea/prepare-build-cache.ps1
- name: Verify Flutter version
@@ -111,7 +115,7 @@ jobs:
- name: Build production Windows app
run: |
Remove-Item Env:CUTDEX_WINDOWS_PATH, Env:CUTDEX_WINDOWS_PACKAGE_PATH -ErrorAction SilentlyContinue
flutter build windows --no-pub --release --flavor production
flutter build windows --release --flavor production
if ($LASTEXITCODE -ne 0) { throw 'Windows build failed.' }
- name: Verify native SDK matches pinned packaging tools
run: |
@@ -140,11 +144,20 @@ jobs:
uses: https://github.com/actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
with:
persist-credentials: false
github-server-url: ${{ env.CUTDEX_GITEA_INTERNAL_URL }}
- 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/
- name: Configure user .NET installation
run: |
$directory = Join-Path $env:LOCALAPPDATA 'Cutdex/ci-tools/dotnet'
[IO.Directory]::CreateDirectory($directory) | Out-Null
"DOTNET_INSTALL_DIR=$directory" | Out-File -LiteralPath $env:GITHUB_ENV -Encoding utf8 -Append
"DOTNET_ROOT=$directory" | Out-File -LiteralPath $env:GITHUB_ENV -Encoding utf8 -Append
- name: Set up .NET SDK
uses: https://github.com/actions/setup-dotnet@26b0ec14cb23fa6904739307f278c14f94c95bf1
with:
@@ -175,13 +188,18 @@ jobs:
uses: https://github.com/actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
with:
persist-credentials: false
github-server-url: ${{ env.CUTDEX_GITEA_INTERNAL_URL }}
- 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/
+5
View File
@@ -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'
@@ -44,6 +45,7 @@ jobs:
with:
ref: ${{ gitea.event.inputs.tag || gitea.ref_name }}
persist-credentials: false
github-server-url: ${{ env.CUTDEX_GITEA_INTERNAL_URL }}
- name: Select successful CI and prepare draft
id: draft
run: |
@@ -68,6 +70,7 @@ jobs:
with:
ref: ${{ needs.prepare.outputs.sha }}
persist-credentials: false
github-server-url: ${{ env.CUTDEX_GITEA_INTERNAL_URL }}
- name: Download Android CI artifact
run: |
python tool/gitea/stage-release.py fetch-android --path .build/android
@@ -93,6 +96,7 @@ jobs:
with:
ref: ${{ needs.prepare.outputs.sha }}
persist-credentials: false
github-server-url: ${{ env.CUTDEX_GITEA_INTERNAL_URL }}
- name: Download Windows CI artifact
run: |
python tool/gitea/stage-release.py fetch-windows --path .build/windows
@@ -118,6 +122,7 @@ jobs:
with:
ref: ${{ needs.prepare.outputs.sha }}
persist-credentials: false
github-server-url: ${{ env.CUTDEX_GITEA_INTERNAL_URL }}
- name: Download release verification metadata
run: |
python tool/gitea/stage-release.py fetch-release --path dist
+3 -2
View File
@@ -126,9 +126,10 @@ void main() {
.closeSource();
}
await access.dispose();
// UI/provider disposal owns the project; allow its async cleanup to finish.
// Provider disposal starts async cleanup without waiting for it. Close the
// workspace explicitly before deleting files, especially on Windows.
await container.read(projectsProvider.notifier).prepareToQuit();
container.dispose();
await Future<void>.delayed(const Duration(milliseconds: 50));
await root.delete(recursive: true);
messenger.setMockMethodCallHandler(native, null);
messenger.setMockMethodCallHandler(events, null);
+35 -3
View File
@@ -4,6 +4,7 @@ from concurrent.futures import ThreadPoolExecutor
import http.client
import json
import os
import re
import sys
import time
import urllib.error
@@ -15,8 +16,26 @@ 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':
body = error.read(64 * 1024).lower()
# FRP returns this page while the vhost tunnel is unavailable.
# A normal Gitea API 404 remains a permanent error.
return b'github.com/fatedier/frp' in body and b'not found' in body
return error.code in {408, 429, 500, 502, 503, 504}
return isinstance(error, (urllib.error.URLError, TimeoutError, ConnectionError,
http.client.IncompleteRead))
@@ -35,12 +54,21 @@ def retry_read(operation):
def request(url, data=None, method=None, content_type='application/json'):
endpoint = transport_url(url)
headers = {'Authorization': 'token ' + os.environ['GITEA_TOKEN']}
local_archive = (data is None and method in (None, 'GET')
and re.fullmatch(r'/api/v1/repos/[^/]+/[^/]+/actions/artifacts/\d+/zip',
urllib.parse.urlparse(url).path))
if endpoint != url and not local_archive:
# Gitea constructs response links from Host, even when reached locally.
# CI ZIP downloads redirect to a signed raw URL. Keep their local Host
# so urllib follows that redirect locally instead of returning to FRP.
headers['Host'] = 'git.orangraph.com'
if data is not None:
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(endpoint, 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
@@ -56,8 +84,12 @@ 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),
headers={'Authorization': 'token ' + os.environ['GITEA_TOKEN']})
url = attachment_url(asset)
endpoint = transport_url(url)
headers = {'Authorization': 'token ' + os.environ['GITEA_TOKEN']}
if endpoint != url:
headers['Host'] = 'git.orangraph.com'
req = urllib.request.Request(endpoint, headers=headers)
with urllib.request.urlopen(req, timeout=300) as response:
while chunk := response.read(1024 * 1024):
sha256.update(chunk)
+104
View File
@@ -9,6 +9,110 @@ 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.get_header('Host'), 'git.orangraph.com')
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(open_url.call_args.args[0].get_header('Host'), 'git.orangraph.com')
self.assertEqual(result['sha256'], hashlib.sha256(b'app').hexdigest())
self.assertEqual(asset['browser_download_url'], 'https://git.orangraph.com/attachments/example')
def test_local_ci_archive_request_keeps_local_host_for_signed_redirect(self):
class Response(io.BytesIO):
headers = {'Content-Type': 'application/zip'}
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'archive')) as open_url:
result = transfers.request(transfers.SERVER + '/api/v1/repos/owner/repo/actions/artifacts/40/zip')
request = open_url.call_args.args[0]
self.assertEqual(result, b'archive')
self.assertEqual(request.full_url, 'http://127.0.0.1:3000/api/v1/repos/owner/repo/actions/artifacts/40/zip')
self.assertIsNone(request.get_header('Host'))
self.assertEqual(request.get_header('Authorization'), 'token test-token')
def test_local_host_exception_does_not_change_other_api_response_links(self):
for path, method in [
('/api/v1/repos/owner/repo/actions/artifacts/40/zip', 'POST'),
('/api/v1/repos/owner/repo/actions/artifacts/not-a-number/zip', None),
('/api/v1/repos/owner/repo/releases/40/zip', None),
]:
class Response(io.BytesIO):
headers = {'Content-Type': 'application/json'}
with self.subTest(path=path, method=method), \
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'{}')) as open_url:
transfers.request(transfers.SERVER + path, method=method)
self.assertEqual(open_url.call_args.args[0].get_header('Host'), 'git.orangraph.com')
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
def transport(url, data=None, method=None, content_type=None):
nonlocal calls
if method is None:
return []
calls += 1
if calls == 1:
body = b'<h1>Not Found</h1><a href="https://github.com/fatedier/frp">frp</a>'
raise urllib.error.HTTPError(url, 404, 'Not Found',
{'Content-Type': 'text/html; charset=utf-8'}, io.BytesIO(body))
return {}
with patch.object(transfers.time, 'sleep') as sleep:
transfers.upload_contents('base', 3, {'app.zip': b'app'}, transport=transport)
self.assertEqual(calls, 2)
sleep.assert_called_once_with(5)
def test_ordinary_html_not_found_and_json_api_errors_are_not_retried(self):
for content_type, body in [('text/html', b'<h1>Not Found</h1>'),
('application/json', b'Not Found github.com/fatedier/frp')]:
with self.subTest(content_type=content_type):
error = urllib.error.HTTPError('url', 404, 'Not Found',
{'Content-Type': content_type}, io.BytesIO(body))
self.assertFalse(transfers.transient(error))
def test_transient_upload_failure_retries_without_restarting_other_files(self):
calls = []