# compiles angular frontend and attaches it to the latest release.
name: Release Frontend

on:
  release:
    # Only use the types keyword to narrow down the activity types that will trigger your workflow.
    types: [published]
jobs:
  release-frontend:
    name: Release Frontend
    runs-on: ubuntu-latest
    container: node:lts-slim
    steps:
      - name: Checkout
        uses: actions/checkout@v2
        with:
          ref: ${{github.event.release.tag_name}}
      - name: Build Frontend
        run: |
          cd webapp/frontend
          npm install -g @angular/cli@9.1.4
          npm install
          mkdir -p dist
          ng build --output-path=dist --deploy-url="/web/" --base-href="/web/" --prod
          tar -czf scrutiny-web-frontend.tar.gz dist
      - name: Upload Frontend Asset
        id: upload-release-asset3
        uses: actions/upload-release-asset@v1
        env:
          GITHUB_TOKEN: ${{ secrets.SCRUTINY_GITHUB_TOKEN }}
        with:
          upload_url: ${{ github.event.release.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
          asset_path: './webapp/frontend/scrutiny-web-frontend.tar.gz'
          asset_name: scrutiny-web-frontend.tar.gz
          asset_content_type: application/gzip
