From 3957efb8d79a8337db58cb9dda514aef20ef2030 Mon Sep 17 00:00:00 2001 From: Richard Simpson Date: Thu, 8 Oct 2020 23:36:44 -0500 Subject: [PATCH 01/12] feat: add github-actions tag support --- .../__fixtures__/main.workflow.1 | 50 ------------------- .../__fixtures__/workflow.yml.2 | 20 ++++++++ .../__snapshots__/extract.spec.ts.snap | 39 +++++++++++++++ lib/manager/github-actions/extract.spec.ts | 8 +-- lib/manager/github-actions/extract.ts | 36 ++++++++++--- 5 files changed, 91 insertions(+), 62 deletions(-) delete mode 100644 lib/manager/github-actions/__fixtures__/main.workflow.1 create mode 100644 lib/manager/github-actions/__fixtures__/workflow.yml.2 diff --git a/lib/manager/github-actions/__fixtures__/main.workflow.1 b/lib/manager/github-actions/__fixtures__/main.workflow.1 deleted file mode 100644 index 09738d3c1c3304..00000000000000 --- a/lib/manager/github-actions/__fixtures__/main.workflow.1 +++ /dev/null @@ -1,50 +0,0 @@ -workflow "Build and Publish" { - on = "push" - resolves = "Docker Publish" -} - -action "Shell Lint" { - uses = "actions/bin/shellcheck@master" - args = "entrypoint.sh" -} - -action "Docker Lint" { - uses = "docker://replicated/dockerfilelint" - args = ["Dockerfile"] -} - -action "Build" { - needs = ["Shell Lint", "Docker Lint"] - uses = "actions/docker/cli@master" - args = "build -t conventional-commits ." -} - -action "Docker Tag" { - needs = ["Build"] - uses = "actions/docker/tag@master" - args = "conventional-commits bcoe/conventional-commits --no-latest" -} - -action "Publish Filter" { - needs = ["Build"] - uses = "actions/bin/filter@master" - args = "branch master" -} - -action "Node_6_Test" { - needs = "Node_6_Install" - runs = "yarn test" - uses = "docker://node:6@sha256:7b65413af120ec5328077775022c78101f103258a1876ec2f83890bce416e896" -} - -action "Docker Login" { - needs = ["Publish Filter"] - uses = "actions/docker/login@master" - secrets = ["DOCKER_USERNAME", "DOCKER_PASSWORD"] -} - -action "Docker Publish" { - needs = ["Docker Tag", "Docker Login"] - uses = "actions/docker/cli@master" - args = "push bcoe/conventional-commits" -} diff --git a/lib/manager/github-actions/__fixtures__/workflow.yml.2 b/lib/manager/github-actions/__fixtures__/workflow.yml.2 new file mode 100644 index 00000000000000..5ad5dc9216e4cc --- /dev/null +++ b/lib/manager/github-actions/__fixtures__/workflow.yml.2 @@ -0,0 +1,20 @@ +name: Run linters + +on: [push] + +jobs: + shell_lint: + name: Shell lint + runs-on: ubuntu-latest + steps: + - name: Shell lint + uses: actions/bin/shellcheck@v1.0.0 + run: ./entrypoint.sh + build: + name: Build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@1.0.0 + - name: Build + uses: actions/docker/cli@master + run: build -t conventional-commits . diff --git a/lib/manager/github-actions/__snapshots__/extract.spec.ts.snap b/lib/manager/github-actions/__snapshots__/extract.spec.ts.snap index f0d680de176315..60f9de702fa9ed 100644 --- a/lib/manager/github-actions/__snapshots__/extract.spec.ts.snap +++ b/lib/manager/github-actions/__snapshots__/extract.spec.ts.snap @@ -1,5 +1,44 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`lib/manager/github-actions/extract extractPackageFile() extracts multiple action tag lines from yaml configuration file 1`] = ` +Array [ + Object { + "currentValue": "v1.0.0", + "datasource": "github-tags", + "depName": "actions/bin/shellcheck", + }, + Object { + "currentValue": "1.0.0", + "datasource": "github-tags", + "depName": "actions/checkout", + }, +] +`; + +exports[`lib/manager/github-actions/extract extractPackageFile() extracts multiple docker image lines from yaml configuration file 1`] = ` +Array [ + Object { + "autoReplaceStringTemplate": "{{depName}}{{#if newValue}}:{{newValue}}{{/if}}{{#if newDigest}}@{{newDigest}}{{/if}}", + "currentDigest": undefined, + "currentValue": undefined, + "datasource": "docker", + "depName": "replicated/dockerfilelint", + "replaceString": "replicated/dockerfilelint", + "versioning": "docker", + }, + Object { + "autoReplaceStringTemplate": "{{depName}}{{#if newValue}}:{{newValue}}{{/if}}{{#if newDigest}}@{{newDigest}}{{/if}}", + "commitMessageTopic": "Node.js", + "currentDigest": "sha256:7b65413af120ec5328077775022c78101f103258a1876ec2f83890bce416e896", + "currentValue": "6", + "datasource": "docker", + "depName": "node", + "replaceString": "node:6@sha256:7b65413af120ec5328077775022c78101f103258a1876ec2f83890bce416e896", + "versioning": "docker", + }, +] +`; + exports[`lib/manager/github-actions/extract extractPackageFile() extracts multiple image lines from docker_container 1`] = ` Array [ Object { diff --git a/lib/manager/github-actions/extract.spec.ts b/lib/manager/github-actions/extract.spec.ts index 346ba1ea3275d8..20ffd9e9c366e1 100644 --- a/lib/manager/github-actions/extract.spec.ts +++ b/lib/manager/github-actions/extract.spec.ts @@ -2,12 +2,12 @@ import { readFileSync } from 'fs'; import { extractPackageFile } from './extract'; const workflow1 = readFileSync( - 'lib/manager/github-actions/__fixtures__/main.workflow.1', + 'lib/manager/github-actions/__fixtures__/workflow.yml.1', 'utf8' ); const workflow2 = readFileSync( - 'lib/manager/github-actions/__fixtures__/workflow.yml.1', + 'lib/manager/github-actions/__fixtures__/workflow.yml.2', 'utf8' ); @@ -16,12 +16,12 @@ describe('lib/manager/github-actions/extract', () => { it('returns null for empty', () => { expect(extractPackageFile('nothing here')).toBeNull(); }); - it('extracts multiple image lines from docker_container', () => { + it('extracts multiple docker image lines from yaml configuration file', () => { const res = extractPackageFile(workflow1); expect(res.deps).toMatchSnapshot(); expect(res.deps).toHaveLength(2); }); - it('extracts multiple image lines from yaml configuration file', () => { + it('extracts multiple action tag lines from yaml configuration file', () => { const res = extractPackageFile(workflow2); expect(res.deps).toMatchSnapshot(); expect(res.deps).toHaveLength(2); diff --git a/lib/manager/github-actions/extract.ts b/lib/manager/github-actions/extract.ts index 4eaf72656a925e..1601fdc4966bf4 100644 --- a/lib/manager/github-actions/extract.ts +++ b/lib/manager/github-actions/extract.ts @@ -1,5 +1,7 @@ +import * as githubTagsDatasource from '../../datasource/github-tags'; import { logger } from '../../logger'; import * as dockerVersioning from '../../versioning/docker'; +import * as semverVersioning from '../../versioning/semver'; import { PackageDependency, PackageFile } from '../common'; import { getDep } from '../dockerfile/extract'; @@ -7,13 +9,13 @@ export function extractPackageFile(content: string): PackageFile | null { logger.debug('github-actions.extractPackageFile()'); const deps: PackageDependency[] = []; for (const line of content.split('\n')) { - // old github actions syntax will be deprecated on September 30, 2019 - // after that, the first line can be removed - const match = - /^\s+uses = "docker:\/\/([^"]+)"\s*$/.exec(line) || - /^\s+uses: docker:\/\/([^"]+)\s*$/.exec(line); - if (match) { - const [, currentFrom] = match; + if (line.trim().startsWith('#')) { + continue; // eslint-disable-line no-continue + } + + const dockerMatch = /^\s+uses: docker:\/\/([^"]+)\s*$/.exec(line); + if (dockerMatch) { + const [, currentFrom] = dockerMatch; const dep = getDep(currentFrom); logger.debug( { @@ -21,10 +23,28 @@ export function extractPackageFile(content: string): PackageFile | null { currentValue: dep.currentValue, currentDigest: dep.currentDigest, }, - 'Docker image inside GitHub Actions' + 'Docker image inside GitHub Workflow' ); dep.versioning = dockerVersioning.id; deps.push(dep); + continue; // eslint-disable-line no-continue + } + + const tagMatch = /^\s+-?\s+?uses: (?[a-z-/]+?)@(?.+?)\s*?$/.exec( + line + ); + if (tagMatch) { + const { depName, currentValue } = tagMatch.groups; + // Only allow tagged versions for now + if (semverVersioning.isVersion(currentValue)) { + const dep = { + depName, + currentValue, + datasource: githubTagsDatasource.id, + }; + logger.debug(dep, 'GitHub Action inside GitHub Workflow'); + deps.push(dep); + } } } if (!deps.length) { From 999f138db1c07b2d598c55dcb96186e906f6bf4b Mon Sep 17 00:00:00 2001 From: Richard Simpson Date: Fri, 9 Oct 2020 00:58:16 -0500 Subject: [PATCH 02/12] amend with more realistic example --- .../__fixtures__/workflow.yml.2 | 7 ++- .../__snapshots__/extract.spec.ts.snap | 58 ++----------------- lib/manager/github-actions/extract.ts | 6 +- 3 files changed, 13 insertions(+), 58 deletions(-) diff --git a/lib/manager/github-actions/__fixtures__/workflow.yml.2 b/lib/manager/github-actions/__fixtures__/workflow.yml.2 index 5ad5dc9216e4cc..bb486d6e214d4e 100644 --- a/lib/manager/github-actions/__fixtures__/workflow.yml.2 +++ b/lib/manager/github-actions/__fixtures__/workflow.yml.2 @@ -8,13 +8,14 @@ jobs: runs-on: ubuntu-latest steps: - name: Shell lint - uses: actions/bin/shellcheck@v1.0.0 + # Isn't supported current + uses: actions/bin/shellcheck@master run: ./entrypoint.sh build: name: Build runs-on: ubuntu-latest steps: - uses: actions/checkout@1.0.0 +# - user: docker/setup-qemu-action@v1 - name: Build - uses: actions/docker/cli@master - run: build -t conventional-commits . + uses: docker/build-push-action@v2 diff --git a/lib/manager/github-actions/__snapshots__/extract.spec.ts.snap b/lib/manager/github-actions/__snapshots__/extract.spec.ts.snap index 60f9de702fa9ed..517303b122313f 100644 --- a/lib/manager/github-actions/__snapshots__/extract.spec.ts.snap +++ b/lib/manager/github-actions/__snapshots__/extract.spec.ts.snap @@ -2,68 +2,22 @@ exports[`lib/manager/github-actions/extract extractPackageFile() extracts multiple action tag lines from yaml configuration file 1`] = ` Array [ - Object { - "currentValue": "v1.0.0", - "datasource": "github-tags", - "depName": "actions/bin/shellcheck", - }, Object { "currentValue": "1.0.0", "datasource": "github-tags", "depName": "actions/checkout", + "versioning": "loose", }, -] -`; - -exports[`lib/manager/github-actions/extract extractPackageFile() extracts multiple docker image lines from yaml configuration file 1`] = ` -Array [ - Object { - "autoReplaceStringTemplate": "{{depName}}{{#if newValue}}:{{newValue}}{{/if}}{{#if newDigest}}@{{newDigest}}{{/if}}", - "currentDigest": undefined, - "currentValue": undefined, - "datasource": "docker", - "depName": "replicated/dockerfilelint", - "replaceString": "replicated/dockerfilelint", - "versioning": "docker", - }, - Object { - "autoReplaceStringTemplate": "{{depName}}{{#if newValue}}:{{newValue}}{{/if}}{{#if newDigest}}@{{newDigest}}{{/if}}", - "commitMessageTopic": "Node.js", - "currentDigest": "sha256:7b65413af120ec5328077775022c78101f103258a1876ec2f83890bce416e896", - "currentValue": "6", - "datasource": "docker", - "depName": "node", - "replaceString": "node:6@sha256:7b65413af120ec5328077775022c78101f103258a1876ec2f83890bce416e896", - "versioning": "docker", - }, -] -`; - -exports[`lib/manager/github-actions/extract extractPackageFile() extracts multiple image lines from docker_container 1`] = ` -Array [ Object { - "autoReplaceStringTemplate": "{{depName}}{{#if newValue}}:{{newValue}}{{/if}}{{#if newDigest}}@{{newDigest}}{{/if}}", - "currentDigest": undefined, - "currentValue": undefined, - "datasource": "docker", - "depName": "replicated/dockerfilelint", - "replaceString": "replicated/dockerfilelint", - "versioning": "docker", - }, - Object { - "autoReplaceStringTemplate": "{{depName}}{{#if newValue}}:{{newValue}}{{/if}}{{#if newDigest}}@{{newDigest}}{{/if}}", - "commitMessageTopic": "Node.js", - "currentDigest": "sha256:7b65413af120ec5328077775022c78101f103258a1876ec2f83890bce416e896", - "currentValue": "6", - "datasource": "docker", - "depName": "node", - "replaceString": "node:6@sha256:7b65413af120ec5328077775022c78101f103258a1876ec2f83890bce416e896", - "versioning": "docker", + "currentValue": "v2", + "datasource": "github-tags", + "depName": "docker/build-push-action", + "versioning": "loose", }, ] `; -exports[`lib/manager/github-actions/extract extractPackageFile() extracts multiple image lines from yaml configuration file 1`] = ` +exports[`lib/manager/github-actions/extract extractPackageFile() extracts multiple docker image lines from yaml configuration file 1`] = ` Array [ Object { "autoReplaceStringTemplate": "{{depName}}{{#if newValue}}:{{newValue}}{{/if}}{{#if newDigest}}@{{newDigest}}{{/if}}", diff --git a/lib/manager/github-actions/extract.ts b/lib/manager/github-actions/extract.ts index 1601fdc4966bf4..2a8809a3db4120 100644 --- a/lib/manager/github-actions/extract.ts +++ b/lib/manager/github-actions/extract.ts @@ -1,7 +1,7 @@ import * as githubTagsDatasource from '../../datasource/github-tags'; import { logger } from '../../logger'; import * as dockerVersioning from '../../versioning/docker'; -import * as semverVersioning from '../../versioning/semver'; +import * as looseVersioning from '../../versioning/loose'; import { PackageDependency, PackageFile } from '../common'; import { getDep } from '../dockerfile/extract'; @@ -35,12 +35,12 @@ export function extractPackageFile(content: string): PackageFile | null { ); if (tagMatch) { const { depName, currentValue } = tagMatch.groups; - // Only allow tagged versions for now - if (semverVersioning.isVersion(currentValue)) { + if (looseVersioning.api.isValid(currentValue)) { const dep = { depName, currentValue, datasource: githubTagsDatasource.id, + versioning: looseVersioning.id, }; logger.debug(dep, 'GitHub Action inside GitHub Workflow'); deps.push(dep); From ace7c48aa9f360e66dae4bc28335bebe7cc79819 Mon Sep 17 00:00:00 2001 From: Richard Simpson Date: Fri, 9 Oct 2020 01:07:21 -0500 Subject: [PATCH 03/12] improve actions regex --- lib/manager/github-actions/__fixtures__/workflow.yml.2 | 2 +- .../github-actions/__snapshots__/extract.spec.ts.snap | 4 ++-- lib/manager/github-actions/extract.ts | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/manager/github-actions/__fixtures__/workflow.yml.2 b/lib/manager/github-actions/__fixtures__/workflow.yml.2 index bb486d6e214d4e..263ab72a26834b 100644 --- a/lib/manager/github-actions/__fixtures__/workflow.yml.2 +++ b/lib/manager/github-actions/__fixtures__/workflow.yml.2 @@ -16,6 +16,6 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@1.0.0 -# - user: docker/setup-qemu-action@v1 +# - uses: docker/setup-qemu-action@v1 - name: Build uses: docker/build-push-action@v2 diff --git a/lib/manager/github-actions/__snapshots__/extract.spec.ts.snap b/lib/manager/github-actions/__snapshots__/extract.spec.ts.snap index 517303b122313f..adbcd771334979 100644 --- a/lib/manager/github-actions/__snapshots__/extract.spec.ts.snap +++ b/lib/manager/github-actions/__snapshots__/extract.spec.ts.snap @@ -5,13 +5,13 @@ Array [ Object { "currentValue": "1.0.0", "datasource": "github-tags", - "depName": "actions/checkout", + "lookupName": "actions/checkout", "versioning": "loose", }, Object { "currentValue": "v2", "datasource": "github-tags", - "depName": "docker/build-push-action", + "lookupName": "docker/build-push-action", "versioning": "loose", }, ] diff --git a/lib/manager/github-actions/extract.ts b/lib/manager/github-actions/extract.ts index 2a8809a3db4120..a122e756d515f2 100644 --- a/lib/manager/github-actions/extract.ts +++ b/lib/manager/github-actions/extract.ts @@ -30,14 +30,14 @@ export function extractPackageFile(content: string): PackageFile | null { continue; // eslint-disable-line no-continue } - const tagMatch = /^\s+-?\s+?uses: (?[a-z-/]+?)@(?.+?)\s*?$/.exec( + const tagMatch = /^^\s+-?\s+?uses: (?[a-zA-Z-_]+\/[a-zA-Z-_]+)(?.*)?@(?.+?)\s*?$/.exec( line ); if (tagMatch) { - const { depName, currentValue } = tagMatch.groups; + const { lookupName, currentValue } = tagMatch.groups; if (looseVersioning.api.isValid(currentValue)) { const dep = { - depName, + lookupName, currentValue, datasource: githubTagsDatasource.id, versioning: looseVersioning.id, From dcdeb48ba8405777d18cdb9fc09217ebe6e76331 Mon Sep 17 00:00:00 2001 From: Richard Simpson Date: Fri, 9 Oct 2020 01:14:57 -0500 Subject: [PATCH 04/12] expand dep info --- .../__snapshots__/extract.spec.ts.snap | 6 ++++++ lib/manager/github-actions/extract.ts | 15 ++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/lib/manager/github-actions/__snapshots__/extract.spec.ts.snap b/lib/manager/github-actions/__snapshots__/extract.spec.ts.snap index adbcd771334979..761ecadd791d21 100644 --- a/lib/manager/github-actions/__snapshots__/extract.spec.ts.snap +++ b/lib/manager/github-actions/__snapshots__/extract.spec.ts.snap @@ -3,15 +3,21 @@ exports[`lib/manager/github-actions/extract extractPackageFile() extracts multiple action tag lines from yaml configuration file 1`] = ` Array [ Object { + "commitMessageTopic": "{{depName}}} Action", "currentValue": "1.0.0", "datasource": "github-tags", + "depName": "actions/checkout", "lookupName": "actions/checkout", + "rangeStrategy": "pin", "versioning": "loose", }, Object { + "commitMessageTopic": "{{depName}}} Action", "currentValue": "v2", "datasource": "github-tags", + "depName": "docker/build-push-action", "lookupName": "docker/build-push-action", + "rangeStrategy": "pin", "versioning": "loose", }, ] diff --git a/lib/manager/github-actions/extract.ts b/lib/manager/github-actions/extract.ts index a122e756d515f2..ab419d91f724a1 100644 --- a/lib/manager/github-actions/extract.ts +++ b/lib/manager/github-actions/extract.ts @@ -34,15 +34,24 @@ export function extractPackageFile(content: string): PackageFile | null { line ); if (tagMatch) { - const { lookupName, currentValue } = tagMatch.groups; + const { lookupName, path, currentValue } = tagMatch.groups; if (looseVersioning.api.isValid(currentValue)) { - const dep = { + const dep: PackageDependency = { + depName: `${lookupName}${path || ''}`, lookupName, currentValue, + commitMessageTopic: '{{depName}}} Action', datasource: githubTagsDatasource.id, versioning: looseVersioning.id, + rangeStrategy: 'pin', }; - logger.debug(dep, 'GitHub Action inside GitHub Workflow'); + logger.debug( + { + depName: dep.depName, + currentValue: dep.currentValue, + }, + 'GitHub Action inside GitHub Workflow' + ); deps.push(dep); } } From 858b6b7f822532d2c930c93f699bcda23352e9e7 Mon Sep 17 00:00:00 2001 From: Richard Simpson Date: Fri, 9 Oct 2020 01:15:44 -0500 Subject: [PATCH 05/12] lowercase action --- lib/manager/github-actions/__snapshots__/extract.spec.ts.snap | 4 ++-- lib/manager/github-actions/extract.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/manager/github-actions/__snapshots__/extract.spec.ts.snap b/lib/manager/github-actions/__snapshots__/extract.spec.ts.snap index 761ecadd791d21..ee10c1116e571f 100644 --- a/lib/manager/github-actions/__snapshots__/extract.spec.ts.snap +++ b/lib/manager/github-actions/__snapshots__/extract.spec.ts.snap @@ -3,7 +3,7 @@ exports[`lib/manager/github-actions/extract extractPackageFile() extracts multiple action tag lines from yaml configuration file 1`] = ` Array [ Object { - "commitMessageTopic": "{{depName}}} Action", + "commitMessageTopic": "{{depName}}} action", "currentValue": "1.0.0", "datasource": "github-tags", "depName": "actions/checkout", @@ -12,7 +12,7 @@ Array [ "versioning": "loose", }, Object { - "commitMessageTopic": "{{depName}}} Action", + "commitMessageTopic": "{{depName}}} action", "currentValue": "v2", "datasource": "github-tags", "depName": "docker/build-push-action", diff --git a/lib/manager/github-actions/extract.ts b/lib/manager/github-actions/extract.ts index ab419d91f724a1..b91ca540f5dac2 100644 --- a/lib/manager/github-actions/extract.ts +++ b/lib/manager/github-actions/extract.ts @@ -40,7 +40,7 @@ export function extractPackageFile(content: string): PackageFile | null { depName: `${lookupName}${path || ''}`, lookupName, currentValue, - commitMessageTopic: '{{depName}}} Action', + commitMessageTopic: '{{depName}}} action', datasource: githubTagsDatasource.id, versioning: looseVersioning.id, rangeStrategy: 'pin', From 09cf9dfd3d83c4bd05f590925c8512cdafc8312a Mon Sep 17 00:00:00 2001 From: Richard Simpson Date: Fri, 9 Oct 2020 01:21:04 -0500 Subject: [PATCH 06/12] address pr feedback --- .../__snapshots__/extract.spec.ts.snap | 2 -- lib/manager/github-actions/extract.ts | 17 +++++------------ 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/lib/manager/github-actions/__snapshots__/extract.spec.ts.snap b/lib/manager/github-actions/__snapshots__/extract.spec.ts.snap index ee10c1116e571f..8225d9f9be9237 100644 --- a/lib/manager/github-actions/__snapshots__/extract.spec.ts.snap +++ b/lib/manager/github-actions/__snapshots__/extract.spec.ts.snap @@ -7,7 +7,6 @@ Array [ "currentValue": "1.0.0", "datasource": "github-tags", "depName": "actions/checkout", - "lookupName": "actions/checkout", "rangeStrategy": "pin", "versioning": "loose", }, @@ -16,7 +15,6 @@ Array [ "currentValue": "v2", "datasource": "github-tags", "depName": "docker/build-push-action", - "lookupName": "docker/build-push-action", "rangeStrategy": "pin", "versioning": "loose", }, diff --git a/lib/manager/github-actions/extract.ts b/lib/manager/github-actions/extract.ts index b91ca540f5dac2..4b8822c577e34f 100644 --- a/lib/manager/github-actions/extract.ts +++ b/lib/manager/github-actions/extract.ts @@ -30,28 +30,21 @@ export function extractPackageFile(content: string): PackageFile | null { continue; // eslint-disable-line no-continue } - const tagMatch = /^^\s+-?\s+?uses: (?[a-zA-Z-_]+\/[a-zA-Z-_]+)(?.*)?@(?.+?)\s*?$/.exec( + const tagMatch = /^^\s+-?\s+?uses: (?[\w-]+\/[\w-]+)(?.*)?@(?.+?)\s*?$/.exec( line ); - if (tagMatch) { - const { lookupName, path, currentValue } = tagMatch.groups; + if (tagMatch?.groups) { + const { depName, currentValue } = tagMatch.groups; if (looseVersioning.api.isValid(currentValue)) { const dep: PackageDependency = { - depName: `${lookupName}${path || ''}`, - lookupName, + depName, currentValue, commitMessageTopic: '{{depName}}} action', datasource: githubTagsDatasource.id, versioning: looseVersioning.id, rangeStrategy: 'pin', }; - logger.debug( - { - depName: dep.depName, - currentValue: dep.currentValue, - }, - 'GitHub Action inside GitHub Workflow' - ); + logger.debug(dep, 'GitHub Action inside GitHub Workflow'); deps.push(dep); } } From f845374c5b4e5734d60626295709d1ca71b73cb7 Mon Sep 17 00:00:00 2001 From: Richard Simpson Date: Fri, 9 Oct 2020 01:46:17 -0500 Subject: [PATCH 07/12] fix: oops --- lib/manager/github-actions/extract.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/manager/github-actions/extract.ts b/lib/manager/github-actions/extract.ts index 4b8822c577e34f..5ffc3448e8852f 100644 --- a/lib/manager/github-actions/extract.ts +++ b/lib/manager/github-actions/extract.ts @@ -25,12 +25,13 @@ export function extractPackageFile(content: string): PackageFile | null { }, 'Docker image inside GitHub Workflow' ); + dep.depType = 'docker'; dep.versioning = dockerVersioning.id; deps.push(dep); continue; // eslint-disable-line no-continue } - const tagMatch = /^^\s+-?\s+?uses: (?[\w-]+\/[\w-]+)(?.*)?@(?.+?)\s*?$/.exec( + const tagMatch = /^\s+-?\s+?uses: (?[\w-]+\/[\w-]+)(?.*)?@(?.+?)\s*?$/.exec( line ); if (tagMatch?.groups) { From 4fda3a58ca1f3049e5ae7b35f2510a9db16a8de3 Mon Sep 17 00:00:00 2001 From: Richard Simpson Date: Fri, 9 Oct 2020 01:50:25 -0500 Subject: [PATCH 08/12] remove old workflow support --- lib/manager/github-actions/index.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/manager/github-actions/index.ts b/lib/manager/github-actions/index.ts index 872becf4cc3749..2410c5e9f794fb 100644 --- a/lib/manager/github-actions/index.ts +++ b/lib/manager/github-actions/index.ts @@ -6,9 +6,6 @@ const language = LANGUAGE_DOCKER; export { extractPackageFile, language }; export const defaultConfig = { - fileMatch: [ - '^\\.github/main.workflow$', - '^\\.github/workflows/[^/]+\\.ya?ml$', - ], + fileMatch: ['^\\.github/workflows/[^/]+\\.ya?ml$'], pinDigests: true, }; From 4fbde9abee5dfcb2ade3e3e5c8a9d3d152519db9 Mon Sep 17 00:00:00 2001 From: Richard Simpson Date: Fri, 9 Oct 2020 19:33:53 -0500 Subject: [PATCH 09/12] fix: switch to docker versioning and github releases datasource --- .../__snapshots__/extract.spec.ts.snap | 33 +++++++++++++++---- lib/manager/github-actions/extract.spec.ts | 6 ++-- lib/manager/github-actions/extract.ts | 24 ++++++-------- 3 files changed, 41 insertions(+), 22 deletions(-) diff --git a/lib/manager/github-actions/__snapshots__/extract.spec.ts.snap b/lib/manager/github-actions/__snapshots__/extract.spec.ts.snap index 8225d9f9be9237..06b9d8711ba66c 100644 --- a/lib/manager/github-actions/__snapshots__/extract.spec.ts.snap +++ b/lib/manager/github-actions/__snapshots__/extract.spec.ts.snap @@ -2,36 +2,56 @@ exports[`lib/manager/github-actions/extract extractPackageFile() extracts multiple action tag lines from yaml configuration file 1`] = ` Array [ + Object { + "commitMessageTopic": "{{depName}}} action", + "currentValue": "master", + "datasource": "github-releases", + "depName": "actions/bin", + "versioning": "docker", + }, Object { "commitMessageTopic": "{{depName}}} action", "currentValue": "1.0.0", - "datasource": "github-tags", + "datasource": "github-releases", "depName": "actions/checkout", - "rangeStrategy": "pin", - "versioning": "loose", + "versioning": "docker", }, Object { "commitMessageTopic": "{{depName}}} action", "currentValue": "v2", - "datasource": "github-tags", + "datasource": "github-releases", "depName": "docker/build-push-action", - "rangeStrategy": "pin", - "versioning": "loose", + "versioning": "docker", }, ] `; exports[`lib/manager/github-actions/extract extractPackageFile() extracts multiple docker image lines from yaml configuration file 1`] = ` Array [ + Object { + "commitMessageTopic": "{{depName}}} action", + "currentValue": "master", + "datasource": "github-releases", + "depName": "actions/bin", + "versioning": "docker", + }, Object { "autoReplaceStringTemplate": "{{depName}}{{#if newValue}}:{{newValue}}{{/if}}{{#if newDigest}}@{{newDigest}}{{/if}}", "currentDigest": undefined, "currentValue": undefined, "datasource": "docker", "depName": "replicated/dockerfilelint", + "depType": "docker", "replaceString": "replicated/dockerfilelint", "versioning": "docker", }, + Object { + "commitMessageTopic": "{{depName}}} action", + "currentValue": "master", + "datasource": "github-releases", + "depName": "actions/docker", + "versioning": "docker", + }, Object { "autoReplaceStringTemplate": "{{depName}}{{#if newValue}}:{{newValue}}{{/if}}{{#if newDigest}}@{{newDigest}}{{/if}}", "commitMessageTopic": "Node.js", @@ -39,6 +59,7 @@ Array [ "currentValue": "6", "datasource": "docker", "depName": "node", + "depType": "docker", "replaceString": "node:6@sha256:7b65413af120ec5328077775022c78101f103258a1876ec2f83890bce416e896", "versioning": "docker", }, diff --git a/lib/manager/github-actions/extract.spec.ts b/lib/manager/github-actions/extract.spec.ts index 20ffd9e9c366e1..ebba27629251df 100644 --- a/lib/manager/github-actions/extract.spec.ts +++ b/lib/manager/github-actions/extract.spec.ts @@ -19,12 +19,14 @@ 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).toHaveLength(2); + expect(res.deps.filter((d) => d.datasource === 'docker')).toHaveLength(2); }); it('extracts multiple action tag lines from yaml configuration file', () => { const res = extractPackageFile(workflow2); expect(res.deps).toMatchSnapshot(); - expect(res.deps).toHaveLength(2); + expect( + res.deps.filter((d) => d.datasource === 'github-releases') + ).toHaveLength(3); }); }); }); diff --git a/lib/manager/github-actions/extract.ts b/lib/manager/github-actions/extract.ts index 5ffc3448e8852f..90f9b63f72a354 100644 --- a/lib/manager/github-actions/extract.ts +++ b/lib/manager/github-actions/extract.ts @@ -1,7 +1,6 @@ -import * as githubTagsDatasource from '../../datasource/github-tags'; +import * as githubReleasesDatasource from '../../datasource/github-releases'; import { logger } from '../../logger'; import * as dockerVersioning from '../../versioning/docker'; -import * as looseVersioning from '../../versioning/loose'; import { PackageDependency, PackageFile } from '../common'; import { getDep } from '../dockerfile/extract'; @@ -36,18 +35,15 @@ export function extractPackageFile(content: string): PackageFile | null { ); if (tagMatch?.groups) { const { depName, currentValue } = tagMatch.groups; - if (looseVersioning.api.isValid(currentValue)) { - const dep: PackageDependency = { - depName, - currentValue, - commitMessageTopic: '{{depName}}} action', - datasource: githubTagsDatasource.id, - versioning: looseVersioning.id, - rangeStrategy: 'pin', - }; - logger.debug(dep, 'GitHub Action inside GitHub Workflow'); - deps.push(dep); - } + const dep: PackageDependency = { + depName, + currentValue, + commitMessageTopic: '{{depName}}} action', + datasource: githubReleasesDatasource.id, + versioning: dockerVersioning.id, + }; + logger.debug(dep, 'GitHub Action inside GitHub Workflow'); + deps.push(dep); } } if (!deps.length) { From 54018d1ff462b7f8eb70f8560ce426b5cd0a494b Mon Sep 17 00:00:00 2001 From: Richard Simpson Date: Sat, 10 Oct 2020 01:22:08 -0500 Subject: [PATCH 10/12] tweak: debug => trace Co-authored-by: Rhys Arkins --- lib/manager/github-actions/extract.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/manager/github-actions/extract.ts b/lib/manager/github-actions/extract.ts index 90f9b63f72a354..c868fe45034361 100644 --- a/lib/manager/github-actions/extract.ts +++ b/lib/manager/github-actions/extract.ts @@ -42,7 +42,7 @@ export function extractPackageFile(content: string): PackageFile | null { datasource: githubReleasesDatasource.id, versioning: dockerVersioning.id, }; - logger.debug(dep, 'GitHub Action inside GitHub Workflow'); + logger.trace(dep, 'GitHub Action inside GitHub Workflow'); deps.push(dep); } } From 08d17a55900466077b3e7ef712d70b087fb939a5 Mon Sep 17 00:00:00 2001 From: Richard Simpson Date: Sat, 10 Oct 2020 01:51:24 -0500 Subject: [PATCH 11/12] switch back to github tags and add skip reason --- .../__snapshots__/extract.spec.ts.snap | 13 ++++++++----- lib/manager/github-actions/extract.spec.ts | 2 +- lib/manager/github-actions/extract.ts | 8 ++++++-- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/lib/manager/github-actions/__snapshots__/extract.spec.ts.snap b/lib/manager/github-actions/__snapshots__/extract.spec.ts.snap index 06b9d8711ba66c..b97ae54319f101 100644 --- a/lib/manager/github-actions/__snapshots__/extract.spec.ts.snap +++ b/lib/manager/github-actions/__snapshots__/extract.spec.ts.snap @@ -5,21 +5,22 @@ Array [ Object { "commitMessageTopic": "{{depName}}} action", "currentValue": "master", - "datasource": "github-releases", + "datasource": "github-tags", "depName": "actions/bin", + "skipReason": "invalid-version", "versioning": "docker", }, Object { "commitMessageTopic": "{{depName}}} action", "currentValue": "1.0.0", - "datasource": "github-releases", + "datasource": "github-tags", "depName": "actions/checkout", "versioning": "docker", }, Object { "commitMessageTopic": "{{depName}}} action", "currentValue": "v2", - "datasource": "github-releases", + "datasource": "github-tags", "depName": "docker/build-push-action", "versioning": "docker", }, @@ -31,8 +32,9 @@ Array [ Object { "commitMessageTopic": "{{depName}}} action", "currentValue": "master", - "datasource": "github-releases", + "datasource": "github-tags", "depName": "actions/bin", + "skipReason": "invalid-version", "versioning": "docker", }, Object { @@ -48,8 +50,9 @@ Array [ Object { "commitMessageTopic": "{{depName}}} action", "currentValue": "master", - "datasource": "github-releases", + "datasource": "github-tags", "depName": "actions/docker", + "skipReason": "invalid-version", "versioning": "docker", }, Object { diff --git a/lib/manager/github-actions/extract.spec.ts b/lib/manager/github-actions/extract.spec.ts index ebba27629251df..4b5b6f0a6140df 100644 --- a/lib/manager/github-actions/extract.spec.ts +++ b/lib/manager/github-actions/extract.spec.ts @@ -25,7 +25,7 @@ describe('lib/manager/github-actions/extract', () => { const res = extractPackageFile(workflow2); expect(res.deps).toMatchSnapshot(); expect( - res.deps.filter((d) => d.datasource === 'github-releases') + res.deps.filter((d) => d.datasource === 'github-tags') ).toHaveLength(3); }); }); diff --git a/lib/manager/github-actions/extract.ts b/lib/manager/github-actions/extract.ts index c868fe45034361..cf9adc5ccba9ae 100644 --- a/lib/manager/github-actions/extract.ts +++ b/lib/manager/github-actions/extract.ts @@ -1,5 +1,6 @@ -import * as githubReleasesDatasource from '../../datasource/github-releases'; +import * as githubTagsDatasource from '../../datasource/github-tags'; import { logger } from '../../logger'; +import { SkipReason } from '../../types'; import * as dockerVersioning from '../../versioning/docker'; import { PackageDependency, PackageFile } from '../common'; import { getDep } from '../dockerfile/extract'; @@ -39,9 +40,12 @@ export function extractPackageFile(content: string): PackageFile | null { depName, currentValue, commitMessageTopic: '{{depName}}} action', - datasource: githubReleasesDatasource.id, + datasource: githubTagsDatasource.id, versioning: dockerVersioning.id, }; + if (!dockerVersioning.api.isValid(currentValue)) { + dep.skipReason = SkipReason.InvalidVersion; + } logger.trace(dep, 'GitHub Action inside GitHub Workflow'); deps.push(dep); } From b0e91d4f6a34f44886a2640eba4fa613c470a30f Mon Sep 17 00:00:00 2001 From: Rhys Arkins Date: Mon, 19 Oct 2020 09:36:08 +0200 Subject: [PATCH 12/12] Remove logs --- lib/manager/github-actions/extract.ts | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/lib/manager/github-actions/extract.ts b/lib/manager/github-actions/extract.ts index cf9adc5ccba9ae..07a0a6fca006f1 100644 --- a/lib/manager/github-actions/extract.ts +++ b/lib/manager/github-actions/extract.ts @@ -6,7 +6,7 @@ import { PackageDependency, PackageFile } from '../common'; import { getDep } from '../dockerfile/extract'; export function extractPackageFile(content: string): PackageFile | null { - logger.debug('github-actions.extractPackageFile()'); + logger.trace('github-actions.extractPackageFile()'); const deps: PackageDependency[] = []; for (const line of content.split('\n')) { if (line.trim().startsWith('#')) { @@ -17,14 +17,6 @@ export function extractPackageFile(content: string): PackageFile | null { if (dockerMatch) { const [, currentFrom] = dockerMatch; const dep = getDep(currentFrom); - logger.debug( - { - depName: dep.depName, - currentValue: dep.currentValue, - currentDigest: dep.currentDigest, - }, - 'Docker image inside GitHub Workflow' - ); dep.depType = 'docker'; dep.versioning = dockerVersioning.id; deps.push(dep); @@ -46,7 +38,6 @@ export function extractPackageFile(content: string): PackageFile | null { if (!dockerVersioning.api.isValid(currentValue)) { dep.skipReason = SkipReason.InvalidVersion; } - logger.trace(dep, 'GitHub Action inside GitHub Workflow'); deps.push(dep); } }