Skip to content

Commit

Permalink
fix(gomod): default to not massaging replace statements (#15767)
Browse files Browse the repository at this point in the history
  • Loading branch information
rarkins committed May 28, 2022
1 parent 99c4d1b commit 4b0102f
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 7 deletions.
2 changes: 1 addition & 1 deletion docs/usage/configuration-options.md
Expand Up @@ -1881,7 +1881,7 @@ This way Renovate can use GitHub's [Commit signing support for bots and other Gi

## postUpdateOptions

- `gomodNoMassage`: Skip massaging `replace` directives before calling `go` commands
- `gomodMassage`: Enable massaging `replace` directives before calling `go` commands
- `gomodTidy`: Run `go mod tidy` after Go module updates. This is implicitly enabled for major module updates when `gomodUpdateImportPaths` is enabled
- `gomodTidy1.17`: Run `go mod tidy -compat=1.17` after Go module updates.
- `gomodUpdateImportPaths`: Update source import paths on major module updates, using [mod](https://github.com/marwan-at-work/mod)
Expand Down
7 changes: 4 additions & 3 deletions docs/usage/golang.md
Expand Up @@ -30,12 +30,13 @@ To install Renovate Bot itself, either enable the [Renovate App](https://github.

### Replace massaging

Renovate's default behavior is to massage any `replace` statements it finds prior to running `go` commands, and then massage them back afterwards.
This was originally done because relative `replace` statements outside of the current repo will not work when Renovate clones the repo locally.
Renovate can massage `replace` statements it finds prior to running `go` commands, and then massage them back afterwards.
This capability was added - and originally default behavior - because relative `replace` statements outside of the current repo will not work when Renovate clones the repo locally.

On the other hand, this massaging of `replace` statements may lead to unexpected results, especially because `go mod tidy` may not fully tidy the `go.sum` if it is missing the `replace` directives in `go.mod`.
It has therefore been disabled by default.

To disable this default behavior, and retain all `replace` statements when running `go` commands, add `gomodNoMassage` to your `postUpdateOptions` array.
To enable this replace massaging behavior, add `gomodMassage` to your `postUpdateOptions` array.

### Module Tidying

Expand Down
14 changes: 14 additions & 0 deletions lib/config/migrations/custom/post-update-options-migration.spec.ts
@@ -0,0 +1,14 @@
import { PostUpdateOptionsMigration } from './post-update-options-migration';

describe('config/migrations/custom/post-update-options-migration', () => {
it('should migrate properly', () => {
expect(PostUpdateOptionsMigration).toMigrate(
{
postUpdateOptions: ['gomodTidy', 'gomodNoMassage'],
},
{
postUpdateOptions: ['gomodTidy'],
}
);
});
});
16 changes: 16 additions & 0 deletions lib/config/migrations/custom/post-update-options-migration.ts
@@ -0,0 +1,16 @@
import is from '@sindresorhus/is';
import { AbstractMigration } from '../base/abstract-migration';

export class PostUpdateOptionsMigration extends AbstractMigration {
override readonly propertyName = 'postUpdateOptions';

override run(value: unknown): void {
if (Array.isArray(value)) {
const newValue = value
.filter(is.nonEmptyString)
.filter((option) => option !== 'gomodNoMassage');

this.rewrite(newValue);
}
}
}
2 changes: 2 additions & 0 deletions lib/config/migrations/migrations-service.ts
Expand Up @@ -28,6 +28,7 @@ import { PackagePatternMigration } from './custom/package-pattern-migration';
import { PackagesMigration } from './custom/packages-migration';
import { PathRulesMigration } from './custom/path-rules-migration';
import { PinVersionsMigration } from './custom/pin-versions-migration';
import { PostUpdateOptionsMigration } from './custom/post-update-options-migration';
import { RaiseDeprecationWarningsMigration } from './custom/raise-deprecation-warnings-migration';
import { RebaseConflictedPrs } from './custom/rebase-conflicted-prs-migration';
import { RebaseStalePrsMigration } from './custom/rebase-stale-prs-migration';
Expand Down Expand Up @@ -100,6 +101,7 @@ export class MigrationsService {
PackagesMigration,
PathRulesMigration,
PinVersionsMigration,
PostUpdateOptionsMigration,
RaiseDeprecationWarningsMigration,
RebaseConflictedPrs,
RebaseStalePrsMigration,
Expand Down
2 changes: 1 addition & 1 deletion lib/config/options/index.ts
Expand Up @@ -1820,7 +1820,7 @@ const options: RenovateOptions[] = [
type: 'array',
default: [],
allowedValues: [
'gomodNoMassage',
'gomodMassage',
'gomodUpdateImportPaths',
'gomodTidy',
'gomodTidy1.17',
Expand Down
1 change: 1 addition & 0 deletions lib/modules/manager/gomod/artifacts.spec.ts
Expand Up @@ -42,6 +42,7 @@ const adminConfig: RepoGlobalConfig = {

const config: UpdateArtifactsConfig = {
constraints: { go: '1.14' },
postUpdateOptions: ['gomodMassage'],
};

const goEnv = {
Expand Down
2 changes: 1 addition & 1 deletion lib/modules/manager/gomod/artifacts.ts
Expand Up @@ -160,7 +160,7 @@ export async function updateArtifacts({

let massagedGoMod = newGoModContent;

if (!config.postUpdateOptions?.includes('gomodNoMassage')) {
if (config.postUpdateOptions?.includes('gomodMassage')) {
// 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
Expand Down
2 changes: 1 addition & 1 deletion lib/modules/manager/gomod/readme.md
Expand Up @@ -4,7 +4,7 @@ You might be interested in the following `postUpdateOptions`:
1. This is implicitly enabled for major updates if the user has enabled the option `gomodUpdateImportPaths`
1. `gomodTidy1.17` - if you'd like Renovate to run `go mod tidy -compat=1.17` after every update before raising the PR.
1. `gomodUpdateImportPaths` - if you'd like Renovate to update your source import paths on major updates before raising the PR.
1. `gomodNoMassage` - to skip massaging of `replace` statements.
1. `gomodMassage` - to enable massaging of all `replace` statements prior to running `go` so that they will be ignored.

When Renovate is running using `binarySource=docker` (such as in the hosted Mend Renovate app) then it will pick the latest compatible version of Go to run, i.e. the latest `1.x` release.
Therefore even if the `go.mod` has a version like `go 1.14`, you will see Renovate treating that as a `^1.14` constraint and not `=1.14`.

0 comments on commit 4b0102f

Please sign in to comment.