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 1 commit
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.

20 changes: 20 additions & 0 deletions lib/manager/github-actions/__fixtures__/workflow.yml.2
Original file line number Diff line number Diff line change
@@ -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/[email protected]
run: ./entrypoint.sh
build:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
- name: Build
uses: actions/docker/cli@master
run: build -t conventional-commits .
39 changes: 39 additions & 0 deletions lib/manager/github-actions/__snapshots__/extract.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -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",
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think this is valid tags - perhaps needs lookupName? Also github.com/actions/bin doesn't exist either?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ha, that's fair. I'll update the examples to something more realistic and maybe add a path nesting limit.

Copy link
Collaborator

@rarkins rarkins Oct 9, 2020

Choose a reason for hiding this comment

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

if it's a/b/c then the a/b represents the repo while c is file or folder name? And if there's multiple actions within one repo then they share the same tags? Ie tags are per repo and not per action?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmmm. While actions technically supports repo subpaths, the recommendation is to have a single action per repo. At least for this first pass of getting this working, I wouldn't support the path'd version as the way most people would likely use that is via SHAs and not tags. Or would require some sort of tag prefixing support.

Copy link
Collaborator

Choose a reason for hiding this comment

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

If it's technically possible then we should ideally support it. In this case the lookupName would be a/b

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I actually did end up doing this. The latest version of the regex will extract owner/repo and ignore the path.

},
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 {
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 semverVersioning from '../../versioning/semver';
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: (?<depName>[a-z-/]+?)@(?<currentValue>.+?)\s*?$/.exec(
line
);
if (tagMatch) {
viceice marked this conversation as resolved.
Show resolved Hide resolved
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) {
Expand Down