# This is a GitHub Action workflow to build toolbox zip/ MLTBX and upload it to a GitHub release

name: Update a published release with build artifacts

# Start the workflow when a release is published.
on:
  release:
    types: [published]

# A workflow run consists of jobs that run sequentially
jobs:
  # This workflow contains one job that builds the zip and MLTBX files.
  AttachBuildArtifacts:
    # The type of runner that the job will run on, we use latest Ubuntu
    runs-on: ubuntu-latest
    steps:
      # Runs commands using the runners shell
      - name: checkout the repo
        uses: actions/checkout@v3

      - name: Zip the toolbox
        run: zip -r '${{  github.ref_name }}.zip' Psychtoolbox

      - name: Set up MATLAB
        uses: matlab-actions/setup-matlab@v1

      - name: Create MLTBX
        uses: matlab-actions/run-command@v1
        continue-on-error: false
        if: always()
        with:
          command: addpath([pwd filesep 'managementtools']); createPsychtoolboxMLTBX("Psychtoolbox.prj",  "${{  github.ref_name }}")

      - name: Upload artifacts to release
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: |
          gh release upload "${{  github.ref_name }}" "./${{  github.ref_name }}.mltbx"
          gh release upload "${{  github.ref_name }}" "./${{  github.ref_name }}.zip"
    


      # # This is for diagnostics
      # - name: list directories
      #   run: ls -l
