# Regularly update the minimum version of astropy-iers-data in pyproject.toml,
# to ensure that if users update astropy, astropy-iers-data will also get
# updated to a recent version.

name: Auto-update astropy-iers-data minimum version

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

permissions:
  contents: read

jobs:

  update-astropy-iers-data-pin:
    permissions:
      contents: write  # for peter-evans/create-pull-request to create branch
      pull-requests: write  # for peter-evans/create-pull-request to create a PR
    name: Auto-update astropy-iers-data minimum version
    runs-on: ubuntu-latest
    if: github.repository == 'astropy/astropy'
    steps:
    - name: Checkout code
      uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871  # v4.2.1
      with:
        persist-credentials: false
    - name: Set up Python
      uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38  # v5.4.0
      with:
        python-version: 3.x
    - name: Install dependencies
      run: pip install requests
    - name: Run update script
      run: python .github/workflows/update_astropy_iers_data_pin.py
    - name: Commit changes
      run: |
        git config user.name github-actions
        git config user.email github-actions@github.com
        git add pyproject.toml
        if ! git diff --cached --exit-code; then
          git commit -m "Update minimum required version of astropy-iers-data"
        fi
    - name: Create Pull Request
      uses: peter-evans/create-pull-request@67ccf781d68cd99b580ae25a5c18a1cc84ffff1f  # v7.0.6
      with:
        branch: update-astropy-iers-data-pin
        branch-suffix: timestamp
        delete-branch: true
        labels: no-changelog-entry-needed, utils.iers
        title: Update minimum required version of astropy-iers-data
        body: |
          This is an automated update of the minimum version of astropy-iers-data package.

          :pray: Please apply backport labels to any active backport branches for v6.0.x or later. :pray:

          :warning: Please close and re-open this pull request to trigger the CI. :warning:
