
# (C) 2022 Jack Lloyd
# (C) 2022 René Meusel, Rohde & Schwarz Cybersecurity
#
# Botan is released under the Simplified BSD License (see license.txt)

name: Setup Botan Build Agent
description: Set up a build agent for building and testing the Botan library

inputs:
  target:
    description: The ci_build.py target going to be built on this agent
    required: true
  cache-key:
    description: The actions/cache key to be used for this runs, caching will be disabled when no key is provided
    required: false
  arch:
    description: Target CPU architecture
    required: false
    default: x64

runs:
  using: composite
  steps:
    - name: Setup Build Agent (Windows)
      run: ${{ github.action_path }}/../../../src/scripts/ci/setup_gh_actions.ps1 "${{ inputs.target }}" "${{ inputs.arch }}"
      shell: pwsh
      if: runner.os == 'Windows'
    - name: Setup Build Agent (Unix-like)
      run: ${{ github.action_path }}/../../../src/scripts/ci/setup_gh_actions.sh "${{ inputs.target }}" "${{ inputs.arch }}"
      shell: bash
      if: runner.os != 'Windows'

    - name: Check Availability of Compiler Cache
      run: print("::warning ::No compiler cache available, build times might suffer")
      shell: python
      if: env.COMPILER_CACHE_LOCATION == '' && inputs.cache-key != ''
    - uses: actions/cache@v3
      if: env.COMPILER_CACHE_LOCATION != '' && inputs.cache-key != ''
      with:
          path: ${{ env.COMPILER_CACHE_LOCATION }}
          key: ${{ inputs.cache-key }}-${{ github.run_id }}
          restore-keys: ${{ inputs.cache-key }}

    - name: Setup Visual Studio Environment
      uses: egor-tensin/vs-shell@v2
      with:
        arch: ${{ env.VSENV_ARCH }} # set by setup_gh_actions.ps1
      if: runner.os == 'Windows'

    - name: Install Build Dependencies # after setting up Visual Studio Environment
      run: ${{ github.action_path }}/../../../src/scripts/ci/setup_gh_actions_after_vcvars.ps1 ${{ inputs.target }}
      shell: pwsh
      if: runner.os == 'Windows'
