name: Prep Appspot Deployment

description: |
  A reusable action that prepares the sources to deploy the Shaka Player Demo
  to appspot.  Assumes that the source is already checked out.

runs:
  using: composite
  steps:
    - name: Install dependencies
      shell: bash
      run: npm ci

    - name: Build Shaka Player
      shell: bash
      run: python build/all.py

    - name: Extract git version
      shell: bash
      run: |
        (
          cd build
          python3 -c 'from shakaBuildHelpers import git_version; print(git_version())'
        ) > demo-version

    - name: Tag the Player version
      shell: bash
      run: |
        DEMO_VERSION="$(cat demo-version)-uncompiled"
        sed \
            -i lib/player.js \
            -e "s/\(shaka.Player.version\) = .*/\1 = '$DEMO_VERSION';/"
        rm demo-version

    - name: Backup demo node modules
      shell: bash
      run: |
        DEMO_NODE_MODULES=$(jq -r .shakaCustom.demoDeps[] package.json)
        tar cf demo-modules.tar \
            $(echo "$DEMO_NODE_MODULES" | sed -e 's@^@node_modules/@')

    - name: Delete unneeded files
      shell: bash
      run: rm -rf .git .github build externs test node_modules

    - name: Restore demo node modules
      shell: bash
      run: |
        tar xf demo-modules.tar
        rm demo-modules.tar

    - name: Install App Engine code
      shell: bash
      run: |
        mv app-engine/shaka-player-demo/* .
        rm README.md
