Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure Renovate to suggest AGP version bumps #1742

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

gabrielfeo
Copy link
Member

@gabrielfeo gabrielfeo commented Jan 3, 2025

Automate the discovery of new AGP versions. While there's an existing workflow for bumping the AGP versions in this project, it must be manually triggered specifying the new version. Renovate can fill this gap by suggesting updates whenever new versions come out.

Renovate

Renovate is a tool like Dependabot but much more flexible. It has built-in "managers" such as maven, gradle, and pip_requirements that look for certain patterns in certain files, then query "datasources" for newer versions. No built-in manager supports the custom versions.json file, but Renovate allows for creating a custom regex-based manager.

Renovate custom manager

A Renovate config file is added with a custom "regex" manager. This can instruct Renovate to parse any version on any file. The goal is to detect and update AGP versions annotated with a comment:

# renovate: AGP version
8.6.0

The "manager" config declares

  • what files it should process
  • what it should consider a version definition within those files
  • what "datasource" it should query for newer versions
  • what "versioning" (scheme) the versions adhere to
  • the dependency name
  • the Maven registry URL the dependency comes from
{
  // Matches AGP versions annotated with a "renovate: AGP version" comment
  customType: "regex",
  fileMatch: [
    "src/main/resources/versions\\.json5",
    "gradle\\.properties",
  ],
  matchStrings: [
    // For JSON: the first double-quoted string below the comment line, e.g. "1.0.0"
    "\/\/ renovate: AGP version\\s+?\"(?<currentValue>\\S+?)\"",
    // For properties: the value of the first property below the comment line, e.g. anyProperty=1.0.0
    "# renovate: AGP version\\s+?\\S+?=(?<currentValue>\\S+?)(?:\\s|$)",
  ],
  "datasourceTemplate": "maven",
  "versioningTemplate": "maven",
  "depNameTemplate": "com.android.tools.build:gradle",
  "registryUrlTemplate": "https://dl.google.com/dl/android/maven2/",
},

An example PR is available in a fork: gabrielfeo#10.

image

The last four elements are commonly set on each comment and captured with regex (example), but I opted to centralize them in the Renovate config to minimize duplication, simplify the comments and the regex that parses them.

Changes

  • Annotate AGP versions in versions.json with a "renovate: AGP version" comment
    • Rename the file to versions.json5 to keep syntax highlighting support when adding comments
    • Change all JsonSlurpers to LAX mode, which is lenient about comments (Groovy has no support for JSON5)
  • Add a Renovate config to bump versions in versions.json5 and gradle.properties too (for the build-time check described below)
  • Change plugin tests to no longer require changes on every patch version. "expectedOutcomes" JSON files are now minor-specific and WorkaroundTest no longer specifies patch numbers. Updating these is something that the existing workflow takes care of, but can't be as easily done with Renovate. Thanks to @erichaagdev for this suggestion.
  • Declare the latest AGP version in gradle.properties and fail the build if it's missing from versions.json5. The goal is to have Renovate create a "nudge" PR if a new major or minor comes out (versions.json5 has major/minor bumps disabled in order to keep older minor versions in the list of "supportedVersions"). The property isn't used for anything else. Thanks to @erichaagdev for this suggestion.

Pending work

  • Find how to keep Renovate updating older versions, e.g. 8.6.0 to 8.6.1 despite 8.7.1 being out (worked out in commit gabrielfeo@f92e638)
  • Revert the downgrade commits that were added for testing from the PR branch
  • Find out if Renovate is enabled for all repos in the org (or ask for it to be enabled in this repo)

(cherry picked from commit 86474cd14f8ea7a4eef7d7705bc8b15f0cb9dd2d)
(cherry picked from commit 994168bcd78831577933c111b9cc1c1dee5cba3b)
@gabrielfeo gabrielfeo force-pushed the gf/agp-pre-release-bump-prs branch 2 times, most recently from e7a9b26 to 2e4ec1c Compare January 6, 2025 12:39
(cherry picked from commit d82c4d7103211d524d4cb4ff8dbb6311ee354ab1)
@gabrielfeo gabrielfeo force-pushed the gf/agp-pre-release-bump-prs branch from 22061a8 to c2cef72 Compare January 6, 2025 14:15
Allow unlimited PRs

Group changes to versions.json5

Improve renovate.json5 comments
@gabrielfeo gabrielfeo force-pushed the gf/agp-pre-release-bump-prs branch from c2cef72 to 36964bf Compare January 6, 2025 14:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant