From a9e08256c7cff83d8400b74c7d9b4830b0251d5a Mon Sep 17 00:00:00 2001 From: Gabriel-Ladzaretti <97394622+Gabriel-Ladzaretti@users.noreply.github.com> Date: Fri, 25 Mar 2022 12:55:44 +0300 Subject: [PATCH] fix(manager/github-actions): renovate propose to delete YAML inline comments (#14757) --- .../__fixtures__/workflow_3.yml | 11 ++++ .../__snapshots__/extract.spec.ts.snap | 61 ++++++++++++++----- .../manager/github-actions/extract.spec.ts | 27 +++++++- lib/modules/manager/github-actions/extract.ts | 2 +- 4 files changed, 84 insertions(+), 17 deletions(-) diff --git a/lib/modules/manager/github-actions/__fixtures__/workflow_3.yml b/lib/modules/manager/github-actions/__fixtures__/workflow_3.yml index 781bec6781..44fcd988ea 100644 --- a/lib/modules/manager/github-actions/__fixtures__/workflow_3.yml +++ b/lib/modules/manager/github-actions/__fixtures__/workflow_3.yml @@ -4,6 +4,17 @@ jobs: steps: - name: Auto merge uses: "pascalgn/automerge-action@v0.13.1" + 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/checkout@v1.1.2" # Comment that Renovate bot will remove later on + + - name: Run a one-line script + run: echo Hello, world! diff --git a/lib/modules/manager/github-actions/__snapshots__/extract.spec.ts.snap b/lib/modules/manager/github-actions/__snapshots__/extract.spec.ts.snap index 4d64e16f38..a4b68ba2b5 100644 --- a/lib/modules/manager/github-actions/__snapshots__/extract.spec.ts.snap +++ b/lib/modules/manager/github-actions/__snapshots__/extract.spec.ts.snap @@ -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 { @@ -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", - }, -] -`; diff --git a/lib/modules/manager/github-actions/extract.spec.ts b/lib/modules/manager/github-actions/extract.spec.ts index 2f7e757e96..625b93e373 100644 --- a/lib/modules/manager/github-actions/extract.spec.ts +++ b/lib/modules/manager/github-actions/extract.spec.ts @@ -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([ { @@ -29,6 +29,31 @@ describe('modules/manager/github-actions/extract', () => { replaceString: '"pascalgn/automerge-action@v0.13.1"', 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/checkout@v1.1.2"', + versioning: 'docker', + }, ]); }); }); diff --git a/lib/modules/manager/github-actions/extract.ts b/lib/modules/manager/github-actions/extract.ts index 4094bf2604..222263fc40 100644 --- a/lib/modules/manager/github-actions/extract.ts +++ b/lib/modules/manager/github-actions/extract.ts @@ -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/ -- GitLab