From d409618984ceace42a62c3f8655f5d5f94bc2f9b Mon Sep 17 00:00:00 2001
From: Douglas Duteil <douglasduteil@gmail.com>
Date: Fri, 26 Feb 2021 16:44:51 +0100
Subject: [PATCH] feat(github-actions): support jobs.<job_id>.container.image
 (#8829)

Co-authored-by: Rhys Arkins <rhys@arkins.net>
---
 lib/manager/github-actions/__fixtures__/workflow.yml.1   | 5 +++++
 .../github-actions/__snapshots__/extract.spec.ts.snap    | 9 +++++++++
 lib/manager/github-actions/extract.spec.ts               | 2 +-
 lib/manager/github-actions/extract.ts                    | 9 +++++++++
 4 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/lib/manager/github-actions/__fixtures__/workflow.yml.1 b/lib/manager/github-actions/__fixtures__/workflow.yml.1
index 1513408eee..cf92d10e68 100644
--- a/lib/manager/github-actions/__fixtures__/workflow.yml.1
+++ b/lib/manager/github-actions/__fixtures__/workflow.yml.1
@@ -30,3 +30,8 @@ jobs:
     steps:
       - name: Node 6 test
         uses: docker://node:6@sha256:7b65413af120ec5328077775022c78101f103258a1876ec2f83890bce416e896
+  container_image_test:
+    name: Container Image Test
+    runs-on: ubuntu-latest
+    container:
+      image: hadolint/hadolint:v1.0.0-alpine
diff --git a/lib/manager/github-actions/__snapshots__/extract.spec.ts.snap b/lib/manager/github-actions/__snapshots__/extract.spec.ts.snap
index 5619b6bc76..e302addf49 100644
--- a/lib/manager/github-actions/__snapshots__/extract.spec.ts.snap
+++ b/lib/manager/github-actions/__snapshots__/extract.spec.ts.snap
@@ -76,5 +76,14 @@ Array [
     "replaceString": "node:6@sha256:7b65413af120ec5328077775022c78101f103258a1876ec2f83890bce416e896",
     "versioning": "docker",
   },
+  Object {
+    "autoReplaceStringTemplate": "{{depName}}{{#if newValue}}:{{newValue}}{{/if}}{{#if newDigest}}@{{newDigest}}{{/if}}",
+    "currentDigest": undefined,
+    "currentValue": "v1.0.0-alpine",
+    "datasource": "docker",
+    "depName": "hadolint/hadolint",
+    "depType": "docker",
+    "replaceString": "hadolint/hadolint:v1.0.0-alpine",
+  },
 ]
 `;
diff --git a/lib/manager/github-actions/extract.spec.ts b/lib/manager/github-actions/extract.spec.ts
index 4b5b6f0a61..7d7675f51b 100644
--- a/lib/manager/github-actions/extract.spec.ts
+++ b/lib/manager/github-actions/extract.spec.ts
@@ -19,7 +19,7 @@ describe('lib/manager/github-actions/extract', () => {
     it('extracts multiple docker image lines from yaml configuration file', () => {
       const res = extractPackageFile(workflow1);
       expect(res.deps).toMatchSnapshot();
-      expect(res.deps.filter((d) => d.datasource === 'docker')).toHaveLength(2);
+      expect(res.deps.filter((d) => d.datasource === 'docker')).toHaveLength(3);
     });
     it('extracts multiple action tag lines from yaml configuration file', () => {
       const res = extractPackageFile(workflow2);
diff --git a/lib/manager/github-actions/extract.ts b/lib/manager/github-actions/extract.ts
index 3608ad6a93..6f154e84d0 100644
--- a/lib/manager/github-actions/extract.ts
+++ b/lib/manager/github-actions/extract.ts
@@ -13,6 +13,15 @@ export function extractPackageFile(content: string): PackageFile | null {
       continue; // eslint-disable-line no-continue
     }
 
+    const containerImageMatch = /^\s+image: ([^"]+)\s*$/.exec(line);
+    if (containerImageMatch) {
+      const [, currentFrom] = containerImageMatch;
+      const dep = getDep(currentFrom);
+      dep.depType = 'docker';
+      deps.push(dep);
+      continue; // eslint-disable-line no-continue
+    }
+
     const dockerMatch = /^\s+uses: docker:\/\/([^"]+)\s*$/.exec(line);
     if (dockerMatch) {
       const [, currentFrom] = dockerMatch;
-- 
GitLab