|
| 1 | +# -------------------------------------------------------------------------------------- |
| 2 | +# Renovate Bot Job Template |
| 3 | +# -------------------------------------------------------------------------------------- |
| 4 | +# This Azure DevOps pipeline job template runs Renovate (https://docs.renovatebot.com/) |
| 5 | +# to automatically update dependencies in a GitHub repository. |
| 6 | +# |
| 7 | +# Renovate scans the repository for dependency files and creates pull requests to update |
| 8 | +# outdated dependencies based on the configuration specified in the renovateConfigPath |
| 9 | +# parameter. |
| 10 | +# |
| 11 | +# Usage: |
| 12 | +# For each product repo wanting to make use of Renovate, this template is called from |
| 13 | +# an internal Azure DevOps pipeline, typically with a schedule trigger, to check for |
| 14 | +# and propose dependency updates. |
| 15 | +# |
| 16 | +# For more info, see https://github.com/dotnet/arcade/blob/main/Documentation/Renovate.md |
| 17 | +# -------------------------------------------------------------------------------------- |
| 18 | + |
| 19 | +parameters: |
| 20 | + |
| 21 | +# Path to the Renovate configuration file within the repository. |
| 22 | +- name: renovateConfigPath |
| 23 | + type: string |
| 24 | + default: 'eng/renovate.json' |
| 25 | + |
| 26 | +# GitHub repository to run Renovate against, in the format 'owner/repo'. |
| 27 | +# This could technically be any repo but convention is to target the same |
| 28 | +# repo that contains the calling pipeline. The Renovate config file would |
| 29 | +# be co-located with the pipeline's repo and, in most cases, the config |
| 30 | +# file is specific to the repo being targeted. |
| 31 | +- name: gitHubRepo |
| 32 | + type: string |
| 33 | + |
| 34 | +# List of base branches to target for Renovate PRs. |
| 35 | +# NOTE: The Renovate configuration file is always read from the branch where the |
| 36 | +# pipeline is run, NOT from the target branches specified here. If you need different |
| 37 | +# configurations for different branches, run the pipeline from each branch separately. |
| 38 | +- name: baseBranches |
| 39 | + type: object |
| 40 | + default: |
| 41 | + - main |
| 42 | + |
| 43 | +# When true, Renovate will run in dry run mode, which previews changes without creating PRs. |
| 44 | +# See the 'Run Renovate' step log output for details of what would have been changed. |
| 45 | +- name: dryRun |
| 46 | + type: boolean |
| 47 | + default: false |
| 48 | + |
| 49 | +# By default, Renovate will not recreate a PR for a given dependency/version pair that was |
| 50 | +# previously closed. This allows opting in to always recreating PRs even if they were |
| 51 | +# previously closed. |
| 52 | +- name: forceRecreatePR |
| 53 | + type: boolean |
| 54 | + default: false |
| 55 | + |
| 56 | +# Pool configuration for the job. |
| 57 | +- name: pool |
| 58 | + type: object |
| 59 | + default: |
| 60 | + name: NetCore1ESPool-Internal |
| 61 | + image: build.azurelinux.3.amd64 |
| 62 | + os: linux |
| 63 | + |
| 64 | +jobs: |
| 65 | +- job: Renovate |
| 66 | + displayName: Run Renovate |
| 67 | + container: RenovateContainer |
| 68 | + variables: |
| 69 | + - group: dotnet-renovate-bot |
| 70 | + # The Renovate version is automatically updated by https://github.com/dotnet/arcade/blob/main/azure-pipelines-renovate.yml. |
| 71 | + # Changing the variable name here would require updating the name in https://github.com/dotnet/arcade/blob/main/eng/renovate.json as well. |
| 72 | + - name: renovateVersion |
| 73 | + value: '42' |
| 74 | + - name: dryRunArg |
| 75 | + ${{ if eq(parameters.dryRun, true) }}: |
| 76 | + value: 'full' |
| 77 | + ${{ else }}: |
| 78 | + value: '' |
| 79 | + - name: recreateWhenArg |
| 80 | + ${{ if eq(parameters.forceRecreatePR, true) }}: |
| 81 | + value: 'always' |
| 82 | + ${{ else }}: |
| 83 | + value: '' |
| 84 | + pool: ${{ parameters.pool }} |
| 85 | + |
| 86 | + templateContext: |
| 87 | + outputParentDirectory: $(Build.ArtifactStagingDirectory) |
| 88 | + outputs: |
| 89 | + - output: pipelineArtifact |
| 90 | + displayName: Publish Renovate Log |
| 91 | + condition: succeededOrFailed() |
| 92 | + targetPath: $(Build.ArtifactStagingDirectory) |
| 93 | + artifactName: $(Agent.JobName)_Logs_Attempt$(System.JobAttempt) |
| 94 | + sbomEnabled: false |
| 95 | + |
| 96 | + steps: |
| 97 | + - checkout: self |
| 98 | + fetchDepth: 1 |
| 99 | + |
| 100 | + - script: renovate-config-validator $(Build.SourcesDirectory)/${{parameters.renovateConfigPath}} |
| 101 | + displayName: Validate Renovate config |
| 102 | + env: |
| 103 | + LOG_LEVEL: info |
| 104 | + LOG_FILE_LEVEL: debug |
| 105 | + LOG_FILE: $(Build.ArtifactStagingDirectory)/renovate-config-validator.json |
| 106 | + |
| 107 | + - script: | |
| 108 | + . $(Build.SourcesDirectory)/eng/common/renovate.env |
| 109 | + renovate |
| 110 | + displayName: Run Renovate |
| 111 | + env: |
| 112 | + RENOVATE_FORK_TOKEN: $(BotAccount-dotnet-renovate-bot-PAT) |
| 113 | + RENOVATE_TOKEN: $(BotAccount-dotnet-renovate-bot-PAT) |
| 114 | + RENOVATE_REPOSITORIES: ${{parameters.gitHubRepo}} |
| 115 | + RENOVATE_BASE_BRANCHES: ${{ convertToJson(parameters.baseBranches) }} |
| 116 | + RENOVATE_DRY_RUN: $(dryRunArg) |
| 117 | + RENOVATE_RECREATE_WHEN: $(recreateWhenArg) |
| 118 | + LOG_LEVEL: info |
| 119 | + LOG_FILE_LEVEL: debug |
| 120 | + LOG_FILE: $(Build.ArtifactStagingDirectory)/renovate.json |
| 121 | + RENOVATE_CONFIG_FILE: $(Build.SourcesDirectory)/${{parameters.renovateConfigPath}} |
| 122 | + |
| 123 | + - script: | |
| 124 | + echo "PRs created by Renovate:" |
| 125 | + if [ -s "$(Build.ArtifactStagingDirectory)/renovate-log.json" ]; then |
| 126 | + if ! jq -r 'select(.msg == "PR created" and .pr != null) | "https://github.com/\(.repository)/pull/\(.pr)"' "$(Build.ArtifactStagingDirectory)/renovate-log.json" | sort -u; then |
| 127 | + echo "##vso[task.logissue type=warning]Failed to parse Renovate log file with jq." |
| 128 | + echo "##vso[task.complete result=SucceededWithIssues]" |
| 129 | + fi |
| 130 | + else |
| 131 | + echo "##vso[task.logissue type=warning]No Renovate log file found or file is empty." |
| 132 | + echo "##vso[task.complete result=SucceededWithIssues]" |
| 133 | + fi |
| 134 | + displayName: List created PRs |
| 135 | + condition: and(succeededOrFailed(), eq('${{ parameters.dryRun }}', false)) |
0 commit comments