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

fix(datasource/custom): do not run digest update on version updates #29730

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions lib/workers/repository/process/lookup/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4004,6 +4004,37 @@ describe('workers/repository/process/lookup/index', () => {
]);
});

it("handles version update with new digest for single-entry custom datasource releases", async () => {
config.currentValue = "1.0.0";
config.packageName = "my-package";
config.datasource = "custom.package";
config.currentDigest = 'zzzzzzzzzzzzzzz';
getCustomDatasourceReleases.mockResolvedValueOnce({
releases: [
{
version: '1.0.1',
newDigest: '0123456789abcdef',
},
],
});
const { updates, warnings } = await Result.wrap(
lookup.lookupUpdates(config),
).unwrapOrThrow();
expect(updates).toEqual([
{
bucket: 'non-major',
newDigest: '0123456789abcdef',
newMajor: 1,
newMinor: 0,
newPatch: 1,
newValue: '1.0.1',
newVersion: '1.0.1',
updateType: 'patch',
},
]);
expect(warnings).toEqual([]);
});

it('handles digest update for non-version', async () => {
config.currentValue = 'alpine';
config.packageName = 'node';
Expand Down
10 changes: 9 additions & 1 deletion lib/workers/repository/process/lookup/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,15 @@ export async function lookupUpdates(
// Add digests if necessary
if (supportsDigests(config.datasource)) {
if (config.currentDigest) {
if (!config.digestOneAndOnly || !res.updates.length) {
let alwaysUpdateDigest = true;
if (config.digestOneAndOnly === true) {
alwaysUpdateDigest = false;
} else if (config.datasource.startsWith('custom.')) {
// Custom datasources should not run a digest update
// on the current version if it already runs a version update.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it "already ran a version update" then wouldn't res.updates.length be non-zero length anyway?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's correct, and !res.updates.length evaluates to false in this case. The problem in the original logic is config.digestOneAndOnly, which is true for gomod and undefined for other data sources.

So, for anything but gomod, the expression !config.digestOneAndOnly || !res.updates.length always evaluates to true no matter what res.updates.length is. So, renovate will try a "pure" digest update.

That pure digest update will look for the current version in the datasource. If the custom datasource only returns the latest version and that version is different from the current version, the digest update will fail and produce a warning.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then this isn't the right solution, because it should be possible to do digest only updates with regex manager. I do that heavily on jenkinsfiles for docker images

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My solution here still allows for digest-only updates. My example repo covers scenarios for digest-only updates. The unit tests pass as well, which contain digest-only updates.

The problem was that renovate will do a digest-only additionally to a version + digest update for the same dependency. Under the circumstances above, this will result in an incorrect warning that renovate cannot look up a digest.

alwaysUpdateDigest = false;
}
if (alwaysUpdateDigest || !res.updates.length) {
// digest update
res.updates.push({
updateType: 'digest',
Expand Down