Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add github-actions tag support #7434

Merged
merged 17 commits into from
Oct 20, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
27 changes: 10 additions & 17 deletions lib/manager/github-actions/__snapshots__/extract.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -1,30 +1,23 @@
// 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",
"versioning": "docker",
"currentValue": "1.0.0",
"datasource": "github-tags",
"lookupName": "actions/checkout",
"versioning": "loose",
},
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",
"lookupName": "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}}",
Expand Down
8 changes: 4 additions & 4 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,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);
Expand Down
36 changes: 28 additions & 8 deletions lib/manager/github-actions/extract.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,50 @@
import * as githubTagsDatasource from '../../datasource/github-tags';
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';

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(
{
depName: dep.depName,
currentValue: dep.currentValue,
currentDigest: dep.currentDigest,
},
'Docker image inside GitHub Actions'
'Docker image inside GitHub Workflow'
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be removed

dep.versioning = dockerVersioning.id;
deps.push(dep);
continue; // eslint-disable-line no-continue
}

const tagMatch = /^^\s+-?\s+?uses: (?<lookupName>[a-zA-Z-_]+\/[a-zA-Z-_]+)(?<path>.*)?@(?<currentValue>.+?)\s*?$/.exec(
viceice marked this conversation as resolved.
Show resolved Hide resolved
line
);
if (tagMatch) {
viceice marked this conversation as resolved.
Show resolved Hide resolved
const { lookupName, currentValue } = tagMatch.groups;
viceice marked this conversation as resolved.
Show resolved Hide resolved
if (looseVersioning.api.isValid(currentValue)) {
const dep = {
lookupName,
viceice marked this conversation as resolved.
Show resolved Hide resolved
currentValue,
datasource: githubTagsDatasource.id,
versioning: looseVersioning.id,
RichiCoder1 marked this conversation as resolved.
Show resolved Hide resolved
};
logger.debug(dep, 'GitHub Action inside GitHub Workflow');
deps.push(dep);
}
}
}
if (!deps.length) {
Expand Down