diff --git a/lib/modules/manager/mix/__fixtures__/mix.exs b/lib/modules/manager/mix/__fixtures__/mix.exs index 08fae9e3caa99eeda2db9f6d93833adc56849058..fe1c24b7c78f875a4827aceea0d36e89029d1f6b 100644 --- a/lib/modules/manager/mix/__fixtures__/mix.exs +++ b/lib/modules/manager/mix/__fixtures__/mix.exs @@ -21,8 +21,11 @@ defmodule MyProject.MixProject do # {:broadway_dashboard, "~> 0.2.2"}, {:postgrex, "~> 0.8.1"}, # {:broadway_dashboard, "~> 0.2.2"}, {:ecto, ">2.1.0 or <=3.0.0"}, - {:cowboy, github: "ninenines/cowboy"}, + {:cowboy, github: "ninenines/cowboy", tag: "v0.4.1"}, + {:phoenix, git: "https://github.com/phoenixframework/phoenix.git", branch: "main"}, + {:ecto, github: "elixir-ecto/ecto", ref: "795036d997c7503b21fb64d6bf1a89b83c44f2b5"}, {:secret, "~> 1.0", organization: "acme"}, + {:also_secret, "~> 1.0", only: [:dev, :test], organization: "acme", runtime: false}, {:ex_doc, ">2.1.0 and <=3.0.0"}, {:jason, ">= 1.0.0"}, {:jason, "~> 1.0", diff --git a/lib/modules/manager/mix/__snapshots__/extract.spec.ts.snap b/lib/modules/manager/mix/__snapshots__/extract.spec.ts.snap deleted file mode 100644 index c2682c143de91d7879e2ef117f98997b5a6b36f0..0000000000000000000000000000000000000000 --- a/lib/modules/manager/mix/__snapshots__/extract.spec.ts.snap +++ /dev/null @@ -1,50 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`modules/manager/mix/extract extractPackageFile() extracts all dependencies 1`] = ` -{ - "deps": [ - { - "currentValue": "~> 0.8.1", - "datasource": "hex", - "depName": "postgrex", - "packageName": "postgrex", - }, - { - "currentValue": ">2.1.0 or <=3.0.0", - "datasource": "hex", - "depName": "ecto", - "packageName": "ecto", - }, - { - "currentValue": "ninenines/cowboy", - "datasource": "github", - "depName": "cowboy", - "skipReason": "non-hex-dep-types", - }, - { - "currentValue": "~> 1.0", - "datasource": "hex", - "depName": "secret", - "packageName": "secret:acme", - }, - { - "currentValue": ">2.1.0 and <=3.0.0", - "datasource": "hex", - "depName": "ex_doc", - "packageName": "ex_doc", - }, - { - "currentValue": ">= 1.0.0", - "datasource": "hex", - "depName": "jason", - "packageName": "jason", - }, - { - "currentValue": "~> 1.0", - "datasource": "hex", - "depName": "jason", - "packageName": "jason", - }, - ], -} -`; diff --git a/lib/modules/manager/mix/extract.spec.ts b/lib/modules/manager/mix/extract.spec.ts index 530b2267aa358af0d56a1c724fdf1bebe3b009af..3ccc432018680a9c58eef0f58dc2131046b87501 100644 --- a/lib/modules/manager/mix/extract.spec.ts +++ b/lib/modules/manager/mix/extract.spec.ts @@ -15,27 +15,71 @@ describe('modules/manager/mix/extract', () => { it('extracts all dependencies', async () => { const res = await extractPackageFile(Fixtures.get('mix.exs'), 'mix.exs'); - expect(res).toMatchSnapshot({ - deps: [ - { depName: 'postgrex', currentValue: '~> 0.8.1' }, - { depName: 'ecto', currentValue: '>2.1.0 or <=3.0.0' }, - { - depName: 'cowboy', - currentValue: 'ninenines/cowboy', - datasource: 'github', - skipReason: 'non-hex-dep-types', - }, - { - depName: 'secret', - currentValue: '~> 1.0', - datasource: 'hex', - packageName: 'secret:acme', - }, - { depName: 'ex_doc', currentValue: '>2.1.0 and <=3.0.0' }, - { depName: 'jason', currentValue: '>= 1.0.0' }, - { depName: 'jason', currentValue: '~> 1.0' }, - ], - }); + expect(res?.deps).toEqual([ + { + currentValue: '~> 0.8.1', + datasource: 'hex', + depName: 'postgrex', + packageName: 'postgrex', + }, + { + currentValue: '>2.1.0 or <=3.0.0', + datasource: 'hex', + depName: 'ecto', + packageName: 'ecto', + }, + { + currentDigest: undefined, + currentValue: 'v0.4.1', + datasource: 'github-tags', + depName: 'cowboy', + packageName: 'ninenines/cowboy', + }, + { + currentDigest: undefined, + currentValue: 'main', + datasource: 'git-tags', + depName: 'phoenix', + packageName: 'https://github.com/phoenixframework/phoenix.git', + }, + { + currentDigest: '795036d997c7503b21fb64d6bf1a89b83c44f2b5', + currentValue: undefined, + datasource: 'github-tags', + depName: 'ecto', + packageName: 'elixir-ecto/ecto', + }, + { + currentValue: '~> 1.0', + datasource: 'hex', + depName: 'secret', + packageName: 'secret:acme', + }, + { + currentValue: '~> 1.0', + datasource: 'hex', + depName: 'also_secret', + packageName: 'also_secret:acme', + }, + { + currentValue: '>2.1.0 and <=3.0.0', + datasource: 'hex', + depName: 'ex_doc', + packageName: 'ex_doc', + }, + { + currentValue: '>= 1.0.0', + datasource: 'hex', + depName: 'jason', + packageName: 'jason', + }, + { + currentValue: '~> 1.0', + datasource: 'hex', + depName: 'jason', + packageName: 'jason', + }, + ]); }); }); }); diff --git a/lib/modules/manager/mix/extract.ts b/lib/modules/manager/mix/extract.ts index 4867af63156594fb8ce7cc1c61bb3afbb14fd631..54bd5e5717ec7273a0cc7e6d13bfea89e34ef9a0 100644 --- a/lib/modules/manager/mix/extract.ts +++ b/lib/modules/manager/mix/extract.ts @@ -1,13 +1,20 @@ import { logger } from '../../../logger'; import { findLocalSiblingOrParent, localPathExists } from '../../../util/fs'; import { newlineRegex, regEx } from '../../../util/regex'; +import { GitTagsDatasource } from '../../datasource/git-tags'; +import { GithubTagsDatasource } from '../../datasource/github-tags'; import { HexDatasource } from '../../datasource/hex'; import type { PackageDependency, PackageFile } from '../types'; const depSectionRegExp = regEx(/defp\s+deps.*do/g); const depMatchRegExp = regEx( - /{:(?<depName>\w+),\s*(?<datasource>[^:"]+)?:?\s*"(?<currentValue>[^"]+)",?\s*(?:organization: "(?<organization>.*)")?.*}/gm + /{:(?<app>\w+)(\s*,\s*"(?<requirement>[^"]+)")?(\s*,\s*(?<opts>[^}]+))?}/gm ); +const gitRegexp = regEx(/git:\s*"(?<value>[^"]+)"/); +const githubRegexp = regEx(/github:\s*"(?<value>[^"]+)"/); +const refRegexp = regEx(/ref:\s*"(?<value>[^"]+)"/); +const branchOrTagRegexp = regEx(/(?:branch|tag):\s*"(?<value>[^"]+)"/); +const organizationRegexp = regEx(/organization:\s*"(?<value>[^"]+)"/); const commentMatchRegExp = regEx(/#.*$/); export async function extractPackageFile( @@ -28,27 +35,30 @@ export async function extractPackageFile( } while (!contentArr[lineNumber].includes('end')); let depMatchGroups = depMatchRegExp.exec(depBuffer)?.groups; while (depMatchGroups) { - const { depName, datasource, currentValue, organization } = - depMatchGroups; + const { app, requirement, opts } = depMatchGroups; + const github = githubRegexp.exec(opts)?.groups?.value; + const git = gitRegexp.exec(opts)?.groups?.value; + const ref = refRegexp.exec(opts)?.groups?.value; + const branchOrTag = branchOrTagRegexp.exec(opts)?.groups?.value; + const organization = organizationRegexp.exec(opts)?.groups?.value; - const dep: PackageDependency = { - depName, - currentValue, - }; + let dep: PackageDependency; - dep.datasource = datasource || HexDatasource.id; - - if (dep.datasource === HexDatasource.id) { - dep.currentValue = currentValue; - dep.packageName = depName; - } - - if (organization) { - dep.packageName += ':' + organization; - } - - if (dep.datasource !== HexDatasource.id) { - dep.skipReason = 'non-hex-dep-types'; + if (git ?? github) { + dep = { + depName: app, + currentDigest: ref, + currentValue: branchOrTag, + datasource: git ? GitTagsDatasource.id : GithubTagsDatasource.id, + packageName: git ?? github, + }; + } else { + dep = { + depName: app, + currentValue: requirement, + datasource: HexDatasource.id, + packageName: organization ? `${app}:${organization}` : app, + }; } deps.push(dep); diff --git a/lib/modules/manager/mix/index.ts b/lib/modules/manager/mix/index.ts index 7820dcded9a9512845c32af09885f93ad20f26c3..f48c01ae2529d13297d23c1636b5f989edbd9d51 100644 --- a/lib/modules/manager/mix/index.ts +++ b/lib/modules/manager/mix/index.ts @@ -1,4 +1,6 @@ import type { ProgrammingLanguage } from '../../../constants'; +import { GitTagsDatasource } from '../../datasource/git-tags'; +import { GithubTagsDatasource } from '../../datasource/github-tags'; import { HexDatasource } from '../../datasource/hex'; import * as hexVersioning from '../../versioning/hex'; @@ -12,4 +14,8 @@ export const defaultConfig = { versioning: hexVersioning.id, }; -export const supportedDatasources = [HexDatasource.id]; +export const supportedDatasources = [ + GithubTagsDatasource.id, + GitTagsDatasource.id, + HexDatasource.id, +];