name: Deploy templates description: > Build the starter-kit demos against the checked-out SDK and deploy the cloudflare-hosted ones to *.templates.tldraw.dev. Shared by deploy-templates.yml (template changes, manual runs) and publish.yml (releases). Expects the repo to be checked out already; runs the setup action itself. # The cloudflare credentials are secrets on the deploy-production environment, so the job using # this action has to select that environment and pass them in. This is a composite action rather # than a workflow_call workflow because a called workflow only ever sees the secrets its caller # hands it, and an `environment:` on a job inside the callee does not add that environment's # secrets to them — see #10636. inputs: license-key: description: tldraw license key the demos are built with (TEMPLATES_TLDRAW_LICENSE_KEY) required: true cloudflare-account-id: description: Cloudflare account the workers deploy to (CLOUDFLARE_ACCOUNT_ID) required: true cloudflare-api-token: description: Cloudflare API token with workers permissions (CLOUDFLARE_API_TOKEN) required: true runs: using: composite steps: - uses: ./.github/actions/setup # most templates run `tsc` as part of their build, which resolves the workspace packages # through their project references and so needs the declarations built first - name: Build types shell: bash env: # build-types pulls in refresh-assets, which rewrites the generated version files. in CI it # exits 1 on any change to a committed asset instead of writing it, which would fail the # deploy on a release ref whose generated files aren't already in sync. ALLOW_REFRESH_ASSETS_CHANGES: 1 run: yarn build-types - name: Deploy templates shell: bash env: CI: 1 PRINT_GITHUB_ANNOTATIONS: 1 ALLOW_REFRESH_ASSETS_CHANGES: 1 TEMPLATES_TLDRAW_LICENSE_KEY: ${{ inputs.license-key }} CLOUDFLARE_API_TOKEN: ${{ inputs.cloudflare-api-token }} CLOUDFLARE_ACCOUNT_ID: ${{ inputs.cloudflare-account-id }} run: | # the templates import tldraw/tldraw.css, which is generated and gitignored yarn lazy prebuild cd templates all_templates=$(ls -d */ | cut -f1 -d'/') cd .. # the demos are independent of each other, so deploy them all before failing: one broken # template shouldn't leave the rest stranded on an old build with no signal about which. # templates with no `deploy` config in their package.json skip themselves. failed="" for template in $all_templates; do echo "::group::Deploying $template" yarn tsx ./internal/scripts/deploy-template.ts $template || failed="$failed $template" echo "::endgroup::" done if [ -n "$failed" ]; then echo "::error::Failed to deploy templates:$failed" exit 1 fi