renovatebot/github-action

repository·main·Indexed 19 days ago

https://github.com/renovatebot/github-action

A GitHub Action wrapper that allows running the Renovate dependency update bot self-hosted within a GitHub Actions workflow. It runs Renovate inside a Docker container and supports configuration via files, environment variables, and custom Docker settings including image versioning, volume mounts, and socket mounting.

Tokens
4.3K
Snippets
11
Records
17
Agent score
18%

What's inside renovatebot-github-action

  1. Set up the Renovate authentication token

    main

    The token option provides the authentication required for Renovate to access repositories.

    Requirements:

    • For public repositories: A Personal Access Token (classic) with repo:public_repo scope.
    • For private repositories: A Personal Access Token (classic) with repo scope.
    • Fine-grained Personal Access Tokens are supported, but classic tokens are recommended to avoid permission gaps (e.g., with Checks access).

    Implementation: Store the token in your repository secrets (e.g., as RENOVATE_TOKEN) and pass it to the action. The name of the secret can be anything as long as it matches the value provided to the token input.

  2. Persist the Renovate repository cache

    main

    To prevent Renovate from updating PRs too frequently and to speed up execution, you can persist the repository cache using actions/cache.

    Steps:

    1. Enable RENOVATE_REPOSITORY_CACHE (via env var or config).
    2. Use actions/cache/restore to restore the directory /tmp/renovate/cache/renovate/repository.
    3. Crucial: Run sudo chown -R 12021:0 /tmp/renovate/ to fix ownership, as Renovate runs inside a container as user 12021.
    4. Use actions/cache/save to save the updated directory.
    env:
      cache_dir: /tmp/renovate/cache/renovate/repository
      cache_key: renovate-cache
    
    jobs:
      renovate:
        runs-on: ubuntu-latest
        steps:
          - uses: actions/checkout@v6.1.0
    
          - name: Restore renovate cache
            id: cache-restore
            uses: actions/cache/restore@v6.1.0
            with:
              path: ${{ env.cache_dir }}
              key: ${{ env.cache_key }}-${{ github.run_id }}-${{ github.run_attempt }}
              restore-keys: | 
                ${{ env.cache_key }}-
    
          - name: Fix restored cache ownership
            if: steps.cache-restore.outputs.cache-matched-key != ''
            run: |
              sudo chown -R 12021:0 /tmp/renovate/
    
          - uses: renovatebot/github-action@v46.2.1
            with:
              configurationFile: renovate.json5
              token: ${{ secrets.RENOVATE_TOKEN }}
            env:
              RENOVATE_REPOSITORY_CACHE: enabled
    
          - name: Save renovate cache
            if: steps.cache-restore.outputs.cache-hit != 'true'
            uses: actions/cache/save@v6.1.0
            with:
              path: ${{ env.cache_dir }}
              key: ${{ env.cache_key }}-${{ github.run_id }}-${{ github.run_attempt }}
  3. Run Renovate on GitHub Enterprise

    main

    When using the action on a GitHub Enterprise instance, you must provide the RENOVATE_ENDPOINT environment variable pointing to your enterprise API endpoint.

          - name: Self-hosted Renovate
            uses: renovatebot/github-action@v46.2.1
            with:
              configurationFile: example/renovate-config.js
              token: ${{ secrets.RENOVATE_TOKEN }}
            env:
              RENOVATE_ENDPOINT: "https://git.your-company.com/api/v3"
  4. Run Renovate using a GitHub App

    main

    Using a GitHub App is preferred over a PAT for better permission tuning. This workflow uses actions/create-github-app-token to exchange the app's private key for a temporary access token.

    Prerequisites:

    1. Create a GitHub App and install it in your account/org.
    2. Add the app's private key to GitHub Secrets as private_key.
    3. Add the app ID to GitHub Secrets as app_id.
    4. Configure your Renovate config to specify the bot's username.
    name: Renovate
    on:
      schedule:
        - cron: '0/15 * * * *'
    jobs:
      renovate:
        runs-on: ubuntu-latest
        steps:
          - name: Get token
            id: get_token
            uses: actions/create-github-app-token@v1
            with:
              private-key: ${{ secrets.private_key }}
              app-id: ${{ secrets.app_id }}
              owner: ${{ github.repository_owner }}
              repositories: 'repo1,repo2'
    
          - name: Checkout
            uses: actions/checkout@v6.1.0
    
          - name: Self-hosted Renovate
            uses: renovatebot/github-action@v46.2.1
            with:
              configurationFile: example/renovate-config.js
              token: '${{ steps.get_token.outputs.token }}'
  5. Enable Commit Signing with GitHub App

    main

    When running as a GitHub App, Renovate can sign commits using GitHub's API-based commits. To enable this, set the RENOVATE_PLATFORM_COMMIT environment variable to enabled and ensure platformCommit: enabled is present in your Renovate configuration.

    - name: Self-hosted Renovate
      uses: renovatebot/github-action@v46.2.1
      with:
        token: '${{ steps.get_token.outputs.token }}'
      env:
        RENOVATE_PLATFORM_COMMIT: 'enabled'
  6. Run Renovate with a Personal Access Token (PAT)

    main

    To run Renovate using a standard GitHub Personal Access Token, configure the token input in your workflow. It is recommended to store the token in a GitHub Secret (e.g., RENOVATE_TOKEN).

    name: Renovate
    on:
      schedule:
        - cron: '0/15 * * * *'
    jobs:
      renovate:
        runs-on: ubuntu-latest
        steps:
          - name: Checkout
            uses: actions/checkout@v6.1.0
          - name: Self-hosted Renovate
            uses: renovatebot/github-action@v46.2.1
            with:
              configurationFile: example/renovate-config.js
              token: ${{ secrets.RENOVATE_TOKEN }}
  7. Specify custom Renovate Docker images and versions

    main

    You can control which Renovate image and version the action uses:

    • renovate-image: The full Docker image name. If omitted, it defaults to ghcr.io/renovatebot/renovate:<renovate-version>.
    • renovate-version: The specific version/tag of Renovate. If omitted, it uses the default version. You can use the full tag to use the full image.

    Recommendation: Pin the version to a specific version or a full checksum to ensure stability.

    # Using a custom image
    - name: Self-hosted Renovate
      uses: renovatebot/github-action@v46.2.1
      with:
        renovate-image: myproxyhub.domain.com/renovate/renovate
        token: ${{ secrets.RENOVATE_TOKEN }}
    
    # Using a specific version
    - name: Self-hosted Renovate
      uses: renovatebot/github-action@v46.2.1
      with:
        renovate-version: 44.11.6
        token: ${{ secrets.RENOVATE_TOKEN }}
    
    # Using the 'full' image
    - name: Self-hosted Renovate
      uses: renovatebot/github-action@v46.2.1
      with:
        renovate-version: full
        token: ${{ secrets.RENOVATE_TOKEN }}
  8. Configure Docker networking and socket mounting

    main

    Use these options to control how the Renovate container interacts with the Docker environment:

    • docker-network: Specify a network for the container. Use ${{ job.container.network }} to join the job's container network, host to use the runner's network, or specify a custom network.
    • mount-docker-socket: (Default: false) If set to true, the action mounts the Docker socket into the container and adds the user to the docker group. This allows Renovate to run Docker commands, which is useful for postUpgradeTasks.
    • docker-socket-host-path: Only applicable when mount-docker-socket is true. Overrides the host path for the Docker socket (defaults to /var/run/docker.sock).
  9. Manage Docker volumes and users

    main

    Control volume mounts and the execution user for the Renovate container:

    • docker-volumes: Specify volume mounts using the format /host:/container. Multiple mounts are separated by a semicolon (;). Defaults to /tmp:/tmp.
    • docker-user: Specify a user or user-id to run the Docker command. This can be used with docker-cmd-file to start as root for customization before switching to an unprivileged user.
    jobs:
      renovate:
        runs-on: ubuntu-latest
        steps:
          - name: Checkout
            uses: actions/checkout@v6.1.0
          - name: Self-hosted Renovate
            uses: renovatebot/github-action@v46.2.1
            with:
              token: ${{ secrets.RENOVATE_TOKEN }}
              docker-volumes: |
                /tmp:/tmp ;
                /foo:/bar
  10. Configure the Renovate global configuration file

    main

    Use the configurationFile option to provide a JavaScript or JSON file that configures Renovate globally. It is recommended to avoid using standard Renovate repository configuration filenames to prevent conflicts.

    To use a single global configuration file and prevent Renovate from looking for repository-specific configs or attempting onboarding, include these two lines in your config:

      onboarding: false,
      requireConfig: 'optional',

    Note: The branchPrefix option should be configured to a value other than the default to avoid interference with the Renovate GitHub App.

  11. Pass custom environment variables via `env-regex`

    main

    Environment variables prefixed with RENOVATE_ are automatically passed to the Docker container. To pass other custom variables (e.g., for hostRules), you must whitelist them using the env-regex input. The regex defines which environment variables are allowed through to the container.

          - name: Self-hosted Renovate
            uses: renovatebot/github-action@v46.2.1
            with:
              configurationFile: example/renovate-config.js
              token: ${{ secrets.RENOVATE_TOKEN }}
              env-regex: "^(?:RENOVATE_\\w+|LOG_LEVEL|GITHUB_COM_TOKEN|NODE_OPTIONS|NO_COLOR|(?:HTTPS?|NO)_PROXY|(?:https?|no)_proxy|CUSTOM_TFE_TOKEN)$"
            env:
              CUSTOM_TFE_TOKEN: ${{ secrets.MY_TFE_TOKEN }}

    Then in your renovate-config.js:

    module.exports = {
      hostRules: [
        {
          hostType: 'terraform-module',
          matchHost: 'app.terraform.io',
          token: process.env.CUSTOM_TFE_TOKEN,
        },
      ],
    };