name: "Nightly deploy"

on:
  schedule:
    - cron: '0 2 * * *'
  workflow_dispatch:

jobs:
  nightly:
    name: Deploy nightly
    strategy:
      fail-fast: false
      matrix:
        refs: [main, development]
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
        with:
          ref: ${{ matrix.refs }}
          submodules: 'recursive'
      - name: Restore private key
        run: |
          echo "${{ secrets.PRIVATE_KEY_B64 }}" | base64 -d > private.pem
          chmod 600 private.pem
      - name : Build
        env:
          PICO_SDK_PATH: ../pico-sdk
          SECURE_BOOT_PKEY: ../private.pem
        run: |
           ./workflows/autobuild.sh pico
           ./build_pico_fido.sh --no-eddsa
           ./workflows/autobuild.sh esp32
      - name: Delete private key
        run: rm private.pem
      - name: Update nightly release
        uses: pyTooling/Actions/releaser@v6.7.0
        with:
          tag: nightly-${{ matrix.refs }}
          rm: true
          token: ${{ secrets.GITHUB_TOKEN }}
          files: release/*.*
