name: Update Data
on:
  workflow_dispatch:
  push:
  schedule:
    # 18:07 UTC every day
    # 23:37 IST every day
    - cron: '7 18 * * *'
jobs:
  update:
    name: Update data
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v3
      with:
        ref: ${{ github.head_ref }}
    - name: Update data
      run: make update
      id: update_data
    # Only tag if we're running on the scheduled job
    - uses: stefanzweifel/git-auto-commit-action@v4
      id: auto-commit-action
      with:
        commit_message: Update ISIN Data
        commit_author: 'github-actions[bot] <github-actions[bot]@users.noreply.github.com>'
        file_pattern: "ISIN.csv"
        status_options: '--untracked-files=no'
        tagging_message: "v${{ steps.update_data.outputs.version }}"
    - name: Create Release
      if: steps.auto-commit-action.outputs.changes_detected == 'true'
      run: |
        pip install -r src/requirements.txt
        make release "version=v${{ steps.update_data.outputs.version }}"
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
