Debugging Renovate locally
Tags: renovate, devops
Published: 2023-05-09 22:00:00

## Introduction

If you are using Renovate, it is important to check whether the settings are properly configured.

This article explains how to debug Renovate in a local environment.

## Prerequisites

The following prerequisites are required:

- Generate GitHub's Classic PAT and set it in the environment variable such as `GITHUB_TOKEN`.
    - If it's only dry-run, read permission to the repository should be sufficient.

## Verification Procedure

Just execute the following command:

```sh
RENOVATE_CONFIG_FILE=.github/renovate.json5 \
  npx renovate \
    --token=$GITHUB_TOKEN \
    --schedule="" \
    --require-config=ignored \
    --dry-run=full \
    corrupt952/home-apps
```

You can check whether the target is correct and whether a PR is created by using stats or messages displayed in `DRY-RUN`.

```sh
$ RENOVATE_CONFIG_FILE=.github/renovate.json5 \
    npx renovate \
      --token=$GITHUB_TOKEN \
      --schedule="" \
      --require-config=ignored \
      --dry-run=full \
      corrupt952/home-apps
 INFO: Repository started (repository=corrupt952/home-apps)
       "renovateVersion": "35.71.5"
 INFO: Dependency extraction complete (repository=corrupt952/home-apps, baseBranch=main)
       "stats": {
         "managers": {
           "argocd": {"fileCount": 5, "depCount": 6},
           "kubernetes": {"fileCount": 1, "depCount": 2},
           "regex": {"fileCount": 5, "depCount": 15}
         },
         "total": {"fileCount": 11, "depCount": 23}
       }
 INFO: DRY-RUN: Would ensure Dependency Dashboard (repository=corrupt952/home-apps)
       "title": "Dependency Dashboard"
 INFO: DRY-RUN: Would save repository cache. (repository=corrupt952/home-apps)
 INFO: Repository finished (repository=corrupt952/home-apps)
       "cloned": true,
       "durationMs": 6888
```

### Brief explanation of the command

The following is an explanation of the command mentioned in the verification procedure:

- `RENOVATE_CONFIG_FILE=.github/renovate.json5`
    - Specifies the path of the configuration file you want to test the operation of.
    - The configuration file contains the information necessary for Renovate to operate.
    - For details, refer to the [official Renovate documentation](https://docs.renovatebot.com/getting-started/running/#global-config).
- `npx renovate`
    - Since you want to try renovate easily without installing it individually, you are running renovate using npx.
- `token=$GITHUB_TOKEN`
    - Specifies the PAT generated in advance.
    - PAT is necessary for Renovate to access the GitHub API.
    - For details, refer to the [official Renovate documentation](https://docs.renovatebot.com/self-hosted-configuration/#token).
- `schedule=""`
    - Since it may not be executed if the schedule is defined in the settings, an empty string is specified.
- `require-config=ignored`
    - Prevents the remote repository's configuration file from being read.
    - If the remote repository's configuration file is read, it will be merged with the local configuration file, which may result in unnecessary PRs being generated.
    - For details, refer to the [official Renovate documentation](https://docs.renovatebot.com/self-hosted-configuration/#requireconfig).
- `dry-run=full`
    - It outputs messages to standard output without actually creating, updating, or deleting PRs.
    - For details, refer to the [official Renovate documentation](https://docs.renovatebot.com/self-hosted-configuration/#dryrun).
- `corrupt952/home-apps`
    - Specifies the repository targeted by Renovate.
    - In this example, `corrupt952/home-apps` is targeted.

## Other cases that are likely to occur when verifying the operation

### I want to validate a branch other than the default branch.

Execute by specifying `RENOVATE_BASE_BRANCHES`.

```sh
# In the case of targeting the dev branch
RENOVATE_BASE_BRANCHES=dev \
RENOVATE_CONFIG_FILE=.github/renovate.json5 \
  npx renovate \
    --token=$GITHUB_TOKEN \
    --schedule="" \
    --require-config=ignored \
    --dry-run=full \
    corrupt952/home-apps
```

### I want to create a PR.

Confirm that PAT has write permission to the repository and remove the `--dry-run` option.

```sh
RENOVATE_CONFIG_FILE=.github/renovate.json5 \
  npx renovate \
    --token=$GITHUB_TOKEN \
    --schedule="" \
    --require-config=ignored \
    corrupt952/home-apps
```

## Conclusion

This article explained how to debug Renovate locally.

If you are using Renovate, it is important to check whether the settings are properly configured.

Please execute the procedure explained in this article to use Renovate normally.