# SPDX-FileCopyrightText: 2025 Tim Cocks, written for Adafruit Industries
#
# SPDX-License-Identifier: MIT

name: Daily Release Check

on:
  schedule:
    - cron: 15 8 * * *
  workflow_dispatch:

jobs:
  release_check:
    if: github.repository_owner == 'adafruit'
    runs-on: ubuntu-latest
    outputs:
      release_created: ${{ steps.check_release.outputs.release_created }}
      assets_upload_url: ${{ steps.check_release.outputs.assets_upload_url }}
    steps:
    - name: Set up requested Python version
      uses: actions/setup-python@v5
      with:
        python-version: 3.12
    - name: Versions
      shell: bash
      run: |
        python3 --version
    - name: Checkout Current Repo
      uses: actions/checkout@v4
      with:
        submodules: true
        show-progress: false
    - name: Install reqs
      shell: bash
      run: |
        pip install -r requirements.txt
    - name: Create Release If Needed
      id: check_release
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      shell: bash
      run: |
        python release_updater.py make_release

  upload_release_assets:
    needs: release_check
    if: github.repository_owner == 'adafruit' && needs.release_check.outputs.release_created == 'true'
    runs-on: ubuntu-latest
    steps:
      - name: Set up requested Python version
        uses: actions/setup-python@v5
        with:
          python-version: 3.12
      - name: Versions
        shell: bash
        run: |
          python3 --version
      - name: Checkout Current Repo
        uses: actions/checkout@v4
        with:
          submodules: true
          show-progress: false
      - name: Install reqs
        shell: bash
        run: |
          pip install -r requirements.txt
      - name: Build assets
        shell: bash
        run: |
          python build.py
      - name: Upload Release Assets
        uses: shogo82148/actions-upload-release-asset@v1
        with:
          asset_path: "dist/*"
          github_token: ${{ secrets.GITHUB_TOKEN }}
          upload_url: ${{ needs.release_check.outputs.assets_upload_url }}
