Skip to content

Commit

Permalink
feat: add github-actions tag support (#7434)
Browse files Browse the repository at this point in the history
  • Loading branch information
RichiCoder1 authored Oct 20, 2020
1 parent d37111c commit 2374bca
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 91 deletions.
50 changes: 0 additions & 50 deletions lib/manager/github-actions/__fixtures__/main.workflow.1

This file was deleted.

21 changes: 21 additions & 0 deletions lib/manager/github-actions/__fixtures__/workflow.yml.2
Original file line number Diff line number Diff line change
@@ -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/[email protected]
# - uses: docker/setup-qemu-action@v1
- name: Build
uses: docker/build-push-action@v2
51 changes: 36 additions & 15 deletions lib/manager/github-actions/__snapshots__/extract.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -1,47 +1,68 @@
// 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",
"currentDigest": "sha256:7b65413af120ec5328077775022c78101f103258a1876ec2f83890bce416e896",
"currentValue": "6",
"datasource": "docker",
"depName": "node",
"depType": "docker",
"replaceString": "node:6@sha256:7b65413af120ec5328077775022c78101f103258a1876ec2f83890bce416e896",
"versioning": "docker",
},
Expand Down
14 changes: 8 additions & 6 deletions lib/manager/github-actions/extract.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
);

Expand All @@ -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);
});
});
});
46 changes: 30 additions & 16 deletions lib/manager/github-actions/extract.ts
Original file line number Diff line number Diff line change
@@ -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: (?<depName>[\w-]+\/[\w-]+)(?<path>.*)?@(?<currentValue>.+?)\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) {
Expand Down
5 changes: 1 addition & 4 deletions lib/manager/github-actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

0 comments on commit 2374bca

Please sign in to comment.