Skip to content

feat(mix): implement getRangeStrategy #33322

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

Merged
merged 2 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions lib/modules/manager/mix/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { HexDatasource } from '../../datasource/hex';

export { extractPackageFile } from './extract';
export { updateArtifacts } from './artifacts';
export { getRangeStrategy } from './range';

export const url = 'https://hexdocs.pm/mix/Mix.html';
export const categories: Category[] = ['elixir'];
Expand Down
47 changes: 47 additions & 0 deletions lib/modules/manager/mix/range.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import type { RangeConfig } from '../types';
import { getRangeStrategy } from '.';

describe('modules/manager/mix/range', () => {
it('returns same if not auto', () => {
const config: RangeConfig = { rangeStrategy: 'pin' };
expect(getRangeStrategy(config)).toBe('pin');

config.rangeStrategy = 'widen';
expect(getRangeStrategy(config)).toBe('widen');
});

it('widens complex bump', () => {
const config: RangeConfig = {
rangeStrategy: 'bump',
depType: 'prod',
currentValue: '>= 1.6.0 and < 2.0.0',
};
expect(getRangeStrategy(config)).toBe('widen');
});

it('bumps non-complex bump', () => {
const config: RangeConfig = {
rangeStrategy: 'bump',
depType: 'prod',
currentValue: '~>1.0.0',
};
expect(getRangeStrategy(config)).toBe('bump');
});

it('widens complex auto', () => {
const config: RangeConfig = {
rangeStrategy: 'auto',
depType: 'prod',
currentValue: '<1.7.0 or ~>1.7.1',
};
expect(getRangeStrategy(config)).toBe('widen');
});

it('defaults to update-lockfile', () => {
const config: RangeConfig = {
rangeStrategy: 'auto',
depType: 'prod',
};
expect(getRangeStrategy(config)).toBe('update-lockfile');
});
});
26 changes: 26 additions & 0 deletions lib/modules/manager/mix/range.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { parseRange } from 'semver-utils';
import { logger } from '../../../logger';
import type { RangeStrategy } from '../../../types';
import type { RangeConfig } from '../types';

export function getRangeStrategy(config: RangeConfig): RangeStrategy {
const { currentValue, rangeStrategy } = config;
const isComplexRange = currentValue
? parseRange(currentValue).length > 1
: false;

if (rangeStrategy === 'bump' && isComplexRange) {
logger.debug(
{ currentValue },
'Replacing bump strategy for complex range with widen',
);
return 'widen';
}
if (rangeStrategy !== 'auto') {
return rangeStrategy;
}
if (isComplexRange) {
return 'widen';
}
return 'update-lockfile';
}
19 changes: 19 additions & 0 deletions lib/modules/manager/mix/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,22 @@ The following `depTypes` are currently supported by the `mix` manager :

- `prod`: all dependencies by default
- `dev`: dependencies with [`:only` option](https://hexdocs.pm/mix/Mix.Tasks.Deps.html#module-dependency-definition-options) not containing `:prod`

### Default `rangeStrategy=auto` behavior

Renovate's default [`rangeStrategy`](../../../configuration-options.md#rangestrategy) is `"auto"`.
Here's how `"auto"` works with the `mix` manager:

| Version type | New version | Old range | New range after update | What Renovate does |
| :----------------------- | :---------- | :-------------------- | :--------------------- | :------------------------------------------------------------------------ |
| Complex range | `1.7.2` | `< 1.7.0 or ~> 1.7.1` | `< 1.7.0 or ~> 1.7.2` | Widen range to include the new version. |
| Simple range | `0.39.0` | `<= 0.38.0` | `<= 0.39.0` | If update outside current range: widens range to include the new version. |
| Exact version constraint | `0.13.0` | `== 0.12.0` | `== 0.13.0` | Replace old version with new version. |

### Recommended `rangeStrategy` for apps and libraries

For applications, we recommend using `rangeStrategy=pin`.
This pins your dependencies to exact versions, which is generally considered [best practice for apps](../../../dependency-pinning.md).

For libraries, use `rangeStrategy=widen` with version ranges in your `mix.exs`.
This allows for greater compatibility with other projects that may use your library as a dependency.
Loading