name: Publish Tutti App Runtime on: push: branches: - main paths: - config/tutti.app-runtime.lock.json workflow_dispatch: inputs: aws_region: description: AWS region. Defaults to runtime vars, then release vars. required: false type: string aws_role_arn: description: AWS role ARN. Defaults to runtime vars, then release vars. required: false type: string s3_bucket: description: S3 bucket. Defaults to runtime vars, then release vars. required: false type: string s3_prefix: description: S3 prefix. Defaults to runtime vars or tutti-app-runtimes. required: false type: string artifact_base_url: description: Public HTTPS base URL matching the S3 prefix, usually a CloudFront URL. required: false type: string cloudfront_distribution_id: description: Optional CloudFront distribution id to invalidate after catalog upload. required: false type: string permissions: contents: read id-token: write concurrency: group: tutti-app-runtime-production cancel-in-progress: false env: FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true RUNTIME_LOCK_FILE: config/tutti.app-runtime.lock.json jobs: build: name: Build ${{ matrix.platform }} runs-on: ${{ matrix.runner }} strategy: fail-fast: false matrix: include: - platform: darwin-arm64 runner: macos-15 node_distribution: darwin-arm64 - platform: darwin-amd64 runner: macos-15-intel node_distribution: darwin-x64 - platform: linux-amd64 runner: ubuntu-latest node_distribution: linux-x64 - platform: windows-amd64 runner: windows-latest node_distribution: win-x64 steps: - name: Checkout uses: actions/checkout@v6 - name: Setup Node.js uses: actions/setup-node@v6 with: node-version-file: .node-version - name: Resolve runtime lock id: lock shell: bash env: PLATFORM: ${{ matrix.platform }} run: | node <<'NODE' >> "$GITHUB_OUTPUT" const fs = require("node:fs"); const lock = JSON.parse(fs.readFileSync(process.env.RUNTIME_LOCK_FILE, "utf8")); const platform = process.env.PLATFORM; if (!lock.platforms?.[platform]) { throw new Error(`runtime lock does not contain ${platform}`); } const pythonVersion = platform === "windows-amd64" ? lock.python?.windows?.version : lock.python?.version; const rtkArtifact = lock.rtk?.artifacts?.[platform]; for (const [name, value] of [ ["runtime_version", lock.runtimeVersion], ["uv_version", lock.uv?.version], ["python_version", pythonVersion], ["python_windows_archive_url", lock.python?.windows?.archiveUrl], ["python_windows_archive_sha256", lock.python?.windows?.archiveSha256], ["python_windows_archive_root", lock.python?.windows?.archiveRoot], ["node_version", lock.node?.version], ["node_release_base_url", lock.node?.releaseBaseUrl], ["rtk_version", lock.rtk?.version], ["rtk_archive_url", rtkArtifact?.url], ["rtk_archive_sha256", rtkArtifact?.sha256], ["rtk_archive_size", rtkArtifact?.sizeBytes], ["rtk_archive_executable", rtkArtifact?.executable], ["rtk_license_url", lock.rtk?.license?.url], ["rtk_license_sha256", lock.rtk?.license?.sha256], ["rtk_license_size", lock.rtk?.license?.sizeBytes], ["configured_node_distribution", lock.platforms[platform].nodeDistribution], ["configured_runner", lock.platforms[platform].runner] ]) { if (!value) throw new Error(`runtime lock missing ${name}`); console.log(`${name}=${value}`); } NODE - name: Check matrix matches runtime lock shell: bash env: CONFIGURED_NODE_DISTRIBUTION: ${{ steps.lock.outputs.configured_node_distribution }} CONFIGURED_RUNNER: ${{ steps.lock.outputs.configured_runner }} MATRIX_NODE_DISTRIBUTION: ${{ matrix.node_distribution }} MATRIX_RUNNER: ${{ matrix.runner }} run: | if [ "${CONFIGURED_NODE_DISTRIBUTION}" != "${MATRIX_NODE_DISTRIBUTION}" ]; then echo "Matrix node distribution does not match runtime lock" >&2 exit 1 fi if [ "${CONFIGURED_RUNNER}" != "${MATRIX_RUNNER}" ]; then echo "Matrix runner does not match runtime lock" >&2 exit 1 fi - name: Install build tools if: runner.os == 'Linux' shell: bash run: | sudo apt-get update sudo apt-get install -y rsync zip - name: Install uv if: runner.os != 'Windows' shell: bash env: UV_VERSION: ${{ steps.lock.outputs.uv_version }} run: | curl --proto '=https' --tlsv1.2 -fsSL "https://releases.astral.sh/github/uv/releases/download/${UV_VERSION}/uv-installer.sh" | sh echo "$HOME/.local/bin" >> "$GITHUB_PATH" - name: Install managed Python if: runner.os != 'Windows' shell: bash env: PYTHON_VERSION: ${{ steps.lock.outputs.python_version }} run: | export UV_PYTHON_INSTALL_DIR="${RUNNER_TEMP}/tutti-runtime-python" uv python install --no-bin "${PYTHON_VERSION}" python_root="$(find "${UV_PYTHON_INSTALL_DIR}" -mindepth 1 -maxdepth 1 -type d ! -name '.temp' | sort | head -n 1)" if [ -z "${python_root}" ] || ! find "${python_root}/bin" -maxdepth 1 -type f -perm -111 -name 'python3*' | grep -q .; then echo "uv did not install a usable Python runtime" >&2 exit 1 fi echo "PYTHON_ROOT=${python_root}" >> "$GITHUB_ENV" - name: Download Node.js if: runner.os != 'Windows' shell: bash env: NODE_DISTRIBUTION: ${{ matrix.node_distribution }} NODE_RELEASE_BASE_URL: ${{ steps.lock.outputs.node_release_base_url }} NODE_VERSION: ${{ steps.lock.outputs.node_version }} run: | node_archive="node-v${NODE_VERSION}-${NODE_DISTRIBUTION}.tar.gz" mkdir -p "${RUNNER_TEMP}/tutti-runtime-node" curl --retry 3 --retry-delay 2 -fsSLo "${RUNNER_TEMP}/${node_archive}" "${NODE_RELEASE_BASE_URL}/${node_archive}" curl --retry 3 --retry-delay 2 -fsSLo "${RUNNER_TEMP}/SHASUMS256.txt" "${NODE_RELEASE_BASE_URL}/SHASUMS256.txt" (cd "${RUNNER_TEMP}" && grep " ${node_archive}$" SHASUMS256.txt | shasum -a 256 -c -) tar -xzf "${RUNNER_TEMP}/${node_archive}" -C "${RUNNER_TEMP}/tutti-runtime-node" --strip-components=1 if [ ! -x "${RUNNER_TEMP}/tutti-runtime-node/bin/node" ] || [ ! -x "${RUNNER_TEMP}/tutti-runtime-node/bin/npm" ]; then echo "Node.js archive does not contain node and npm" >&2 exit 1 fi - name: Download RTK if: runner.os != 'Windows' shell: bash env: RTK_ARCHIVE_EXECUTABLE: ${{ steps.lock.outputs.rtk_archive_executable }} RTK_ARCHIVE_SHA256: ${{ steps.lock.outputs.rtk_archive_sha256 }} RTK_ARCHIVE_SIZE: ${{ steps.lock.outputs.rtk_archive_size }} RTK_ARCHIVE_URL: ${{ steps.lock.outputs.rtk_archive_url }} RTK_LICENSE_SHA256: ${{ steps.lock.outputs.rtk_license_sha256 }} RTK_LICENSE_SIZE: ${{ steps.lock.outputs.rtk_license_size }} RTK_LICENSE_URL: ${{ steps.lock.outputs.rtk_license_url }} RTK_VERSION: ${{ steps.lock.outputs.rtk_version }} run: | archive="${RUNNER_TEMP}/$(basename "${RTK_ARCHIVE_URL}")" license="${RUNNER_TEMP}/rtk-LICENSE" expanded="${RUNNER_TEMP}/tutti-runtime-rtk-expanded" target="${RUNNER_TEMP}/tutti-runtime-rtk/rtk" curl --retry 3 --retry-delay 2 -fsSLo "${archive}" "${RTK_ARCHIVE_URL}" test "$(wc -c < "${archive}" | tr -d ' ')" = "${RTK_ARCHIVE_SIZE}" printf '%s %s\n' "${RTK_ARCHIVE_SHA256}" "${archive}" | shasum -a 256 -c - rm -rf "${expanded}" "${target}" mkdir -p "${expanded}" "${target}/bin" tar -xf "${archive}" -C "${expanded}" executable="$(find "${expanded}" -type f -name "${RTK_ARCHIVE_EXECUTABLE}" | head -n 1)" test -n "${executable}" cp "${executable}" "${target}/bin/rtk" chmod 0755 "${target}/bin/rtk" curl --retry 3 --retry-delay 2 -fsSLo "${license}" "${RTK_LICENSE_URL}" test "$(wc -c < "${license}" | tr -d ' ')" = "${RTK_LICENSE_SIZE}" printf '%s %s\n' "${RTK_LICENSE_SHA256}" "${license}" | shasum -a 256 -c - cp "${license}" "${target}/LICENSE" "${target}/bin/rtk" --version | grep -Fx "rtk ${RTK_VERSION}" - name: Assemble runtime artifacts if: runner.os != 'Windows' shell: bash env: NODE_VERSION: ${{ steps.lock.outputs.node_version }} PLATFORM: ${{ matrix.platform }} PYTHON_VERSION: ${{ steps.lock.outputs.python_version }} RTK_VERSION: ${{ steps.lock.outputs.rtk_version }} RUNTIME_VERSION: ${{ steps.lock.outputs.runtime_version }} run: | artifact_dir="${GITHUB_WORKSPACE}/tutti-app-runtime/${RUNTIME_VERSION}/${PLATFORM}" python_staging="${RUNNER_TEMP}/tutti-app-runtime-python" node_staging="${RUNNER_TEMP}/tutti-app-runtime-node-artifact" rtk_staging="${RUNNER_TEMP}/tutti-runtime-rtk" python_artifact_dir="${artifact_dir}/python" node_artifact_dir="${artifact_dir}/node" rtk_artifact_dir="${artifact_dir}/rtk" python_artifact_file="tutti-app-runtime-python-${PLATFORM}-${RUNTIME_VERSION}.zip" node_artifact_file="tutti-app-runtime-node-${PLATFORM}-${RUNTIME_VERSION}.zip" rtk_artifact_file="tutti-app-runtime-rtk-${PLATFORM}-${RUNTIME_VERSION}.zip" mkdir -p "${python_staging}/python" "${node_staging}/node" "${python_artifact_dir}" "${node_artifact_dir}" "${rtk_artifact_dir}" rsync -aL "${PYTHON_ROOT}/" "${python_staging}/python/" rsync -aL "${RUNNER_TEMP}/tutti-runtime-node/" "${node_staging}/node/" if [ ! -x "${python_staging}/python/bin/python3" ]; then python_executable="$(find "${python_staging}/python/bin" -maxdepth 1 -type f -perm -111 -name 'python3*' | sort | head -n 1)" cp "${python_executable}" "${python_staging}/python/bin/python3" fi cat > "${node_staging}/node/bin/npm" <<'SH' #!/bin/sh script_dir="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)" exec "${script_dir}/node" "${script_dir}/../lib/node_modules/npm/bin/npm-cli.js" "$@" SH cat > "${node_staging}/node/bin/npx" <<'SH' #!/bin/sh script_dir="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)" exec "${script_dir}/node" "${script_dir}/../lib/node_modules/npm/bin/npx-cli.js" "$@" SH cat > "${node_staging}/node/bin/corepack" <<'SH' #!/bin/sh script_dir="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)" exec "${script_dir}/node" "${script_dir}/../lib/node_modules/corepack/dist/corepack.js" "$@" SH chmod 0755 \ "${node_staging}/node/bin/npm" \ "${node_staging}/node/bin/npx" \ "${node_staging}/node/bin/corepack" test -x "${python_staging}/python/bin/python3" test -x "${node_staging}/node/bin/node" test -x "${node_staging}/node/bin/npm" test -x "${node_staging}/node/bin/npx" test -x "${node_staging}/node/bin/corepack" test -x "${rtk_staging}/rtk/bin/rtk" PATH="${node_staging}/node/bin:${PATH}" "${node_staging}/node/bin/npm" --version PATH="${node_staging}/node/bin:${PATH}" "${node_staging}/node/bin/npx" --version PATH="${node_staging}/node/bin:${PATH}" "${node_staging}/node/bin/corepack" --version "${rtk_staging}/rtk/bin/rtk" --version | grep -Fx "rtk ${RTK_VERSION}" find "${python_staging}" "${node_staging}" "${rtk_staging}" -exec touch -h -t 202606010000 {} + (cd "${python_staging}" && zip -X -qry "${python_artifact_dir}/${python_artifact_file}" .) (cd "${node_staging}" && zip -X -qry "${node_artifact_dir}/${node_artifact_file}" .) (cd "${rtk_staging}" && zip -X -qry "${rtk_artifact_dir}/${rtk_artifact_file}" .) python_artifact_sha256="$(shasum -a 256 "${python_artifact_dir}/${python_artifact_file}" | awk '{print $1}')" node_artifact_sha256="$(shasum -a 256 "${node_artifact_dir}/${node_artifact_file}" | awk '{print $1}')" rtk_artifact_sha256="$(shasum -a 256 "${rtk_artifact_dir}/${rtk_artifact_file}" | awk '{print $1}')" python_artifact_size="$(wc -c < "${python_artifact_dir}/${python_artifact_file}" | tr -d ' ')" node_artifact_size="$(wc -c < "${node_artifact_dir}/${node_artifact_file}" | tr -d ' ')" rtk_artifact_size="$(wc -c < "${rtk_artifact_dir}/${rtk_artifact_file}" | tr -d ' ')" cat > "${artifact_dir}/metadata.json" <&2 exit 1 fi echo "Restored ${metadata_count} runtime artifact metadata files." - name: Validate AWS configuration shell: bash run: | missing=() for name in AWS_REGION_VALUE AWS_ROLE_ARN_VALUE S3_BUCKET_VALUE ARTIFACT_BASE_URL_VALUE; do if [ -z "${!name:-}" ]; then missing+=("${name}") fi done if [ "${#missing[@]}" -gt 0 ]; then printf 'Missing required AWS configuration: %s\n' "${missing[*]}" >&2 exit 1 fi - name: Configure AWS credentials uses: aws-actions/configure-aws-credentials@v4 with: aws-region: ${{ env.AWS_REGION_VALUE }} role-to-assume: ${{ env.AWS_ROLE_ARN_VALUE }} - name: Build runtime catalog shell: bash run: | metadata_args=() while IFS= read -r metadata_file; do metadata_args+=(--metadata-file "${metadata_file}") done < <(find tutti-app-runtime -name metadata.json -type f | sort) if [ "${#metadata_args[@]}" -eq 0 ]; then echo "No runtime metadata files were downloaded" >&2 exit 1 fi node tools/scripts/build-tutti-app-runtime-catalog.mjs \ --artifact-base-url "${ARTIFACT_BASE_URL_VALUE%/}" \ "${metadata_args[@]}" \ --output tutti-app-runtime/catalog.json - name: Upload runtime artifacts to S3 shell: bash run: | if [ -z "${S3_BUCKET_VALUE}" ]; then echo "S3 bucket is required" >&2 exit 1 fi prefix="${S3_PREFIX_VALUE%/}" if [ -n "${prefix}" ]; then s3_root="s3://${S3_BUCKET_VALUE}/${prefix}" else s3_root="s3://${S3_BUCKET_VALUE}" fi find tutti-app-runtime -name 'tutti-app-runtime-*-*.zip' -type f | sort | while IFS= read -r artifact; do relative_path="${artifact#tutti-app-runtime/}" aws s3 cp "${artifact}" "${s3_root}/${relative_path}" \ --content-type "application/zip" \ --cache-control "public, max-age=31536000, immutable" done - name: Upload runtime catalog to S3 shell: bash run: | prefix="${S3_PREFIX_VALUE%/}" if [ -n "${prefix}" ]; then s3_target="s3://${S3_BUCKET_VALUE}/${prefix}/catalog.json" else s3_target="s3://${S3_BUCKET_VALUE}/catalog.json" fi aws s3 cp tutti-app-runtime/catalog.json "${s3_target}" \ --content-type "application/json" \ --cache-control "public, max-age=60" - name: Invalidate CloudFront runtime catalog if: env.CLOUDFRONT_DISTRIBUTION_ID_VALUE != '' shell: bash run: | prefix="${S3_PREFIX_VALUE%/}" if [ -n "${prefix}" ]; then path_to_invalidate="/${prefix}/catalog.json" else path_to_invalidate="/catalog.json" fi aws cloudfront create-invalidation \ --distribution-id "${CLOUDFRONT_DISTRIBUTION_ID_VALUE}" \ --paths "${path_to_invalidate}"