name: Update maplibre-native dependency

on:
  schedule:
    # The first day of every month at 12:00 AM UTC
    - cron: "0 12 1 * *"
  workflow_dispatch:

permissions:
  contents: write
  pull-requests: write

jobs:
  update-dependency:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
        with:
          persist-credentials: false
          submodules: true
      - name: Install just
        uses: taiki-e/install-action@7a79fe8c3a13344501c80d99cae481c1c9085912 # v2.81.10
        with:
          tool: just

      - name: Update maplibre-native
        run: just update-maplibre-native

      - name: Get maplibre-native details
        id: maplibre-details
        run: |
          echo "details<<EOF" >> $GITHUB_OUTPUT
          just maplibre-native-info >> "$GITHUB_OUTPUT"
          echo "EOF" >> $GITHUB_OUTPUT

      - name: Create Pull Request
        uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8.1.1
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          commit-message: "chore: update `maplibre-native`"
          title: "chore(deps): update `maplibre-native`"
          body: |
            ## Automated `maplibre-native` dependency update

            This PR updates `package.metadata.mln.release` in `Cargo.toml` to the latest Maplibre Native Core release.

            ${{ steps.maplibre-details.outputs.details }}
          branch: update-maplibre-native-dependency
          delete-branch: true
          labels: dependencies
