Skip to content

Commit

Permalink
feat(github-actions): support GitHub actions runners (#23633)
Browse files Browse the repository at this point in the history
Co-authored-by: HonkingGoose <34918129+HonkingGoose@users.noreply.github.com>
  • Loading branch information
PeterNitsche and HonkingGoose committed Aug 8, 2023
1 parent 15cfe4b commit 1ecaab2
Show file tree
Hide file tree
Showing 10 changed files with 362 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/modules/datasource/api.ts
Expand Up @@ -25,6 +25,7 @@ import { GitRefsDatasource } from './git-refs';
import { GitTagsDatasource } from './git-tags';
import { GithubReleaseAttachmentsDatasource } from './github-release-attachments';
import { GithubReleasesDatasource } from './github-releases';
import { GithubRunnersDatasource } from './github-runners';
import { GithubTagsDatasource } from './github-tags';
import { GitlabPackagesDatasource } from './gitlab-packages';
import { GitlabReleasesDatasource } from './gitlab-releases';
Expand Down Expand Up @@ -90,6 +91,7 @@ api.set(
new GithubReleaseAttachmentsDatasource()
);
api.set(GithubReleasesDatasource.id, new GithubReleasesDatasource());
api.set(GithubRunnersDatasource.id, new GithubRunnersDatasource());
api.set(GithubTagsDatasource.id, new GithubTagsDatasource());
api.set(GitlabPackagesDatasource.id, new GitlabPackagesDatasource());
api.set(GitlabReleasesDatasource.id, new GitlabReleasesDatasource());
Expand Down
30 changes: 30 additions & 0 deletions lib/modules/datasource/github-runners/index.spec.ts
@@ -0,0 +1,30 @@
import { getPkgReleases } from '..';
import { GithubRunnersDatasource } from '.';

describe('modules/datasource/github-runners/index', () => {
describe('getReleases', () => {
it('returns releases if package is known', async () => {
const res = await getPkgReleases({
datasource: GithubRunnersDatasource.id,
packageName: 'ubuntu',
});

expect(res).toMatchObject({
releases: [
{ version: '18.04' },
{ version: '20.04' },
{ version: '22.04' },
],
});
});

it('returns null if package is unknown', async () => {
const res = await getPkgReleases({
datasource: GithubRunnersDatasource.id,
packageName: 'unknown',
});

expect(res).toBeNull();
});
});
});
58 changes: 58 additions & 0 deletions lib/modules/datasource/github-runners/index.ts
@@ -0,0 +1,58 @@
import { id as dockerVersioningId } from '../../versioning/docker';
import { Datasource } from '../datasource';
import type { GetReleasesConfig, Release, ReleaseResult } from '../types';

export class GithubRunnersDatasource extends Datasource {
static readonly id = 'github-runners';

/**
* Only add stable runners to the datasource. See datasource readme for details.
*/
private static readonly releases: Record<string, Release[] | undefined> = {
ubuntu: [{ version: '22.04' }, { version: '20.04' }, { version: '18.04' }],
macos: [
{ version: '13' },
{ version: '13-xl' },
{ version: '12' },
{ version: '12-xl' },
{ version: '11' },
{ version: '10.15' },
],
windows: [{ version: '2022' }, { version: '2019' }],
};

public static isValidRunner(
runnerName: string,
runnerVersion: string
): boolean {
const runnerReleases = GithubRunnersDatasource.releases[runnerName];
if (!runnerReleases) {
return false;
}

const versionExists = runnerReleases.some(
({ version }) => version === runnerVersion
);

return runnerVersion === 'latest' || versionExists;
}

override readonly defaultVersioning = dockerVersioningId;

constructor() {
super(GithubRunnersDatasource.id);
}

override getReleases({
packageName,
}: GetReleasesConfig): Promise<ReleaseResult | null> {
const releases = GithubRunnersDatasource.releases[packageName];
const releaseResult: ReleaseResult | null = releases
? {
releases,
sourceUrl: 'https://github.com/actions/runner-images',
}
: null;
return Promise.resolve(releaseResult);
}
}
11 changes: 11 additions & 0 deletions lib/modules/datasource/github-runners/readme.md
@@ -0,0 +1,11 @@
This datasource returns a list of all _stable_ runners that are hosted by GitHub.
This datasource ignores beta releases.
The datasource is based on [GitHub's `runner-images` repository](https://github.com/actions/runner-images).

Examples: `windows-2019` / `ubuntu-22.04` / `macos-13`

## Maintenance

New _stable_ runner versions must be added to the datasource with a pull request.
Unstable runners are tagged as `[beta]` in the readme of the [`runner-images` repository](https://github.com/actions/runner-images).
Once a runner version becomes stable, the `[beta]` tag is removed and the suffix `latest` is added to its YAML label.
Expand Up @@ -87,6 +87,33 @@ exports[`modules/manager/github-actions/extract extractPackageFile() extracts mu
"replaceString": "actions-rs/cargo@v1.0.3",
"versioning": "docker",
},
{
"autoReplaceStringTemplate": "{{depName}}-{{newValue}}",
"currentValue": "latest",
"datasource": "github-runners",
"depName": "ubuntu",
"depType": "github-runner",
"replaceString": "ubuntu-latest",
"skipReason": "invalid-version",
},
{
"autoReplaceStringTemplate": "{{depName}}-{{newValue}}",
"currentValue": "latest",
"datasource": "github-runners",
"depName": "ubuntu",
"depType": "github-runner",
"replaceString": "ubuntu-latest",
"skipReason": "invalid-version",
},
{
"autoReplaceStringTemplate": "{{depName}}-{{newValue}}",
"currentValue": "latest",
"datasource": "github-runners",
"depName": "ubuntu",
"depType": "github-runner",
"replaceString": "ubuntu-latest",
"skipReason": "invalid-version",
},
]
`;

Expand Down Expand Up @@ -132,6 +159,42 @@ exports[`modules/manager/github-actions/extract extractPackageFile() extracts mu
"depType": "docker",
"replaceString": "node:6@sha256:7b65413af120ec5328077775022c78101f103258a1876ec2f83890bce416e896",
},
{
"autoReplaceStringTemplate": "{{depName}}-{{newValue}}",
"currentValue": "latest",
"datasource": "github-runners",
"depName": "ubuntu",
"depType": "github-runner",
"replaceString": "ubuntu-latest",
"skipReason": "invalid-version",
},
{
"autoReplaceStringTemplate": "{{depName}}-{{newValue}}",
"currentValue": "latest",
"datasource": "github-runners",
"depName": "ubuntu",
"depType": "github-runner",
"replaceString": "ubuntu-latest",
"skipReason": "invalid-version",
},
{
"autoReplaceStringTemplate": "{{depName}}-{{newValue}}",
"currentValue": "latest",
"datasource": "github-runners",
"depName": "ubuntu",
"depType": "github-runner",
"replaceString": "ubuntu-latest",
"skipReason": "invalid-version",
},
{
"autoReplaceStringTemplate": "{{depName}}-{{newValue}}",
"currentValue": "latest",
"datasource": "github-runners",
"depName": "ubuntu",
"depType": "github-runner",
"replaceString": "ubuntu-latest",
"skipReason": "invalid-version",
},
{
"autoReplaceStringTemplate": "{{depName}}{{#if newValue}}:{{newValue}}{{/if}}{{#if newDigest}}@{{newDigest}}{{/if}}",
"currentDigest": undefined,
Expand Down Expand Up @@ -159,6 +222,15 @@ exports[`modules/manager/github-actions/extract extractPackageFile() extracts mu
"depType": "service",
"replaceString": "postgres:10",
},
{
"autoReplaceStringTemplate": "{{depName}}-{{newValue}}",
"currentValue": "latest",
"datasource": "github-runners",
"depName": "ubuntu",
"depType": "github-runner",
"replaceString": "ubuntu-latest",
"skipReason": "invalid-version",
},
{
"autoReplaceStringTemplate": "{{depName}}{{#if newValue}}:{{newValue}}{{/if}}{{#if newDigest}}@{{newDigest}}{{/if}}",
"currentDigest": undefined,
Expand All @@ -168,5 +240,14 @@ exports[`modules/manager/github-actions/extract extractPackageFile() extracts mu
"depType": "container",
"replaceString": "node:16-bullseye",
},
{
"autoReplaceStringTemplate": "{{depName}}-{{newValue}}",
"currentValue": "latest",
"datasource": "github-runners",
"depName": "ubuntu",
"depType": "github-runner",
"replaceString": "ubuntu-latest",
"skipReason": "invalid-version",
},
]
`;
112 changes: 112 additions & 0 deletions lib/modules/manager/github-actions/extract.spec.ts
Expand Up @@ -2,6 +2,35 @@ import { Fixtures } from '../../../../test/fixtures';
import { GlobalConfig } from '../../../config/global';
import { extractPackageFile } from '.';

const runnerTestWorkflow = `
jobs:
test1:
runs-on: ubuntu-latest
test2:
runs-on:
ubuntu-22.04
test3:
runs-on: "macos-12-xl"
test4:
runs-on: 'macos-latest'
test5:
runs-on: |
windows-2019
test6:
runs-on: >
windows-2022
test7:
runs-on: [windows-2022, selfhosted]
test8:
runs-on: \${{ env.RUNNER }}
test9:
runs-on:
group: ubuntu-runners
labels: ubuntu-20.04-16core
test10:
runs-on: abc-123
`;

describe('modules/manager/github-actions/extract', () => {
beforeEach(() => {
GlobalConfig.reset();
Expand Down Expand Up @@ -121,6 +150,7 @@ describe('modules/manager/github-actions/extract', () => {
Fixtures.get('workflow_3.yml'),
'workflow_3.yml'
);

expect(res?.deps).toMatchObject([
{
currentValue: 'v0.13.1',
Expand Down Expand Up @@ -155,6 +185,20 @@ describe('modules/manager/github-actions/extract', () => {
replaceString: '"actions/checkout@v1.1.2"',
versioning: 'docker',
},
{
currentValue: 'latest',
datasource: 'github-runners',
depName: 'ubuntu',
depType: 'github-runner',
replaceString: 'ubuntu-latest',
},
{
currentValue: 'latest',
datasource: 'github-runners',
depName: 'ubuntu',
depType: 'github-runner',
replaceString: 'ubuntu-latest',
},
]);
});

Expand Down Expand Up @@ -342,5 +386,73 @@ describe('modules/manager/github-actions/extract', () => {
},
]);
});

it('extracts multiple action runners from yaml configuration file', () => {
const res = extractPackageFile(runnerTestWorkflow, 'workflow.yml');

expect(res?.deps).toMatchObject([
{
depName: 'ubuntu',
currentValue: 'latest',
replaceString: 'ubuntu-latest',
depType: 'github-runner',
datasource: 'github-runners',
autoReplaceStringTemplate: '{{depName}}-{{newValue}}',
skipReason: 'invalid-version',
},
{
depName: 'ubuntu',
currentValue: '22.04',
replaceString: 'ubuntu-22.04',
depType: 'github-runner',
datasource: 'github-runners',
autoReplaceStringTemplate: '{{depName}}-{{newValue}}',
},
{
depName: 'macos',
currentValue: '12-xl',
replaceString: 'macos-12-xl',
depType: 'github-runner',
datasource: 'github-runners',
autoReplaceStringTemplate: '{{depName}}-{{newValue}}',
},
{
depName: 'macos',
currentValue: 'latest',
replaceString: 'macos-latest',
depType: 'github-runner',
datasource: 'github-runners',
autoReplaceStringTemplate: '{{depName}}-{{newValue}}',
skipReason: 'invalid-version',
},
{
depName: 'windows',
currentValue: '2019',
replaceString: 'windows-2019',
depType: 'github-runner',
datasource: 'github-runners',
autoReplaceStringTemplate: '{{depName}}-{{newValue}}',
},
{
depName: 'windows',
currentValue: '2022',
replaceString: 'windows-2022',
depType: 'github-runner',
datasource: 'github-runners',
autoReplaceStringTemplate: '{{depName}}-{{newValue}}',
},
{
depName: 'windows',
currentValue: '2022',
replaceString: 'windows-2022',
depType: 'github-runner',
datasource: 'github-runners',
autoReplaceStringTemplate: '{{depName}}-{{newValue}}',
},
]);
expect(
res?.deps.filter((d) => d.datasource === 'github-runners')
).toHaveLength(7);
});
});
});

0 comments on commit 1ecaab2

Please sign in to comment.