diff --git a/lib/workers/repository/update/branch/auto-replace.spec.ts b/lib/workers/repository/update/branch/auto-replace.spec.ts index fb06f7bc23bc89..03ada2c1e2423a 100644 --- a/lib/workers/repository/update/branch/auto-replace.spec.ts +++ b/lib/workers/repository/update/branch/auto-replace.spec.ts @@ -1374,5 +1374,43 @@ describe('workers/repository/update/branch/auto-replace', () => { `, ); }); + + it('github-actions: failes to update currentDigestShort', async () => { + const githubAction = codeBlock` + jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@2485f4 # tag=v1.0.0 + `; + upgrade.manager = 'github-actions'; + upgrade.updateType = 'replacement'; + upgrade.pinDigests = true; + upgrade.autoReplaceStringTemplate = + '{{depName}}@{{#if newDigest}}{{newDigest}}{{#if newValue}} # {{newValue}}{{/if}}{{/if}}{{#unless newDigest}}{{newValue}}{{/unless}}'; + upgrade.depName = 'actions/checkout'; + upgrade.currentValue = 'v1.0.0'; + upgrade.currentDigestShort = 'wrong'; + upgrade.depIndex = 0; + upgrade.replaceString = 'actions/checkout@2485f4 # tag=v1.0.0'; + upgrade.newName = 'some-other-action/checkout'; + upgrade.newValue = 'v2.0.0'; + upgrade.newDigest = '1cf887'; + upgrade.packageFile = 'workflow.yml'; + const res = await doAutoReplace( + upgrade, + githubAction, + reuseExistingBranch, + ); + expect(res).toBe( + codeBlock` + jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: some-other-action/checkout@2485f4 # tag=v2.0.0 + `, + ); + }); }); }); diff --git a/lib/workers/repository/update/branch/auto-replace.ts b/lib/workers/repository/update/branch/auto-replace.ts index d89862e5daf72c..39bd5204644be5 100644 --- a/lib/workers/repository/update/branch/auto-replace.ts +++ b/lib/workers/repository/update/branch/auto-replace.ts @@ -190,8 +190,10 @@ export async function doAutoReplace( const { packageFile, depName, + depNameTemplate, newName, currentValue, + currentValueTemplate, newValue, currentDigest, currentDigestShort, @@ -237,24 +239,52 @@ export async function doAutoReplace( newString = replaceString!; const autoReplaceRegExpFlag = autoReplaceGlobalMatch ? 'g' : ''; - if (currentValue && newValue) { + if (currentValue && newValue && currentValue !== newValue) { + if (!newString.includes(currentValue)) { + logger.debug( + { stringToReplace: newString, currentValue, currentValueTemplate }, + 'currentValue not found in string to replace', + ); + } newString = newString.replace( regEx(escapeRegExp(currentValue), autoReplaceRegExpFlag), newValue, ); } - if (depName && newName) { + if (depName && newName && depName !== newName) { + if (!newString.includes(depName)) { + logger.debug( + { stringToReplace: newString, depName, depNameTemplate }, + 'depName not found in string to replace', + ); + } newString = newString.replace( regEx(escapeRegExp(depName), autoReplaceRegExpFlag), newName, ); } - if (currentDigest && newDigest) { + if (currentDigest && newDigest && currentDigest !== newDigest) { + if (!newString.includes(currentDigest)) { + logger.debug( + { stringToReplace: newString, currentDigest }, + 'currentDigest not found in string to replace', + ); + } newString = newString.replace( regEx(escapeRegExp(currentDigest), autoReplaceRegExpFlag), newDigest, ); - } else if (currentDigestShort && newDigest) { + } else if ( + currentDigestShort && + newDigest && + currentDigestShort !== newDigest + ) { + if (!newString.includes(currentDigestShort)) { + logger.debug( + { stringToReplace: newString, currentDigestShort }, + 'currentDigestShort not found in string to replace', + ); + } newString = newString.replace( regEx(escapeRegExp(currentDigestShort), autoReplaceRegExpFlag), newDigest, diff --git a/lib/workers/types.ts b/lib/workers/types.ts index 3b5727320bbe08..54f0df74db6965 100644 --- a/lib/workers/types.ts +++ b/lib/workers/types.ts @@ -42,6 +42,8 @@ export interface BranchUpgradeConfig currentDigest?: string; currentDigestShort?: string; currentValue?: string; + + currentValueTemplate?: string; depIndex?: number; depTypes?: string[];