Skip to content

Commit

Permalink
feat(autoreplace): extended logging for autoreplace mismatches (#33984)
Browse files Browse the repository at this point in the history
Co-authored-by: Michael Kriese <[email protected]>
  • Loading branch information
rarkins and viceice authored Feb 1, 2025
1 parent c25ffa5 commit a1c291c
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 4 deletions.
38 changes: 38 additions & 0 deletions lib/workers/repository/update/branch/auto-replace.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
`,
);
});
});
});
38 changes: 34 additions & 4 deletions lib/workers/repository/update/branch/auto-replace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,10 @@ export async function doAutoReplace(
const {
packageFile,
depName,
depNameTemplate,
newName,
currentValue,
currentValueTemplate,
newValue,
currentDigest,
currentDigestShort,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions lib/workers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ export interface BranchUpgradeConfig
currentDigest?: string;
currentDigestShort?: string;
currentValue?: string;

currentValueTemplate?: string;
depIndex?: number;
depTypes?: string[];

Expand Down

0 comments on commit a1c291c

Please sign in to comment.