name: Upload Release Asset

on:
  push:
    tags:
    - '*.*.*'

jobs:
  build:
    name: Upload Release Asset
    runs-on: ubuntu-20.04
    steps:
      - name: Checkout code
        uses: actions/checkout@v2
        # BuildStream requires tags to be able to find its version.
        with:
          fetch-depth: 0

      - name: Give `testuser` ownership of the source directory
        run: sudo chown -R 1000:1000 ${GITHUB_WORKSPACE}

      - name: Build documentation using Docker Compose
        run: |
          docker-compose \
            --env-file ${GITHUB_WORKSPACE}/.github/common.env \
            --file ${GITHUB_WORKSPACE}/.github/compose/ci.docker-compose.yml \
            run \
            docs

          # Restore permissions to the current user
          sudo chown -R ${USER} ${GITHUB_WORKSPACE}

          tar -C doc/build/html -zcf docs.tgz .

      - name: Upload release assets
        run: |
          tag_name="${GITHUB_REF##*/}"
          hub release create -a "docs.tgz" -m "$tag_name" "$tag_name"
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
