name: "Setup emscripten"
description: "Setup emcc"
inputs:
  emscripten-version:
    required: true
    description: "emscripten version"
runs:
  using: "composite"

  steps:
    - name: "get emscripten cached location"
      shell: bash
      run: |
        echo "emscripten_path=$(pwd)/emsdk" >> $GITHUB_ENV
    - name: cache emscripten
      id: cache-emscripten
      uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 # 4.2.0
      with:
        path: ${{ env.emscripten_path }}
        key: emscripten-${{ inputs.emscripten-version }}
    - name: install emscripten
      shell: bash
      if: steps.cache-emscripten.outputs.cache-hit != 'true'
      run: |
        git clone --branch ${{ inputs.emscripten-version }} https://github.com/emscripten-core/emsdk.git
        cd emsdk
        ./emsdk install latest
        ./emsdk activate latest
        source ./emsdk_env.sh
    - name: add emscripten to path
      shell: bash
      run: |
        echo ${{ env.emscripten_path }}/upstream/bin >> $GITHUB_PATH
        echo ${{ env.emscripten_path }}/upstream/emscripten >> $GITHUB_PATH