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..263ab72a26834b --- /dev/null +++ b/lib/manager/github-actions/__fixtures__/workflow.yml.2 @@ -0,0 +1,21 @@ +name: Run linters + +on: [push] + +jobs: + shell_lint: + name: Shell lint + runs-on: ubuntu-latest + steps: + - name: Shell lint + # 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 +# - 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 f0d680de176315..b97ae54319f101 100644 --- a/lib/manager/github-actions/__snapshots__/extract.spec.ts.snap +++ b/lib/manager/github-actions/__snapshots__/extract.spec.ts.snap @@ -1,40 +1,60 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`lib/manager/github-actions/extract extractPackageFile() extracts multiple image lines from docker_container 1`] = ` +exports[`lib/manager/github-actions/extract extractPackageFile() extracts multiple action tag 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", + "commitMessageTopic": "{{depName}}} action", + "currentValue": "master", + "datasource": "github-tags", + "depName": "actions/bin", + "skipReason": "invalid-version", "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", + "commitMessageTopic": "{{depName}}} action", + "currentValue": "1.0.0", + "datasource": "github-tags", + "depName": "actions/checkout", + "versioning": "docker", + }, + Object { + "commitMessageTopic": "{{depName}}} action", + "currentValue": "v2", + "datasource": "github-tags", + "depName": "docker/build-push-action", "versioning": "docker", }, ] `; -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 { + "commitMessageTopic": "{{depName}}} action", + "currentValue": "master", + "datasource": "github-tags", + "depName": "actions/bin", + "skipReason": "invalid-version", + "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-tags", + "depName": "actions/docker", + "skipReason": "invalid-version", + "versioning": "docker", + }, Object { "autoReplaceStringTemplate": "{{depName}}{{#if newValue}}:{{newValue}}{{/if}}{{#if newDigest}}@{{newDigest}}{{/if}}", "commitMessageTopic": "Node.js", @@ -42,6 +62,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 346ba1ea3275d8..4b5b6f0a6140df 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,15 +16,17 @@ 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); + expect(res.deps.filter((d) => d.datasource === 'docker')).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); + expect( + 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 4eaf72656a925e..07a0a6fca006f1 100644 --- a/lib/manager/github-actions/extract.ts +++ b/lib/manager/github-actions/extract.ts @@ -1,30 +1,44 @@ +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'; 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')) { - // 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( - { - depName: dep.depName, - currentValue: dep.currentValue, - currentDigest: dep.currentDigest, - }, - 'Docker image inside GitHub Actions' - ); + 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( + line + ); + if (tagMatch?.groups) { + const { depName, currentValue } = tagMatch.groups; + const dep: PackageDependency = { + depName, + currentValue, + commitMessageTopic: '{{depName}}} action', + datasource: githubTagsDatasource.id, + versioning: dockerVersioning.id, + }; + if (!dockerVersioning.api.isValid(currentValue)) { + dep.skipReason = SkipReason.InvalidVersion; + } + deps.push(dep); } } if (!deps.length) { 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, };