forked from renovatebot/renovate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(bitbucket-pipelines): support bitbucket pipe renovations (renova…
- Loading branch information
1 parent
27812e9
commit 2d2a599
Showing
6 changed files
with
142 additions
and
0 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
24 changes: 24 additions & 0 deletions
24
lib/manager/bitbucket-pipelines/__fixtures__/bitbucket-pipelines.yaml
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,24 @@ | ||
image: node:10.15.1 | ||
|
||
pipelines: | ||
default: | ||
- step: | ||
name: Build and Test | ||
image: node:10.15.2 | ||
script: | ||
- npm install | ||
- npm test | ||
- npm run dist | ||
artifacts: | ||
- dist/** | ||
- step: | ||
name: Deploy | ||
deployment: production | ||
script: | ||
- pipe: atlassian/aws-s3-deploy:0.2.1 | ||
variables: | ||
AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID | ||
AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY | ||
AWS_DEFAULT_REGION: "us-east-1" | ||
S3_BUCKET: "my-bucket-name" | ||
LOCAL_PATH: "dist" |
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,45 @@ | ||
import { loadFixture } from '../../../test/util'; | ||
import { extractPackageFile } from './extract'; | ||
|
||
const bitbucketPipelinesYAML = loadFixture('bitbucket-pipelines.yaml'); | ||
|
||
describe('manager/bitbucket-pipelines/extract', () => { | ||
describe('extractPackageFile()', () => { | ||
it('returns null for empty', () => { | ||
expect(extractPackageFile('nothing here')).toBeNull(); | ||
}); | ||
|
||
it('extracts dependencies', () => { | ||
const res = extractPackageFile(bitbucketPipelinesYAML); | ||
expect(res.deps).toMatchInlineSnapshot(` | ||
Array [ | ||
Object { | ||
"autoReplaceStringTemplate": "{{depName}}{{#if newValue}}:{{newValue}}{{/if}}{{#if newDigest}}@{{newDigest}}{{/if}}", | ||
"currentDigest": undefined, | ||
"currentValue": "10.15.1", | ||
"datasource": "docker", | ||
"depName": "node", | ||
"depType": "docker", | ||
"replaceString": "node:10.15.1", | ||
}, | ||
Object { | ||
"autoReplaceStringTemplate": "{{depName}}{{#if newValue}}:{{newValue}}{{/if}}{{#if newDigest}}@{{newDigest}}{{/if}}", | ||
"currentDigest": undefined, | ||
"currentValue": "10.15.2", | ||
"datasource": "docker", | ||
"depName": "node", | ||
"depType": "docker", | ||
"replaceString": "node:10.15.2", | ||
}, | ||
Object { | ||
"currentValue": "0.2.1", | ||
"datasource": "bitbucket-tags", | ||
"depName": "atlassian/aws-s3-deploy", | ||
"depType": "bitbucket-tags", | ||
}, | ||
] | ||
`); | ||
expect(res.deps).toHaveLength(3); | ||
}); | ||
}); | ||
}); |
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,61 @@ | ||
import { logger } from '../../logger'; | ||
import { regEx } from '../../util/regex'; | ||
import { getDep } from '../dockerfile/extract'; | ||
import type { PackageDependency, PackageFile } from '../types'; | ||
|
||
const pipeRegex = regEx(`^\\s*-\\s?pipe:\\s*'?"?([^\\s'"]+)'?"?\\s*$`); | ||
const dockerImageRegex = regEx(`^\\s*-?\\s?image:\\s*'?"?([^\\s'"]+)'?"?\\s*$`); | ||
|
||
export function extractPackageFile(content: string): PackageFile | null { | ||
const deps: PackageDependency[] = []; | ||
|
||
try { | ||
const lines = content.split('\n'); | ||
for (const line of lines) { | ||
const pipeMatch = pipeRegex.exec(line); | ||
if (pipeMatch) { | ||
const pipe = pipeMatch[1]; | ||
const [depName, currentValue] = pipe.split(':'); | ||
|
||
const dep: PackageDependency = { | ||
depName, | ||
currentValue, | ||
datasource: 'bitbucket-tags', | ||
}; | ||
|
||
logger.trace( | ||
{ | ||
depName: dep.depName, | ||
currentValue: dep.currentValue, | ||
}, | ||
'Bitbucket pipe' | ||
); | ||
dep.depType = 'bitbucket-tags'; | ||
deps.push(dep); | ||
} | ||
|
||
const dockerImageMatch = dockerImageRegex.exec(line); | ||
if (dockerImageMatch) { | ||
const currentFrom = dockerImageMatch[1]; | ||
const dep = getDep(currentFrom); | ||
|
||
logger.trace( | ||
{ | ||
depName: dep.depName, | ||
currentValue: dep.currentValue, | ||
currentDigest: dep.currentDigest, | ||
}, | ||
'Docker image' | ||
); | ||
dep.depType = 'docker'; | ||
deps.push(dep); | ||
} | ||
} | ||
} catch (err) /* istanbul ignore next */ { | ||
logger.warn({ err }, 'Error extracting Bitbucket Pipes dependencies'); | ||
} | ||
if (!deps.length) { | ||
return null; | ||
} | ||
return { deps }; | ||
} |
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,7 @@ | ||
import { extractPackageFile } from './extract'; | ||
|
||
export { extractPackageFile }; | ||
|
||
export const defaultConfig = { | ||
fileMatch: ['(^|/)\\.bitbucket-pipelines\\.yaml$'], | ||
}; |
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,3 @@ | ||
Extracts dependencies from Bitbucket Pipelines config files. | ||
|
||
If you need to change the versioning format, read the [versioning](https://docs.renovatebot.com/modules/versioning/) documentation to learn more. |