name: Automatic Calendar Version 
on:
  schedule:
    # At 03:00 UTC every Tuesday in preparation for an RC.
    # The tool assumes the release is published in 6-days (the following Monday).
    # Note: Most of these runs will be no-op until the release month changes.
    - cron: '0 3 * * 2'
  workflow_dispatch:

permissions: {}

# Bumps the year and month, resetting the patch.
# Patch bumps are handled by the release script.
jobs:
  automatic-calendar-version:
    runs-on: macos-15
    timeout-minutes: 15
    
    # Skip in forks
    if: github.repository == 'element-hq/element-x-ios'
    steps:
      - name: Checkout
        uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
        with:
          persist-credentials: false

      - name: Setup environment
        run: 
          source ci_scripts/ci_common.sh && setup_github_actions_environment

      - name: Bump the CalVer if needed
        run: swift run -q tools bump-calendar-version

      - name: Create a PR for the new version
        uses: peter-evans/create-pull-request@c0f553fe549906ede9cf27b5156039d195d2ece0 # v8.1.0
        with:
          token: ${{ secrets.ELEMENT_BOT_TOKEN }}
          author: ElementRobot <releases@riot.im>
          commit-message: Bump the calendar version ready for the next release
          title: Bump the calendar version ready for the next release
          body: |
            - Version bump
          labels: pr-build
          branch: version/bump
          base: develop
          add-paths: |
            *.yml
            *.xcodeproj/**
