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 a4b68ba2b5cafb0d918da6520a9723d0b9652639..721889f778d9d844d7ba778507a700f8ebc65c52 100644 --- a/lib/modules/manager/github-actions/__snapshots__/extract.spec.ts.snap +++ b/lib/modules/manager/github-actions/__snapshots__/extract.spec.ts.snap @@ -93,7 +93,7 @@ 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}}", + "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", @@ -124,7 +124,7 @@ Array [ "versioning": "docker", }, Object { - "autoReplaceStringTemplate": "{{depName}}@{{#if newDigest}}{{newDigest}}{{#if newValue}} # tag={{newValue}}{{/if}}{{/if}}{{#unless newDigest}}{{newValue}}{{/unless}}", + "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", diff --git a/lib/modules/manager/github-actions/extract.spec.ts b/lib/modules/manager/github-actions/extract.spec.ts index a3f129c54b8359b5da68a0c3fddc03e5f7fb40a7..3dde39333118142c7e99352e17b054491843952d 100644 --- a/lib/modules/manager/github-actions/extract.spec.ts +++ b/lib/modules/manager/github-actions/extract.spec.ts @@ -59,5 +59,87 @@ describe('modules/manager/github-actions/extract', () => { }, ]); }); + + it('maintains quotes', () => { + const yamlContent = ` + jobs: + build: + steps: + - name: "test1" + uses: actions/setup-node@56337c425554a6be30cdef71bf441f15be286854 # tag=v3.1.1 + - name: "test2" + uses: 'actions/setup-node@1f8c6b94b26d0feae1e387ca63ccbdc44d27b561' # tag=v3.1.1 + - name: "test3" + uses: "actions/setup-node@1f8c6b94b26d0feae1e387ca63ccbdc44d27b561" # tag=v2.5.1 + - name: "checkout repository" + uses: "actions/checkout@v2" # comment after + - name: "quoted, no comment, outdated" + uses: "actions/setup-java@v2"`; + + const res = extractPackageFile(yamlContent); + expect(res.deps).toMatchObject([ + { + depName: 'actions/setup-node', + commitMessageTopic: '{{{depName}}} action', + datasource: 'github-tags', + versioning: 'docker', + depType: 'action', + replaceString: + 'actions/setup-node@56337c425554a6be30cdef71bf441f15be286854 # tag=v3.1.1', + autoReplaceStringTemplate: + '{{depName}}@{{#if newDigest}}{{newDigest}}{{#if newValue}} # tag={{newValue}}{{/if}}{{/if}}{{#unless newDigest}}{{newValue}}{{/unless}}', + currentValue: 'v3.1.1', + currentDigest: '56337c425554a6be30cdef71bf441f15be286854', + }, + { + depName: 'actions/setup-node', + commitMessageTopic: '{{{depName}}} action', + datasource: 'github-tags', + versioning: 'docker', + depType: 'action', + replaceString: + "'actions/setup-node@1f8c6b94b26d0feae1e387ca63ccbdc44d27b561' # tag=v3.1.1", + autoReplaceStringTemplate: + "'{{depName}}@{{#if newDigest}}{{newDigest}}'{{#if newValue}} # tag={{newValue}}{{/if}}{{/if}}{{#unless newDigest}}{{newValue}}'{{/unless}}", + currentValue: 'v3.1.1', + currentDigest: '1f8c6b94b26d0feae1e387ca63ccbdc44d27b561', + }, + { + depName: 'actions/setup-node', + commitMessageTopic: '{{{depName}}} action', + datasource: 'github-tags', + versioning: 'docker', + depType: 'action', + replaceString: + '"actions/setup-node@1f8c6b94b26d0feae1e387ca63ccbdc44d27b561" # tag=v2.5.1', + autoReplaceStringTemplate: + '"{{depName}}@{{#if newDigest}}{{newDigest}}"{{#if newValue}} # tag={{newValue}}{{/if}}{{/if}}{{#unless newDigest}}{{newValue}}"{{/unless}}', + currentValue: 'v2.5.1', + currentDigest: '1f8c6b94b26d0feae1e387ca63ccbdc44d27b561', + }, + { + depName: 'actions/checkout', + commitMessageTopic: '{{{depName}}} action', + datasource: 'github-tags', + versioning: 'docker', + depType: 'action', + replaceString: '"actions/checkout@v2"', + autoReplaceStringTemplate: + '"{{depName}}@{{#if newDigest}}{{newDigest}}"{{#if newValue}} # tag={{newValue}}{{/if}}{{/if}}{{#unless newDigest}}{{newValue}}"{{/unless}}', + currentValue: 'v2', + }, + { + depName: 'actions/setup-java', + commitMessageTopic: '{{{depName}}} action', + datasource: 'github-tags', + versioning: 'docker', + depType: 'action', + replaceString: '"actions/setup-java@v2"', + autoReplaceStringTemplate: + '"{{depName}}@{{#if newDigest}}{{newDigest}}"{{#if newValue}} # tag={{newValue}}{{/if}}{{/if}}{{#unless newDigest}}{{newValue}}"{{/unless}}', + currentValue: 'v2', + }, + ]); + }); }); }); diff --git a/lib/modules/manager/github-actions/extract.ts b/lib/modules/manager/github-actions/extract.ts index 222263fc400ef7b5815a287869c697f6c1e323bf..c5162e583a15ddb2e2fb45254780754270e7a1e0 100644 --- a/lib/modules/manager/github-actions/extract.ts +++ b/lib/modules/manager/github-actions/extract.ts @@ -40,6 +40,13 @@ export function extractPackageFile(content: string): PackageFile | null { tag, replaceString, } = tagMatch.groups; + let quotes = ''; + if (replaceString.indexOf("'") >= 0) { + quotes = "'"; + } + if (replaceString.indexOf('"') >= 0) { + quotes = '"'; + } const dep: PackageDependency = { depName, commitMessageTopic: '{{{depName}}} action', @@ -47,7 +54,7 @@ export function extractPackageFile(content: string): PackageFile | null { versioning: dockerVersioning.id, depType: 'action', replaceString, - autoReplaceStringTemplate: `{{depName}}${path}@{{#if newDigest}}{{newDigest}}{{#if newValue}} # tag={{newValue}}{{/if}}{{/if}}{{#unless newDigest}}{{newValue}}{{/unless}}`, + autoReplaceStringTemplate: `${quotes}{{depName}}${path}@{{#if newDigest}}{{newDigest}}${quotes}{{#if newValue}} # tag={{newValue}}{{/if}}{{/if}}{{#unless newDigest}}{{newValue}}${quotes}{{/unless}}`, }; if (shaRe.test(currentValue)) { dep.currentValue = tag;