Build custom engine branch if needed workflow (prisma/prisma)
The Build custom engine branch if needed workflow from prisma/prisma, explained and optimized by Latchkey.
CI health: B - good
Point runs-on at Latchkey and get job timeouts, SHA-pinned actions, self-healing for flaky steps, and up to 58% lower cost, applied automatically.
What it does
This is the Build custom engine branch if needed workflow from the prisma/prisma repository, a real project running GitHub Actions. It is shown here with attribution under its Apache-2.0 license.
Below, Latchkey shows a faster, safer version produced by its optimization engine.
The workflow
name: Build custom engine branch if needed
on:
workflow_call:
outputs:
branchName:
description: The name of the branch of checked out engine
value: ${{ jobs.parseCommand.outputs.branchName }}
engineHash:
description: Commit hash of the checked out engine
value: ${{ jobs.build.outputs.engineHash }}
jobs:
parseCommand:
name: Parse "/engine-branch" command in PR body
runs-on: ubuntu-latest
outputs:
branchName: ${{ steps.detectCustomEngineBranch.outputs.branchName }}
steps:
- name: Extract custom engine branch name from PR body
id: detectCustomEngineBranch
env:
PR_BODY: ${{ github.event.pull_request.body }}
if: |
github.event_name == 'pull_request' &&
contains(env.PR_BODY, '/engine-branch') &&
(
github.event.pull_request.author_association == 'OWNER' ||
github.event.pull_request.author_association == 'MEMBER' ||
github.event.pull_request.author_association == 'COLLABORATOR' ||
github.event.pull_request.author_association == 'CONTRIBUTOR'
)
run: |
BRANCH_NAME=$(echo "$PR_BODY" | grep -o '/engine-branch \S*' | awk '{print $2}')
if [ -z "$BRANCH_NAME" ]; then
echo "Branch name not specified in /engine-branch command."
exit 1
fi
echo "Requested custom engine from branch: $BRANCH_NAME"
echo "branchName=$BRANCH_NAME" >> "$GITHUB_OUTPUT"
build:
name: Build
strategy:
matrix:
os: [ubuntu-latest, macos-14, windows-latest]
runs-on: ${{ matrix.os }}
needs: parseCommand
if: ${{ needs.parseCommand.outputs.branchName != '' }}
outputs:
engineHash: ${{ steps.engine-hash.outputs.engineHash }}
steps:
- uses: actions/checkout@v6
with:
repository: prisma/prisma-engines
ref: ${{ needs.parseCommand.outputs.branchName }}
- name: Get current engine hash
id: engine-hash
shell: bash
run: echo "engineHash=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
- uses: actions/cache@v5
name: Artifacts cache
id: artifacts-cache
with:
path: |
target/release/schema-engine
target/release/schema-engine.exe
target/prisma-schema-wasm
query-compiler/query-compiler-wasm/pkg
schema-engine/schema-engine-wasm/pkg
key: ${{ runner.os }}-engine-${{ steps.engine-hash.outputs.engineHash }}-${{ github.event.number }}
- uses: dtolnay/rust-toolchain@stable
if: steps.artifacts-cache.outputs.cache-hit != 'true'
- uses: actions/cache@v5
name: Dependencies cache
if: steps.artifacts-cache.outputs.cache-hit != 'true'
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Build native engines with cargo
if: steps.artifacts-cache.outputs.cache-hit != 'true'
shell: bash
run: |
cargo build --release -p schema-engine-cli
- uses: cargo-bins/cargo-binstall@main
- name: Extract wasm-bindgen version and install matching CLI
if: steps.artifacts-cache.outputs.cache-hit != 'true'
shell: bash
run: |
REQUESTED_WASM_BINDGEN_VERSION=$(grep -A 2 '^\[\[package\]\]$' Cargo.lock | grep 'name = "wasm-bindgen"' -A 1 | grep 'version' | sed 's/.*"\(.*\)".*/\1/')
if [ -n "$REQUESTED_WASM_BINDGEN_VERSION" ]; then
echo "Found wasm-bindgen version in Cargo.lock: $REQUESTED_WASM_BINDGEN_VERSION"
if which wasm-bindgen; then
INSTALLED_WASM_BINDGEN_VERSION=$(wasm-bindgen --version | cut -d' ' -f2)
if [ "$INSTALLED_WASM_BINDGEN_VERSION" == "$REQUESTED_WASM_BINDGEN_VERSION" ]; then
echo "Skipping wasm-bindgen CLI installation, version $INSTALLED_WASM_BINDGEN_VERSION has already been installed"
else
echo "ERROR: wasm-bindgen CLI $INSTALLED_WASM_BINDGEN_VERSION has already been installed, but the required version is $REQUESTED_WASM_BINDGEN_VERSION"
exit 1
fi
else
echo "Installing wasm-bindgen CLI $REQUESTED_WASM_BINDGEN_VERSION"
cargo binstall wasm-bindgen-cli --version "$REQUESTED_WASM_BINDGEN_VERSION"
fi
else
echo "ERROR: Could not find wasm-bindgen version in Cargo.lock"
exit 1
fi
- name: Install Binaryen (includes wasm-opt)
uses: jaxxstorm/action-install-gh-release@v2.1.0
with:
repo: WebAssembly/binaryen
tag: version_122
binaries-location: binaryen-version_122/bin
platform: ${{ runner.os == 'macOS' && 'macos' || runner.os == 'Windows' && 'windows' || 'linux' }}
cache: true
- name: Install coreutils on macOS (includes numfmt)
if: runner.os == 'macOS'
run: brew install coreutils
- name: Add coreutils to PATH on Windows (includes numfmt)
if: runner.os == 'Windows'
shell: bash
run: |
echo "C:/msys64/usr/bin" >> "$GITHUB_PATH"
echo "C:/msys64/mingw64/bin" >> "$GITHUB_PATH"
- name: Build prisma-schema-wasm
if: steps.artifacts-cache.outputs.cache-hit != 'true'
shell: bash
run: |
make PROFILE=release build-schema-wasm
- name: Build query-compiler-wasm
if: steps.artifacts-cache.outputs.cache-hit != 'true'
shell: bash
run: |
make WASM_BUILD_PROFILE=release build-qc-wasm
- name: Build schema-engine-wasm
if: steps.artifacts-cache.outputs.cache-hit != 'true'
shell: bash
run: |
make WASM_BUILD_PROFILE=release build-se-wasm
The same workflow, on Latchkey
Removes redundant runs and caps runaway jobs. Added and changed lines are highlighted.
name: Build custom engine branch if needed on: workflow_call: outputs: branchName: description: The name of the branch of checked out engine value: ${{ jobs.parseCommand.outputs.branchName }} engineHash: description: Commit hash of the checked out engine value: ${{ jobs.build.outputs.engineHash }} jobs: parseCommand: timeout-minutes: 30 name: Parse "/engine-branch" command in PR body runs-on: latchkey-small outputs: branchName: ${{ steps.detectCustomEngineBranch.outputs.branchName }} steps: - name: Extract custom engine branch name from PR body id: detectCustomEngineBranch env: PR_BODY: ${{ github.event.pull_request.body }} if: | github.event_name == 'pull_request' && contains(env.PR_BODY, '/engine-branch') && ( github.event.pull_request.author_association == 'OWNER' || github.event.pull_request.author_association == 'MEMBER' || github.event.pull_request.author_association == 'COLLABORATOR' || github.event.pull_request.author_association == 'CONTRIBUTOR' ) run: | BRANCH_NAME=$(echo "$PR_BODY" | grep -o '/engine-branch \S*' | awk '{print $2}') if [ -z "$BRANCH_NAME" ]; then echo "Branch name not specified in /engine-branch command." exit 1 fi echo "Requested custom engine from branch: $BRANCH_NAME" echo "branchName=$BRANCH_NAME" >> "$GITHUB_OUTPUT" build: timeout-minutes: 30 name: Build strategy: matrix: os: [ubuntu-latest, macos-14, windows-latest] runs-on: ${{ matrix.os }} needs: parseCommand if: ${{ needs.parseCommand.outputs.branchName != '' }} outputs: engineHash: ${{ steps.engine-hash.outputs.engineHash }} steps: - uses: actions/checkout@v6 with: repository: prisma/prisma-engines ref: ${{ needs.parseCommand.outputs.branchName }} - name: Get current engine hash id: engine-hash shell: bash run: echo "engineHash=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT" - uses: actions/cache@v5 name: Artifacts cache id: artifacts-cache with: path: | target/release/schema-engine target/release/schema-engine.exe target/prisma-schema-wasm query-compiler/query-compiler-wasm/pkg schema-engine/schema-engine-wasm/pkg key: ${{ runner.os }}-engine-${{ steps.engine-hash.outputs.engineHash }}-${{ github.event.number }} - uses: dtolnay/rust-toolchain@stable if: steps.artifacts-cache.outputs.cache-hit != 'true' - uses: actions/cache@v5 name: Dependencies cache if: steps.artifacts-cache.outputs.cache-hit != 'true' with: path: | ~/.cargo/bin/ ~/.cargo/registry/index/ ~/.cargo/registry/cache/ ~/.cargo/git/db/ target/ key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} - name: Build native engines with cargo if: steps.artifacts-cache.outputs.cache-hit != 'true' shell: bash run: | cargo build --release -p schema-engine-cli - uses: cargo-bins/cargo-binstall@main - name: Extract wasm-bindgen version and install matching CLI if: steps.artifacts-cache.outputs.cache-hit != 'true' shell: bash run: | REQUESTED_WASM_BINDGEN_VERSION=$(grep -A 2 '^\[\[package\]\]$' Cargo.lock | grep 'name = "wasm-bindgen"' -A 1 | grep 'version' | sed 's/.*"\(.*\)".*/\1/') if [ -n "$REQUESTED_WASM_BINDGEN_VERSION" ]; then echo "Found wasm-bindgen version in Cargo.lock: $REQUESTED_WASM_BINDGEN_VERSION" if which wasm-bindgen; then INSTALLED_WASM_BINDGEN_VERSION=$(wasm-bindgen --version | cut -d' ' -f2) if [ "$INSTALLED_WASM_BINDGEN_VERSION" == "$REQUESTED_WASM_BINDGEN_VERSION" ]; then echo "Skipping wasm-bindgen CLI installation, version $INSTALLED_WASM_BINDGEN_VERSION has already been installed" else echo "ERROR: wasm-bindgen CLI $INSTALLED_WASM_BINDGEN_VERSION has already been installed, but the required version is $REQUESTED_WASM_BINDGEN_VERSION" exit 1 fi else echo "Installing wasm-bindgen CLI $REQUESTED_WASM_BINDGEN_VERSION" cargo binstall wasm-bindgen-cli --version "$REQUESTED_WASM_BINDGEN_VERSION" fi else echo "ERROR: Could not find wasm-bindgen version in Cargo.lock" exit 1 fi - name: Install Binaryen (includes wasm-opt) uses: jaxxstorm/action-install-gh-release@v2.1.0 with: repo: WebAssembly/binaryen tag: version_122 binaries-location: binaryen-version_122/bin platform: ${{ runner.os == 'macOS' && 'macos' || runner.os == 'Windows' && 'windows' || 'linux' }} cache: true - name: Install coreutils on macOS (includes numfmt) if: runner.os == 'macOS' run: brew install coreutils - name: Add coreutils to PATH on Windows (includes numfmt) if: runner.os == 'Windows' shell: bash run: | echo "C:/msys64/usr/bin" >> "$GITHUB_PATH" echo "C:/msys64/mingw64/bin" >> "$GITHUB_PATH" - name: Build prisma-schema-wasm if: steps.artifacts-cache.outputs.cache-hit != 'true' shell: bash run: | make PROFILE=release build-schema-wasm - name: Build query-compiler-wasm if: steps.artifacts-cache.outputs.cache-hit != 'true' shell: bash run: | make WASM_BUILD_PROFILE=release build-qc-wasm - name: Build schema-engine-wasm if: steps.artifacts-cache.outputs.cache-hit != 'true' shell: bash run: | make WASM_BUILD_PROFILE=release build-se-wasm
What changed
- Run on Latchkey managed runners with one line (
runs-on), which apply the fixes below automatically and self-heal transient failures. This example useslatchkey-small; pick the runner size that fits the job. - Add a job timeout so a hung step cannot burn hours of runner time.
3 third-party actions are referenced by a movable tag. Pin them to the commit SHA (Latchkey resolves and applies this automatically) so a repointed tag cannot change what runs.
What Latchkey heals here
This workflow has steps that commonly fail on transient issues (network, registries, flaky browsers). On Latchkey managed runners they are detected, retried, and self-healed instead of failing your build:
- Dependency installs
This workflow runs 2 jobs (4 with the matrix expanded) per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.