Files
galaxy/.github/actions/prepare_environment/action.yml
T

166 lines
6.8 KiB
YAML

name: Prepare Environment
description: A shared set of setup steps to prepare the runtime environment.
inputs:
target_os:
required: true
description: The target OS that we're building for ("macos", "linux", "windows", or "wasm").
is_self_hosted:
required: true
description: Whether or not the workflow is running on a self-hosted runner.
ref:
description: If set, the ref to checkout.
install_test_deps:
description: If true, dependencies needed for running tests will be installed.
install_release_deps:
description: If true, dependencies needed for building release artifacts will be installed (e.g., cargo-about for license generation).
cache_key:
description: If set, the cache key to use. If unset, the cache key will be derived from the target OS.
ssh_key:
description: SSH private key used to clone the private warp-channel-config repository. Only consumed when running in warpdotdev/warp-internal.
runs:
using: composite
steps:
- name: Make GitHub token available in the environment
shell: bash
run: echo "GH_TOKEN=${{ github.token }}" >> $GITHUB_ENV
- name: Set up git for Windows
if: ${{ inputs.target_os == 'windows' }}
shell: bash
run: git config --system core.longpaths true
- name: Set CARGO_HOME location
if: ${{ inputs.target_os == 'windows' }}
shell: bash
run: echo "CARGO_HOME=C:\cargo" >> $GITHUB_ENV
- name: Determine repository root
id: repo-root
shell: bash
run: |
# The action lives at <repo-root>/.github/actions/prepare_environment.
# Derive the repository root from the action path.
REPO_ROOT=$(cd "${{ github.action_path }}/../../.." && pwd)
echo "path=$REPO_ROOT" >> $GITHUB_OUTPUT
# Normalize $GITHUB_WORKSPACE through cd/pwd so that path formats
# match on Windows (where $GITHUB_WORKSPACE uses backslashes but
# pwd produces MSYS-style forward-slash paths).
WORKSPACE=$(cd "$GITHUB_WORKSPACE" && pwd)
if [ "$REPO_ROOT" = "$WORKSPACE" ]; then
echo "is-workspace-root=true" >> $GITHUB_OUTPUT
else
echo "is-workspace-root=false" >> $GITHUB_OUTPUT
fi
- uses: Swatinem/rust-cache@e18b497796c12c097a38f9edb9d0641fb99eee32 # v2
if: ${{ inputs.is_self_hosted != 'true' && !startsWith(runner.name, 'nsc-runner') }}
with:
# Make sure x86_64-unknown-linux-gnu and wasm32-unknown-unknown builds
# don't share a cache, despite running on the same _host_ architecture.
key: ${{ inputs.cache_key != '' && inputs.cache_key || inputs.target_os }}
# Only cache runs on the master branch (caches on feature branches
# are not reusable).
save-if: ${{ github.ref == 'refs/heads/master' }}
- name: Set up Namespace cache
if: ${{ startsWith(runner.name, 'nsc-runner') }}
uses: namespacelabs/nscloud-cache-action@a90bb5d4b27522ce881c6e98eebd7d7e6d1653f9 # v1.4.2
with:
cache: |
rust
${{ inputs.target_os == 'macos' && 'brew' || '' }}
- name: Install cargo-binstall
uses: cargo-bins/cargo-binstall@dc19f1e48450eefe5a29b8da6c6b00a87d730b37 # v1.18.1
env:
BINSTALL_VERSION: 1.14.4
# Load the SSH key needed to clone the private warp-channel-config repo. Only
# run in warpdotdev/warp-internal; elsewhere (mirrors, fork PRs) this is a no-op
# and install_channel_config falls back gracefully.
- name: Setup SSH keys for warp-channel-config
if: ${{ github.repository == 'warpdotdev/warp-internal' && inputs.ssh_key != '' }}
uses: webfactory/ssh-agent@e83874834305fe9a4a2997156cb26c5de65a8555 # v0.10.0
with:
ssh-private-key: ${{ inputs.ssh_key }}
- name: Install dependencies
shell: bash
run: |
cd "${{ steps.repo-root.outputs.path }}"
if ${{ inputs.target_os == 'macos' }}; then
# Try to install warp-channel-config but don't complain if it cannot
# be installed.
./script/install_channel_config || true
if ${{ inputs.install_release_deps == 'true' }}; then
./script/install_cargo_release_deps
else
./script/install_cargo_build_deps
fi
elif ${{ inputs.target_os == 'linux' }}; then
# Update the apt cache before installing dependencies - it can be slow, so the install scripts
# don't do it.
sudo apt-get update -y
if ${{ inputs.install_test_deps == 'true' }}; then
./script/linux/install_test_deps
elif ${{ inputs.install_release_deps == 'true' }}; then
./script/linux/install_build_deps
./script/install_cargo_release_deps
else
./script/linux/install_build_deps
fi
elif ${{ inputs.target_os == 'windows' }}; then
./script/windows/install_build_deps.ps1
if ${{ inputs.install_release_deps == 'true' }}; then
./script/install_cargo_release_deps
fi
elif ${{ inputs.target_os == 'wasm' }}; then
# Update the apt cache before installing dependencies - it can be slow, so the install scripts
# don't do it (to avoid doing it more than once).
sudo apt update -y
./script/wasm/install_build_deps
else
echo "::error::Missing logic to install build dependencies for OS \"${{ inputs.target_os }}\""
exit 1
fi
- name: Install Node
uses: actions/setup-node@3235b876344d2a9aa001b8d1453c930bba69e610 # v3.9.1
with:
node-version: 20.9.0
- name: Enable Corepack
# Enables NodeJS's Corepack tool, which is necessary to use the right version of `yarn` to
# build TS command signatures.
shell: bash
run: corepack enable
- name: Install protoc for generating rust bindings of protobuf APIs
id: install_protoc
# Install protoc for generating rust bindings of protobuf APIs.
uses: ConorMacBride/install-package@3e7ad059e07782ee54fa35f827df52aae0626f30 # v1
# Don't fail the job here so the winget fallback below has a chance to run on Windows.
continue-on-error: true
with:
brew: protobuf
choco: protoc
- name: Install protoc via winget (fallback for Windows)
if: ${{ inputs.target_os == 'windows' && steps.install_protoc.outcome == 'failure' }}
shell: pwsh
run: winget install Google.Protobuf
- name: Fail if protoc install did not succeed
if: ${{ inputs.target_os != 'windows' && steps.install_protoc.outcome == 'failure' }}
shell: bash
run: |
echo "::error::protoc install step failed on ${{ inputs.target_os }}"
exit 1
- uses: maxim-lobanov/setup-xcode@ed7a3b1fda3918c0306d1b724322adc0b8cc0a90 # v1.7.0
if: ${{ inputs.target_os == 'macos' && inputs.is_self_hosted != 'true' }}
with:
xcode-version: '26'