Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
813 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import upath from 'upath'; | ||
import fs from 'fs-extra'; | ||
import { hrtime } from 'process'; | ||
import { platform } from '../../platform'; | ||
import { exec } from '../../util/exec'; | ||
import { logger } from '../../logger'; | ||
import { UpdateArtifactsConfig, UpdateArtifactsResult } from '../common'; | ||
|
||
export async function updateArtifacts( | ||
packageFileName: string, | ||
updatedDeps: string[], | ||
newPackageFileContent: string, | ||
config: UpdateArtifactsConfig | ||
): Promise<UpdateArtifactsResult[] | null> { | ||
await logger.debug(`mix.getArtifacts(${packageFileName})`); | ||
if (updatedDeps.length < 1) { | ||
logger.debug('No updated mix deps - returning null'); | ||
return null; | ||
} | ||
|
||
const cwd = config.localDir; | ||
if (!cwd) { | ||
logger.debug('No local dir specified'); | ||
return null; | ||
} | ||
|
||
const lockFileName = 'mix.lock'; | ||
try { | ||
const localPackageFileName = upath.join(cwd, packageFileName); | ||
await fs.outputFile(localPackageFileName, newPackageFileContent); | ||
} catch (err) { | ||
logger.warn({ err }, 'mix.exs could not be written'); | ||
return [ | ||
{ | ||
lockFileError: { | ||
lockFile: lockFileName, | ||
stderr: err.message, | ||
}, | ||
}, | ||
]; | ||
} | ||
|
||
const existingLockFileContent = await platform.getFile(lockFileName); | ||
if (!existingLockFileContent) { | ||
logger.debug('No mix.lock found'); | ||
return null; | ||
} | ||
|
||
const cmdParts = | ||
config.binarySource === 'docker' | ||
? [ | ||
'docker', | ||
'run', | ||
'--rm', | ||
`-v ${cwd}:${cwd}`, | ||
`-w ${cwd}`, | ||
'renovate/mix mix', | ||
] | ||
: ['mix']; | ||
cmdParts.push('deps.update'); | ||
|
||
const startTime = hrtime(); | ||
/* istanbul ignore next */ | ||
try { | ||
const command = [...cmdParts, ...updatedDeps].join(' '); | ||
const { stdout, stderr } = await exec(command, { cwd }); | ||
logger.debug(stdout); | ||
if (stderr) logger.warn('error: ' + stderr); | ||
} catch (err) { | ||
logger.warn( | ||
{ err, message: err.message }, | ||
'Failed to update Mix lock file' | ||
); | ||
|
||
return [ | ||
{ | ||
lockFileError: { | ||
lockFile: lockFileName, | ||
stderr: err.message, | ||
}, | ||
}, | ||
]; | ||
} | ||
|
||
const duration = hrtime(startTime); | ||
const seconds = Math.round(duration[0] + duration[1] / 1e9); | ||
logger.info({ seconds, type: 'mix.lock' }, 'Updated lockfile'); | ||
logger.debug('Returning updated mix.lock'); | ||
|
||
const localLockFileName = upath.join(cwd, lockFileName); | ||
const newMixLockContent = await fs.readFile(localLockFileName, 'utf8'); | ||
if (existingLockFileContent === newMixLockContent) { | ||
logger.debug('mix.lock is unchanged'); | ||
return null; | ||
} | ||
|
||
return [ | ||
{ | ||
file: { | ||
name: lockFileName, | ||
contents: newMixLockContent, | ||
}, | ||
}, | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { isValid } from '../../versioning/hex'; | ||
import { logger } from '../../logger'; | ||
import { PackageDependency, PackageFile } from '../common'; | ||
|
||
const depSectionRegExp = /defp\s+deps.*do/g; | ||
const depMatchRegExp = /{:(\w+),\s*([^:"]+)?:?\s*"([^"]+)",?\s*(organization: "(.*)")?.*}/gm; | ||
|
||
export function extractPackageFile(content: string): PackageFile { | ||
logger.trace('mix.extractPackageFile()'); | ||
const deps: PackageDependency[] = []; | ||
const contentArr = content.split('\n'); | ||
|
||
for (let lineNumber = 0; lineNumber < contentArr.length; lineNumber += 1) { | ||
if (contentArr[lineNumber].match(depSectionRegExp)) { | ||
logger.trace(`Matched dep section on line ${lineNumber}`); | ||
let depBuffer = ''; | ||
do { | ||
depBuffer += contentArr[lineNumber] + '\n'; | ||
lineNumber += 1; | ||
} while (!contentArr[lineNumber].includes('end')); | ||
let depMatch: RegExpMatchArray; | ||
do { | ||
depMatch = depMatchRegExp.exec(depBuffer); | ||
if (depMatch) { | ||
const depName = depMatch[1]; | ||
const datasource = depMatch[2]; | ||
const currentValue = depMatch[3]; | ||
const organization = depMatch[5]; | ||
|
||
const dep: PackageDependency = { | ||
depName, | ||
currentValue, | ||
managerData: {}, | ||
}; | ||
|
||
dep.datasource = datasource || 'hex'; | ||
|
||
if (dep.datasource === 'hex') { | ||
dep.currentValue = currentValue; | ||
dep.lookupName = depName; | ||
} | ||
|
||
if (organization) { | ||
dep.lookupName += ':' + organization; | ||
} | ||
|
||
if (!isValid(currentValue)) { | ||
dep.skipReason = 'unsupported-version'; | ||
} | ||
|
||
if (dep.datasource !== 'hex') { | ||
dep.skipReason = 'non-hex depTypes'; | ||
} | ||
|
||
// Find dep's line number | ||
for (let i = 0; i < contentArr.length; i += 1) | ||
if (contentArr[i].includes(`:${depName},`)) | ||
dep.managerData.lineNumber = i; | ||
|
||
deps.push(dep); | ||
} | ||
} while (depMatch); | ||
} | ||
} | ||
return { deps }; | ||
} |
Oops, something went wrong.