# https://medium.com/@superseb/maintenance-free-renovate-using-github-actions-workflows-d91d32ad854a
# https://github.com/renovatebot/github-action
name: renovate
on:
  # Allows manual/automated ad-hoc trigger
  workflow_dispatch:
    inputs:
      logLevel:
        description: "Override default log level"
        required: false
        default: "info"
        type: string
      overrideSchedule:
        description: "Override all schedules"
        required: false
        default: "false"
        type: string
  # Run twice in the early morning for initial and follow up steps (create pull request and merge)
  schedule:
    - cron: "30 4,6 * * *"
concurrency: renovate
jobs:
  renovate:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/create-github-app-token@v3
        id: get_token
        with:
          private-key: ${{ secrets.INTBOT_PRIVATE_KEY }}
          app-id: ${{ secrets.INTBOT_APP_ID }}
        #   owner: ${{ github.repository_owner }}
        #   repositories: ${{ github.repository }}
      - uses: actions/checkout@v7
        with:
          token: ${{ steps.get_token.outputs.token }}
          ref: ${{ github.head_ref }}
          # Make sure the value of GITHUB_TOKEN will not be persisted in repo's config
          persist-credentials: false
      - uses: renovatebot/github-action@v46.1.0
        env:
          # Repository taken from variable to keep configuration file generic
          RENOVATE_REPOSITORIES: ${{ github.repository }}
          # Onboarding not needed for self hosted
          RENOVATE_ONBOARDING: "false"
          # Username for GitHub authentication (should match GitHub App name + [bot])
          # RENOVATE_USERNAME: ""
          # Git commit author used, must match GitHub App
          # RENOVATE_GIT_AUTHOR: ""
          # Use GitHub API to create commits (this allows for signed commits from GitHub App)
          RENOVATE_PLATFORM_COMMIT: "true"
          # Override schedule if set
          RENOVATE_FORCE: ${{ github.event.inputs.overrideSchedule == 'true' && '{''schedule'':null}' || '' }}
          LOG_LEVEL: ${{ inputs.logLevel || 'info' }}
        with:
          configurationFile: .github/renovate.json5
          token: "${{ steps.get_token.outputs.token }}"
