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.
- B
- CI health grade
- 72/100
- Health score
- 2
- Jobs per trigger
- 2
- Fixes in the optimized version
In short
- CI health: B (good)
- The optimized version below points runs-on at Latchkey managed runners and adds job timeouts.
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-wasmThe 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: ubuntu-latest
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. Each Linux x64 job moves to the Latchkey size matching its vCPU count,latchkey-smallfor a standard 2 vCPU runner; macOS, Windows and arm64 jobs stay as written. - Add a job timeout so a hung step cannot burn hours of runner time.
Left runs-on as written on the build job: matrix.os mixes Linux with macOS and Windows, which Latchkey does not run. Point only the Linux legs at Latchkey, for example with a matrix include entry that sets the runner.
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. 2 of the 4 run on a standard GitHub-hosted Linux x64 runner, which in a private repository bills $0.006 a minute against $0.0025 on latchkey-small, 58% lower; in a public repository like this one they are free. 2 of the 4 run on macOS and Windows, which Latchkey does not offer, so those stay where they are. Estimate the monthly difference with your own run counts.
Actions used in this workflow
- actions/checkout
- actions/cache
- dtolnay/rust-toolchain
- cargo-bins/cargo-binstall
- jaxxstorm/action-install-gh-release