name: Automated Maintenance v1
on:
  schedule:
    - cron: "0 8,20 * * *"
  workflow_dispatch: # Enables on-demand/manual triggering: https://docs.github.com/en/free-pro-team@latest/actions/managing-workflow-runs/manually-running-a-workflow

permissions:
  contents: write
  pull-requests: write
jobs:
  job:
    runs-on: ubuntu-latest
    if: github.repository == 'aws-cloudformation/cfn-lint'
    steps:
      - uses: actions/checkout@v6
        with:
          ref: "main"
      - uses: actions/setup-python@v6
        with:
          python-version: 3.13
      - id: maintenance
        run: |
          latest_sam_cli=`curl -s https://api.github.com/repos/aws/aws-sam-cli/releases/latest | jq -r .tag_name | cut -c 2-`
          latest=`curl "https://pypi.org/pypi/aws-sam-cli/$latest_sam_cli/json" -s | jq -r '.info.requires_dist[] | select(contains("aws-sam-translator"))' | cut -c 21-`
          sed -i -E "s/aws-sam-translator>=[0-9.]+/aws-sam-translator>=$latest/" requirements/base.txt
          pip install -e .
          pip install requests
          rm -rf src/cfnlint/data/DownloadsMetadata/*
          cfn-lint --update-iam-policies
          cfn-lint --update-documentation
          scripts/update_specs_from_pricing.py
          scripts/update_serverless_aws_policies.py
          scripts/smithy/update_schemas_from_smithy.py
          scripts/update_schemas_from_aws_api.py
          cfn-lint --update-specs
          echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT
        env:
          AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
          AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
      - uses: peter-evans/create-pull-request@v8
        with:
          branch: create-pull-request/maintenance-v1
          commit-message: |
            Update CloudFormation schemas to ${{ steps.maintenance.outputs.date }}
          body: |
            - Update CloudFormation schemas to ${{ steps.maintenance.outputs.date }}
            - Update Specs from pricing data as of ${{ steps.maintenance.outputs.date }}

            Automated changes by [create-pull-request](https://github.com/peter-evans/create-pull-request) GitHub action
          delete-branch: true
          title: Update CloudFormation schemas to ${{ steps.maintenance.outputs.date }}
