# action.yml
name: renovate
description: 'renovate with caching'

inputs:
  endpoint:
    description: 'Renovate Endpoint'
    required: true
  token:
    description: 'Renovate Token'
    required: true
  github-token:
    description: 'GitHub Token'
    required: true
  github-username:
    description: 'GitHub Username'
    required: true
  docker-username:
    description: 'Docker Hub Username'
    required: true
  docker-password:
    description: 'Docker Hub Password'
    required: true
  args:
    description: 'Renovate Args'
    required: false
    default: ''

runs:
  using: 'composite'
  steps:
    - name: Cache Renovate
      uses: https://code.forgejo.org/actions/cache@v4.2.0
      with:
        path: |
          .tmp/cache/renovate/repository
        key: renovate-${{ inputs.endpoint }}-${{ github.run_id }}
        restore-keys: |
          renovate-${{ inputs.endpoint }}-
        compression: true
        timeout: 900000
        retry: 5
        retry-wait: 5000

    - run: |
        renovate ${{ inputs.args }}
      shell: bash
      env:
        GITHUB_COM_TOKEN: ${{ inputs.github-token }}
        LOG_LEVEL: debug
        RENOVATE_BASE_DIR: ${{ github.workspace }}/.tmp
        RENOVATE_ENDPOINT: ${{ github.server_url }}
        RENOVATE_GIT_AUTHOR: 'Renovate Bot <smeagol@hsn.dev>'
        RENOVATE_PLATFORM: gitea
        RENOVATE_REPOSITORY_CACHE: 'enabled'
        RENOVATE_TOKEN: ${{ inputs.token }}
        RENOVATE_HOST_RULES: |-
          [
            {"matchHost":"docker.io","hostType":"docker","username":"${{ inputs.docker-username }}","password":"${{ inputs.docker-password }}"},
            {"matchHost":"github.com","hostType":"github","token":"${{ inputs.github-token }}"},
          ]
        GIT_AUTHOR_NAME: 'Renovate Bot'
        GIT_AUTHOR_EMAIL: 'smeagol@hsn.dev'
        GIT_COMMITTER_NAME: 'Renovate Bot'
        GIT_COMMITTER_EMAIL: 'smeagol@hsn.dev'