name: Update AAGUIDs

on:
  schedule:
    - cron: "0 0 * * 1" # Runs every Monday at midnight
  workflow_dispatch: # Allows manual triggering of the workflow

permissions: 
    contents: write
    
jobs:
  update-aaguids:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Fetch JSON data
        run: |
          curl -o data.json https://raw.githubusercontent.com/pocket-id/passkey-aaguids/refs/heads/main/combined_aaguid.json

      - name: Process JSON data
        run: |
          mkdir -p backend/resources
          jq -c 'map_values(.name)' data.json > backend/resources/aaguids.json

      - name: Commit changes
        run: |
          git config --local user.email "action@github.com"
          git config --local user.name "GitHub Action"
          git add backend/resources/aaguids.json
          git diff --staged --quiet || git commit -m "chore: update AAGUIDs"
          git push
