diff --git a/lib/modules/manager/gomod/artifacts.spec.ts b/lib/modules/manager/gomod/artifacts.spec.ts index 22dda91fcb7c7d82f308cfc5f840a66b2cb4f610..cae9a08625d78d30f99489e0f37f5807b766dbce 100644 --- a/lib/modules/manager/gomod/artifacts.spec.ts +++ b/lib/modules/manager/gomod/artifacts.spec.ts @@ -27,11 +27,17 @@ require github.com/davecgh/go-spew v1.0.0 require golang.org/x/foo v1.0.0 require github.com/rarkins/foo abcdef1 require gopkg.in/russross/blackfriday.v1 v1.0.0 +require go.uber.org/zap v1.20.0 replace github.com/pkg/errors => ../errors replace (golang.org/x/foo => github.com/pravesht/gocql v0.0.0) +replace ( + // TODO: this comment breaks renovatebot (>v0.11.1) + go.uber.org/zap => go.uber.org/zap v1.21.0 +) + `; const adminConfig: RepoGlobalConfig = { diff --git a/lib/modules/manager/gomod/artifacts.ts b/lib/modules/manager/gomod/artifacts.ts index cc8bee8437dd671fcac42295dbe628a4dc58a9e6..f75349ef612430ddae7c4486340c4dc20eab19a0 100644 --- a/lib/modules/manager/gomod/artifacts.ts +++ b/lib/modules/manager/gomod/artifacts.ts @@ -164,6 +164,19 @@ export async function updateArtifacts({ // Regex match inline replace directive, example: // replace golang.org/x/net v1.2.3 => example.com/fork/net v1.4.5 // https://go.dev/ref/mod#go-mod-file-replace + + // replace bracket after comments, so it doesn't break the regex, doing a complex regex causes problems + // when there's a comment and ")" after it, the regex will read replace block until comment.. and stop. + massagedGoMod = massagedGoMod + .split('\n') + .map((line) => { + if (line.trim().startsWith('//')) { + return line.replace(')', 'renovate-replace-bracket'); + } + return line; + }) + .join('\n'); + const inlineReplaceRegEx = regEx( /(\r?\n)(replace\s+[^\s]+\s+=>\s+\.\.\/.*)/g ); @@ -188,12 +201,14 @@ export async function updateArtifacts({ match.replace(/(\r?\n)/g, '$1// renovate-replace '); // Comment out golang replace directives - massagedGoMod = newGoModContent + massagedGoMod = massagedGoMod .replace(inlineReplaceRegEx, inlineCommentOut) .replace(blockReplaceRegEx, blockCommentOut); if (massagedGoMod !== newGoModContent) { - logger.debug('Removed some relative replace statements from go.mod'); + logger.debug( + 'Removed some relative replace statements and comments from go.mod' + ); } } try { @@ -336,9 +351,9 @@ export async function updateArtifacts({ } } - const finalGoModContent = ( - await readLocalFile(goModFileName, 'utf8') - ).replace(regEx(/\/\/ renovate-replace /g), ''); + const finalGoModContent = (await readLocalFile(goModFileName, 'utf8')) + .replace(regEx(/\/\/ renovate-replace /g), '') + .replace(regEx(/renovate-replace-bracket/g), ')'); if (finalGoModContent !== newGoModContent) { logger.debug('Found updated go.mod after go.sum update'); res.push({