Skip to content

Commit

Permalink
fix(manager/github-actions): renovate propose to delete YAML inline c…
Browse files Browse the repository at this point in the history
…omments (#14757)
  • Loading branch information
Gabriel-Ladzaretti authored Mar 25, 2022
1 parent 559f805 commit a9e0825
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 17 deletions.
11 changes: 11 additions & 0 deletions lib/modules/manager/github-actions/__fixtures__/workflow_3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ jobs:
steps:
- name: Auto merge
uses: "pascalgn/[email protected]"

env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
MERGE_METHOD: squash

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@1e204e9a9253d643386038d443f96446fa156a97 # renovate: tag=v2.3.5 # Comment that Renovate bot has moved Comment that Renovate bot will remove later on
- uses: actions/checkout@v1 # Comment that Renovate bot will remove later on
- uses: "actions/[email protected]" # Comment that Renovate bot will remove later on

- name: Run a one-line script
run: echo Hello, world!
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,52 @@ Array [
]
`;

exports[`modules/manager/github-actions/extract extractPackageFile() extracts multiple action tag lines with double quotes and comments 1`] = `
Array [
Object {
"autoReplaceStringTemplate": "{{depName}}@{{#if newDigest}}{{newDigest}}{{#if newValue}} # tag={{newValue}}{{/if}}{{/if}}{{#unless newDigest}}{{newValue}}{{/unless}}",
"commitMessageTopic": "{{{depName}}} action",
"currentValue": "v0.13.1",
"datasource": "github-tags",
"depName": "pascalgn/automerge-action",
"depType": "action",
"replaceString": "\\"pascalgn/automerge-action@v0.13.1\\"",
"versioning": "docker",
},
Object {
"autoReplaceStringTemplate": "{{depName}}@{{#if newDigest}}{{newDigest}}{{#if newValue}} # tag={{newValue}}{{/if}}{{/if}}{{#unless newDigest}}{{newValue}}{{/unless}}",
"commitMessageTopic": "{{{depName}}} action",
"currentDigest": "1e204e9a9253d643386038d443f96446fa156a97",
"currentValue": "v2.3.5",
"datasource": "github-tags",
"depName": "actions/checkout",
"depType": "action",
"replaceString": "actions/checkout@1e204e9a9253d643386038d443f96446fa156a97 # renovate: tag=v2.3.5",
"versioning": "docker",
},
Object {
"autoReplaceStringTemplate": "{{depName}}@{{#if newDigest}}{{newDigest}}{{#if newValue}} # tag={{newValue}}{{/if}}{{/if}}{{#unless newDigest}}{{newValue}}{{/unless}}",
"commitMessageTopic": "{{{depName}}} action",
"currentValue": "v1",
"datasource": "github-tags",
"depName": "actions/checkout",
"depType": "action",
"replaceString": "actions/checkout@v1",
"versioning": "docker",
},
Object {
"autoReplaceStringTemplate": "{{depName}}@{{#if newDigest}}{{newDigest}}{{#if newValue}} # tag={{newValue}}{{/if}}{{/if}}{{#unless newDigest}}{{newValue}}{{/unless}}",
"commitMessageTopic": "{{{depName}}} action",
"currentValue": "v1.1.2",
"datasource": "github-tags",
"depName": "actions/checkout",
"depType": "action",
"replaceString": "\\"actions/checkout@v1.1.2\\"",
"versioning": "docker",
},
]
`;

exports[`modules/manager/github-actions/extract extractPackageFile() extracts multiple docker image lines from yaml configuration file 1`] = `
Array [
Object {
Expand Down Expand Up @@ -136,18 +182,3 @@ Array [
},
]
`;

exports[`modules/manager/github-actions/extract extractPackageFile() extracts tag line with double quotes 1`] = `
Array [
Object {
"autoReplaceStringTemplate": "{{depName}}@{{#if newDigest}}{{newDigest}}{{#if newValue}} # tag={{newValue}}{{/if}}{{/if}}{{#unless newDigest}}{{newValue}}{{/unless}}",
"commitMessageTopic": "{{{depName}}} action",
"currentValue": "v0.13.1",
"datasource": "github-tags",
"depName": "pascalgn/automerge-action",
"depType": "action",
"replaceString": "\\"pascalgn/automerge-action@v0.13.1\\"",
"versioning": "docker",
},
]
`;
27 changes: 26 additions & 1 deletion lib/modules/manager/github-actions/extract.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('modules/manager/github-actions/extract', () => {
res.deps.filter((d) => d.datasource === 'github-tags')
).toHaveLength(8);
});
it('extracts tag line with double quotes', () => {
it('extracts multiple action tag lines with double quotes and comments', () => {
const res = extractPackageFile(Fixtures.get('workflow_3.yml'));
expect(res.deps).toMatchSnapshot([
{
Expand All @@ -29,6 +29,31 @@ describe('modules/manager/github-actions/extract', () => {
replaceString: '"pascalgn/[email protected]"',
versioning: 'docker',
},
{
currentValue: 'v2.3.5',
datasource: 'github-tags',
depName: 'actions/checkout',
depType: 'action',
replaceString:
'actions/checkout@1e204e9a9253d643386038d443f96446fa156a97 # renovate: tag=v2.3.5',
versioning: 'docker',
},
{
currentValue: 'v1',
datasource: 'github-tags',
depName: 'actions/checkout',
depType: 'action',
replaceString: 'actions/checkout@v1',
versioning: 'docker',
},
{
currentValue: 'v1.1.2',
datasource: 'github-tags',
depName: 'actions/checkout',
depType: 'action',
replaceString: '"actions/[email protected]"',
versioning: 'docker',
},
]);
});
});
Expand Down
2 changes: 1 addition & 1 deletion lib/modules/manager/github-actions/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type { PackageDependency, PackageFile } from '../types';

const dockerRe = regEx(/^\s+uses: docker:\/\/([^"]+)\s*$/);
const actionRe = regEx(
/^\s+-?\s+?uses: (?<replaceString>['"]?(?<depName>[\w-]+\/[\w-]+)(?<path>\/.*)?@(?<currentValue>.+?)\s*['"]?(?:#\s+(?:renovate:\s+)?tag=(?<tag>.+?))?)\s*?$/
/^\s+-?\s+?uses: (?<replaceString>['"]?(?<depName>[\w-]+\/[\w-]+)(?<path>\/.*)?@(?<currentValue>[^\s'"]+)['"]?(?:\s+#\s+(?:renovate:\s+)?tag=(?<tag>\S+))?)/
);

// SHA1 or SHA256, see https://github.blog/2020-10-19-git-2-29-released/
Expand Down

0 comments on commit a9e0825

Please sign in to comment.