Public-repo CodeBuild integration for Linux x64 and arm64. GitHub
Actions assumes a dedicated IAM role with OIDC (no long-lived AWS keys)
and starts the projects. Each project posts a commit status comparable to
the CortexLM/backend checks cortex-gha-x64 / cortex-gha-arm64.
Marker: CLI_CODEBUILD_CI_READY
Existing workflows stay in place: ci.yml, release.yml, publish-r2.yml,
homebrew.yml, winget.yml, version-bump.yml, test-stability.yml.
CodeBuild extends them. It does not replace R2 publishing, version
bumps, or macOS/Windows release jobs. Staging/prod app deploy remains
unchanged (prod HOLD).
Windows CodeBuild is out of scope. Compliance treats Windows CI as
outside the production gate; keep windows-latest on GitHub-hosted runners
in ci.yml / release.yml until a separate follow-up.
Do not commit AWS account IDs, access keys, PATs, or internal hostnames.
After the one-time AWS setup below, add these required checks on main:
| Context | Push/main project (S3 cache) |
Pull-request project (no cache) | Arch |
|---|---|---|---|
cortex-cli-gha-x64 |
cortex-cli-gha-x64 |
cortex-cli-gha-x64-pr |
Linux x86_64 |
cortex-cli-gha-arm64 |
cortex-cli-gha-arm64 |
cortex-cli-gha-arm64-pr |
Linux aarch64 |
Unapproved same-repository pull requests are handled with
pull_request_target so this workflow file and the OIDC token come from
main, not from the unapproved head. Those runs start the *-pr projects
only (logs-only service role, NO_CACHE). They cannot read, write, or
delete the shared cargo cache. The runner checks out the PR base for
buildspec-ci.yml and passes the head SHA into CodeBuild as
CORTEX_SOURCE_SHA. OIDC trust is only
repo:CortexLM/cli:ref:refs/heads/main plus
job_workflow_ref for .github/workflows/codebuild.yml on main.
Untrusted pull_request workflows cannot assume the role.
Keep the existing ci.yml checks (Format, Clippy, Test, TUI checks,
Security Audit, Source and dependency policy, Changed-line coverage,
CLI Version and Distribution, CI Success). Do not remove them in this
change. After CodeBuild is required and stable, a later PR can slim the
duplicate GitHub-hosted Linux cargo jobs.
Same-repo PRs start the *-pr projects via pull_request_target. Pushes
to main start the cached projects. Fork PRs keep using GitHub-hosted
ci.yml only (StartBuild is skipped when the head repo is not this
repository).
If this AWS account already hosts backend projects cortex-gha-x64 /
cortex-gha-arm64, reuse the GitHub OIDC provider and the account, not
the projects. A CodeBuild project has one source/buildspec; do not point
backend projects at this public CLI repo. Create dedicated
cortex-cli-gha-* projects. Override names only via GitHub variables
if an admin already created equivalent CLI projects.
In the AWS account that already runs CortexLM/backend CodeBuild (or a new account dedicated to public CLI CI):
- IAM → Identity providers →
token.actions.githubusercontent.com. - If it exists, do not recreate it. Continue to the role.
- If it does not exist, create it:
- Provider URL:
https://token.actions.githubusercontent.com - Audience:
sts.amazonaws.com - Or pass
CreateGithubOidcProvider=trueto the stack below.
- Provider URL:
From a workstation that can assume an admin role (never from this repo's CI, and never with keys committed here):
aws cloudformation deploy \
--stack-name cortex-cli-codebuild \
--template-file deploy/aws/codebuild/cloudformation.yaml \
--capabilities CAPABILITY_NAMED_IAM \
--parameter-overrides \
GitHubOrgRepo=CortexLM/cli \
ProjectNameX64=cortex-cli-gha-x64 \
ProjectNameArm64=cortex-cli-gha-arm64 \
GhaRoleName=cortex-cli-codebuild-gha \
CreateGithubOidcProvider=falseCopy the GithubActionsRoleArn output. It contains the account ID; store
it as a GitHub variable, not in git.
- Create role
cortex-cli-codebuild-gha. - Trust policy:
iam-trust-policy.jsonwithACCOUNT_IDreplaced at deploy time. The subject must be onlyrepo:CortexLM/cli:ref:refs/heads/main. Also requirejob_workflow_refCortexLM/cli/.github/workflows/codebuild.yml@refs/heads/main. Do not trustrepo:CortexLM/cli:pull_request— that would let an unapprovedpull_requestworkflow assume the role. - Permissions:
iam-gha-permissions.jsonwithACCOUNT_IDandREGIONreplaced. Actions are onlycodebuild:StartBuild,codebuild:BatchGetBuilds, andlogs:GetLogEventson the two CLI projects. - Create cached projects
cortex-cli-gha-x64/cortex-cli-gha-arm64(BUILD_GENERAL1_LARGE, source NO_SOURCE, S3 cache, 90 minute timeout) and matching*-prprojects with NO_CACHE. - Cached-project service role: CloudWatch Logs plus read/write on the cache bucket. PR-project service role: CloudWatch Logs only. No deploy, no R2, no production secrets.
On CortexLM/cli → Settings → Secrets and variables → Actions → Variables:
| Variable | Value |
|---|---|
AWS_CODEBUILD_ROLE_ARN |
GithubActionsRoleArn stack output |
AWS_REGION |
Region of the stack (default in the workflow is us-east-1) |
AWS_CODEBUILD_PROJECT_X64 |
Optional override; default cortex-cli-gha-x64 |
AWS_CODEBUILD_PROJECT_ARM64 |
Optional override; default cortex-cli-gha-arm64 |
Do not add AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY. Do not put
staging or production app secrets on these projects.
Until AWS_CODEBUILD_ROLE_ARN is set, .github/workflows/codebuild.yml
validates the in-repo assets and skips StartBuild. It does not post a
green cortex-cli-gha-* status for that skip (no mock-success).
Branch protection / ruleset on main: require
cortex-cli-gha-x64 and cortex-cli-gha-arm64 in addition to the
existing ci.yml jobs. Require these only after a successful StartBuild
has been observed on a test PR.
buildspec-ci.yml clones the public CortexLM/cli commit over HTTPS
(no PAT) and runs run-ci.sh:
cargo fmt --all -- --check./scripts/clippy.sh./scripts/check-cli-version.shpython3 scripts/readiness/tests.pycargo test --locked --workspace --docpython3 scripts/readiness/schema.pycargo build --locked -p cortex-cli -p cortex-app-serverpython3 scripts/readiness/qa.py- headless TUI / snapshot packages (same set as
ci.yml) - changed-line coverage against the real PR base SHA
Cargo registry, git, rustup, and target/ are cached in S3.
Not in this change. If Windows CodeBuild is added later, use a separate project and a non-required check. Do not block production on it.