# Basic workflow to build the project periodically. This basically serves as a check on dependencies
# which can sometimes change and break scripts in ways that aren't discovered until much later.

name: Periodic Build

# run using a cron schedule. '0 4 * * 6' is every Saturday at 4 a.m. UTC (9 pm Pacific)
on:
  schedule:
    - cron: '0 4 * * 6'
  workflow_dispatch:
    inputs:
      reason:
        description: 'Reason for running workflow'
        required: true

jobs:
  build:
    name: Build Adobe VF Prototype
    runs-on: ubuntu-latest

    steps:
      - name: Log reason (manual run only)
        if: github.event_name == 'workflow_dispatch'
        run: |
          echo "Reason for triggering: ${{ github.event.inputs.reason }}"

      - name: Get latest release with tag
        id: latestrelease
        run: |
          echo "::set-output name=releasetag::$(curl -s --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' https://api.github.com/repos/adobe-fonts/adobe-variable-font-prototype/releases/latest | jq '.tag_name' | sed 's/\"//g')"

      - name: Log tag
        run: |
          echo 'Latest: ${{ steps.latestrelease.outputs.releasetag }}'

      - name: Check out the release
        uses: actions/checkout@v2
        with:
          ref: ${{ steps.latestrelease.outputs.releasetag }}

      - name: Set up Python 3.7
        uses: actions/setup-python@v1
        with:
          python-version: 3.7

      - name: Install requirements
        run: |
          python -m pip install --upgrade pip
          pip install -r requirements-dev.txt

      - name: Run buildFont.sh
        run: |
          bash ./buildFont.sh

      - name: Run tests
        run: |
          pytest -v
