build-engine-branch.yml•6.59 kB
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@v4
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@v4
name: Artifacts cache
id: artifacts-cache
with:
path: |
target/release/schema-engine
target/release/schema-engine.exe
target/release/query-engine
target/release/query-engine.exe
target/release/libquery_engine.so
target/release/libquery_engine.dylib
target/release/query_engine.dll
target/prisma-schema-wasm
query-engine/query-engine-wasm/pkg
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@v4
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 query-engine \
-p query-engine-node-api \
-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@v1.14.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-engine-wasm
if: steps.artifacts-cache.outputs.cache-hit != 'true'
shell: bash
run: |
make WASM_BUILD_PROFILE=release build-qe-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