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

feat(autoreplace): extended logging for autoreplace mismatches #33984

Merged
merged 3 commits into from
Feb 1, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
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 @@ -5,7 +5,7 @@
import { WORKER_FILE_UPDATE_FAILED } from '../../../../constants/error-messages';
import { extractPackageFile } from '../../../../modules/manager/html';
import type { BranchUpgradeConfig } from '../../../types';
import { doAutoReplace } from './auto-replace';

Check failure on line 8 in lib/workers/repository/update/branch/auto-replace.spec.ts

View workflow job for this annotation

GitHub Actions / lint-eslint

Parse errors in imported module './auto-replace': ')' expected. (267:47)

const sampleHtml = Fixtures.get(
'sample.html',
Expand Down Expand Up @@ -1374,5 +1374,43 @@
`,
);
});

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 @@
const {
packageFile,
depName,
depNameTemplate,
newName,
currentValue,
currentValueTemplate,
newValue,
currentDigest,
currentDigestShort,
Expand Down Expand Up @@ -237,24 +239,52 @@
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) {

Check failure on line 267 in lib/workers/repository/update/branch/auto-replace.ts

View workflow job for this annotation

GitHub Actions / lint-eslint

Parsing error: ')' expected.

Check failure on line 267 in lib/workers/repository/update/branch/auto-replace.ts

View workflow job for this annotation

GitHub Actions / lint-other

')' expected.

Check failure on line 267 in lib/workers/repository/update/branch/auto-replace.ts

View workflow job for this annotation

GitHub Actions / build

')' expected.
viceice marked this conversation as resolved.
Show resolved Hide resolved
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
Loading