diff --git a/.github/sdk-release.json b/.github/sdk-release.json new file mode 100644 index 0000000..46a681e --- /dev/null +++ b/.github/sdk-release.json @@ -0,0 +1,3 @@ +{ + "engine_commit": "8fd3e8780c985721730855396de987e59e268fcf" +} diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b2b3295..14e6586 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,6 +1,9 @@ # SPDX-License-Identifier: AGPL-3.0-only name: Build and publish binary SDKs on: + push: + branches: [main] + paths: ['.github/sdk-release.json'] workflow_dispatch: inputs: engine_commit: @@ -9,11 +12,39 @@ on: permissions: contents: read concurrency: - group: sdk-${{ inputs.engine_commit }} + group: sdk-${{ inputs.engine_commit || github.sha }} cancel-in-progress: false jobs: - build: + request: if: github.ref == 'refs/heads/main' + runs-on: ubuntu-22.04 + outputs: + commit: ${{ steps.revision.outputs.commit }} + steps: + - uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5 + with: + fetch-depth: 0 + persist-credentials: false + - uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6 + with: + python-version: '3.12' + - name: Audit the reviewed release request + run: python release.py check-repository + - name: Resolve the requested engine revision + id: revision + env: + REQUESTED_ENGINE_COMMIT: ${{ inputs.engine_commit }} + REQUEST_EVENT: ${{ github.event_name }} + shell: python + run: | + import os + from release import SDKRelease + override = os.environ['REQUESTED_ENGINE_COMMIT'] if os.environ['REQUEST_EVENT'] == 'workflow_dispatch' else None + commit = SDKRelease.requested_commit('.', override) + with open(os.environ['GITHUB_OUTPUT'], 'a') as output: + output.write('commit=' + commit + '\n') + build: + needs: request strategy: fail-fast: false matrix: @@ -26,7 +57,7 @@ jobs: target: macos-universal runs-on: ${{ matrix.os }} env: - ENGINE_COMMIT: ${{ inputs.engine_commit }} + ENGINE_COMMIT: ${{ needs.request.outputs.commit }} SDK_TARGET: ${{ matrix.target }} steps: - uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5 @@ -46,7 +77,7 @@ jobs: uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5 with: repository: RakuenSoftware/wol-engine - ref: runtime-${{ inputs.engine_commit }} + ref: runtime-${{ needs.request.outputs.commit }} token: ${{ secrets.ENGINE_SOURCE_TOKEN }} path: private-engine submodules: recursive @@ -105,12 +136,12 @@ jobs: if-no-files-found: error retention-days: 7 publish: - needs: build + needs: [request, build] runs-on: ubuntu-22.04 permissions: contents: write env: - ENGINE_COMMIT: ${{ inputs.engine_commit }} + ENGINE_COMMIT: ${{ needs.request.outputs.commit }} steps: - uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5 with: diff --git a/README.md b/README.md index 8b46365..1a8491a 100644 --- a/README.md +++ b/README.md @@ -11,8 +11,9 @@ repository's Releases page. - Public Git history contains only the explicitly allowed automation, tests, documentation and licence files. The audit checks all reachable history, so deleting a forbidden file in a later commit does not make it acceptable. -- Only a manual run of the workflow on `main` can access the source credential. - Pull request checks never receive it. Maintainers who can change `main` or +- Merging a reviewed change to `.github/sdk-release.json` into `main` starts + the native release builds. Manual runs on `main` are also available. + Pull request checks never receive the source credential. Maintainers who can change `main` or workflows are trusted with this credential; review those changes accordingly. - Each fresh GitHub-hosted Linux, Windows and Mac runner temporarily checks out an exact private `runtime-<40-character SHA>` tag into a separate sibling @@ -47,7 +48,13 @@ for software that users execute. workflow inputs, commits or logs. Keep automatic pull request reviews enabled. 3. Merge this repository's reviewed automation to `main`. Create a private engine tag `runtime-` for the reviewed source to build. -4. Run **Build and publish binary SDKs** on `main` with that exact commit SHA. +4. Open a PR updating `.github/sdk-release.json` to that exact commit SHA. + The PR validates the request and publication policy without private source + access. Merging it into `main` automatically starts all three native builds. + This repository's initial request selects the already-tagged engine revision + `8fd3e8780c985721730855396de987e59e268fcf`. + Manual **Build and publish binary SDKs** runs on `main` remain available for + retries, using the same exact commit SHA. All three native-host SDK jobs must pass. The release contains three ZIP archives and their checksum records; GitHub's automatic source archives contain only this public automation repository. diff --git a/release.py b/release.py index ba93139..6ecb59f 100644 --- a/release.py +++ b/release.py @@ -20,15 +20,28 @@ class SDKRelease: "windows-x64": ("windows", "x86_64", "dll"), "macos-universal": ("macos", "universal", "dylib")} PUBLIC_FILES = {"LICENSE", "README.md", "SECURITY.md", "AGENTS.md", ".gitignore", "release.py", - "test_release.py", ".github/workflows/build.yml", ".github/workflows/audit.yml"} + "test_release.py", ".github/sdk-release.json", ".github/workflows/build.yml", ".github/workflows/audit.yml"} FORBIDDEN = {".c", ".cpp", ".cc", ".cxx", ".h", ".hpp", ".hxx", ".gd", ".gdshader", ".gdshaderinc", ".glsl", ".hlsl", ".shader", ".pdb", ".snupkg", ".csproj", ".sln", ".map", ".py", ".sh", ".ps1", ".js", ".ts", ".rs", ".log"} SOURCE_TEXT = re.compile(rb'(?m)^\s*(?:namespace\s+Wol\.Engine\b|(?:public|internal)\s+(?:(?:partial|sealed|static|abstract)\s+)*(?:class|struct|interface|record)\s+\w+|shader_type\s+\w+\s*;|void\s+(?:vertex|fragment)\s*\(|#include\s*[<"])') SECRET_TEXT = re.compile(rb'(?:-----BEGIN (?:OPENSSH |RSA |EC )?PRIVATE KEY-----|github_pat_[A-Za-z0-9_]{20,}|gh[pousr]_[A-Za-z0-9_]{20,})') + @classmethod + def requested_commit(cls, root, override=None): + if override is None: + request = json.loads((Path(root) / ".github/sdk-release.json").read_text()) + if not isinstance(request, dict) or set(request) != {"engine_commit"}: + raise ValueError("Unexpected release request fields") + override = request["engine_commit"] + if not isinstance(override, str) or not re.fullmatch(r"[0-9a-f]{40}", override): + raise ValueError("Release requests require a full engine commit") + return override + @classmethod def check_repository(cls, root): root = Path(root) + if (root / ".github/sdk-release.json").exists(): + cls.requested_commit(root) paths = set(subprocess.check_output(["git", "ls-files", "-z"], cwd=root).decode().split("\0")) - {""} revisions = subprocess.check_output(["git", "rev-list", "--all"], cwd=root).decode().splitlines() for revision in revisions: diff --git a/test_release.py b/test_release.py index 0712e60..3d32928 100644 --- a/test_release.py +++ b/test_release.py @@ -91,6 +91,22 @@ def test_checksum_sidecars_cannot_carry_extra_content(self): with archive.with_suffix('.zip.sha256').open('a') as stream: stream.write('private diagnostic text') with self.assertRaises(ValueError): SDKRelease.check_sdk(archive, self.commit, 'linux-x64') + def test_release_requests_and_manual_overrides_require_exact_commits(self): + directory = self.root / '.github'; directory.mkdir() + request = directory / 'sdk-release.json' + request.write_text(json.dumps({'engine_commit': self.commit})) + self.assertEqual(SDKRelease.requested_commit(self.root), self.commit) + self.assertEqual(SDKRelease.requested_commit(self.root, 'b' * 40), 'b' * 40) + for data in ({'engine_commit': 'main'}, {'engine_commit': self.commit + '/extra'}, + {'engine_commit': self.commit.upper()}, {'engine_commit': self.commit, 'command': 'extra'}, + {'engine_commit': None}, ['unexpected']): + request.write_text(json.dumps(data)) + with self.subTest(data=data), self.assertRaises(ValueError): + SDKRelease.requested_commit(self.root) + for value in ('', 'main', 'a' * 39, 'a' * 40 + '\n'): + with self.subTest(override=value), self.assertRaises(ValueError): + SDKRelease.requested_commit(self.root, value) + def test_repository_history_keeps_deleted_source_visible_to_the_audit(self): repo = self.root / 'repo'; repo.mkdir() subprocess.run(['git', 'init', '-q', str(repo)], check=True)