Skip to content

Commit 57aacc3

Browse files
authored
Merge pull request #977 from crazy-max/github-split
github: move artifact and summary logic to dedicated classes
2 parents 4748d57 + e169fb3 commit 57aacc3

File tree

28 files changed

+616
-516
lines changed

28 files changed

+616
-516
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* Copyright 2026 actions-toolkit authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import {describe, expect, it} from '@jest/globals';
18+
import fs from 'fs';
19+
import os from 'os';
20+
import path from 'path';
21+
22+
import {GitHubArtifact} from '../../src/github/artifact';
23+
import {Util} from '../../src/util';
24+
25+
const fixturesDir = path.join(__dirname, '..', '.fixtures');
26+
const tmpDir = fs.mkdtempSync(path.join(process.env.TEMP || os.tmpdir(), 'github-itg-'));
27+
28+
const maybe = !process.env.GITHUB_ACTIONS || (process.env.GITHUB_ACTIONS === 'true' && process.env.ImageOS && process.env.ImageOS.startsWith('ubuntu')) ? describe : describe.skip;
29+
30+
maybe('upload', () => {
31+
it('uploads an artifact', async () => {
32+
const filename = path.join(tmpDir, `github-repo-${Util.generateRandomString()}.json`);
33+
fs.copyFileSync(path.join(fixturesDir, `github-repo.json`), filename);
34+
const res = await GitHubArtifact.upload({
35+
filename: filename,
36+
mimeType: 'application/json',
37+
retentionDays: 1
38+
});
39+
expect(res).toBeDefined();
40+
console.log('uploadArtifactResponse', res);
41+
expect(res?.url).toBeDefined();
42+
});
43+
});
Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ import * as fs from 'fs';
1919
import * as path from 'path';
2020
import * as core from '@actions/core';
2121

22-
import {GitHub} from '../src/github';
23-
import {GitHubRepo} from '../src/types/github';
22+
import {GitHub} from '../../src/github/github';
23+
import {GitHubRepo} from '../../src/types/github/github';
2424

25-
import repoFixture from './.fixtures/github-repo.json';
25+
import repoFixture from '../.fixtures/github-repo.json';
26+
27+
const fixturesDir = path.join(__dirname, '..', '.fixtures');
2628

2729
describe('repoData', () => {
2830
it('returns GitHub repo data', async () => {
@@ -49,7 +51,7 @@ describe('repoData (api)', () => {
4951
try {
5052
jest.resetModules();
5153
jest.unmock('@actions/github');
52-
const {GitHub} = await import('../src/github');
54+
const {GitHub} = await import('../../src/github/github');
5355
const github = new GitHub({token: process.env.GITHUB_TOKEN});
5456
const repo = await github.repoData();
5557
const fullName = repo.full_name ?? `${repo.owner?.login}/${repo.name}`;
@@ -172,10 +174,7 @@ describe('actionsRuntimeToken', () => {
172174
}).toThrow();
173175
});
174176
it('fixture', async () => {
175-
process.env.ACTIONS_RUNTIME_TOKEN = fs
176-
.readFileSync(path.join(__dirname, '.fixtures', 'runtimeToken.txt'))
177-
.toString()
178-
.trim();
177+
process.env.ACTIONS_RUNTIME_TOKEN = fs.readFileSync(path.join(fixturesDir, 'runtimeToken.txt')).toString().trim();
179178
const runtimeToken = GitHub.actionsRuntimeToken;
180179
expect(runtimeToken?.ac).toEqual('[{"Scope":"refs/heads/master","Permission":3}]');
181180
expect(runtimeToken?.iss).toEqual('vstoken.actions.githubusercontent.com');
@@ -203,10 +202,7 @@ describe('printActionsRuntimeTokenACs', () => {
203202
});
204203
it('refs/heads/master', async () => {
205204
const infoSpy = jest.spyOn(core, 'info');
206-
process.env.ACTIONS_RUNTIME_TOKEN = fs
207-
.readFileSync(path.join(__dirname, '.fixtures', 'runtimeToken.txt'))
208-
.toString()
209-
.trim();
205+
process.env.ACTIONS_RUNTIME_TOKEN = fs.readFileSync(path.join(fixturesDir, 'runtimeToken.txt')).toString().trim();
210206
await GitHub.printActionsRuntimeTokenACs();
211207
expect(infoSpy).toHaveBeenCalledTimes(1);
212208
expect(infoSpy).toHaveBeenCalledWith(`refs/heads/master: read/write`);
Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -19,34 +19,19 @@ import fs from 'fs';
1919
import os from 'os';
2020
import path from 'path';
2121

22-
import {Buildx} from '../src/buildx/buildx';
23-
import {Bake} from '../src/buildx/bake';
24-
import {Build} from '../src/buildx/build';
25-
import {Exec} from '../src/exec';
26-
import {GitHub} from '../src/github';
27-
import {History} from '../src/buildx/history';
28-
import {Util} from '../src/util';
22+
import {Buildx} from '../../src/buildx/buildx';
23+
import {Bake} from '../../src/buildx/bake';
24+
import {Build} from '../../src/buildx/build';
25+
import {Exec} from '../../src/exec';
26+
import {GitHubArtifact} from '../../src/github/artifact';
27+
import {GitHubSummary} from '../../src/github/summary';
28+
import {History} from '../../src/buildx/history';
2929

30-
const fixturesDir = path.join(__dirname, '.fixtures');
30+
const fixturesDir = path.join(__dirname, '..', '.fixtures');
3131
const tmpDir = fs.mkdtempSync(path.join(process.env.TEMP || os.tmpdir(), 'github-itg-'));
3232

3333
const maybe = !process.env.GITHUB_ACTIONS || (process.env.GITHUB_ACTIONS === 'true' && process.env.ImageOS && process.env.ImageOS.startsWith('ubuntu')) ? describe : describe.skip;
3434

35-
maybe('uploadArtifact', () => {
36-
it('uploads an artifact', async () => {
37-
const filename = path.join(tmpDir, `github-repo-${Util.generateRandomString()}.json`);
38-
fs.copyFileSync(path.join(fixturesDir, `github-repo.json`), filename);
39-
const res = await GitHub.uploadArtifact({
40-
filename: filename,
41-
mimeType: 'application/json',
42-
retentionDays: 1
43-
});
44-
expect(res).toBeDefined();
45-
console.log('uploadArtifactResponse', res);
46-
expect(res?.url).toBeDefined();
47-
});
48-
});
49-
5035
maybe('writeBuildSummary', () => {
5136
// prettier-ignore
5237
test.each([
@@ -98,15 +83,15 @@ maybe('writeBuildSummary', () => {
9883
expect(exportRes?.dockerbuildSize).toBeDefined();
9984
expect(exportRes?.summaries).toBeDefined();
10085

101-
const uploadRes = await GitHub.uploadArtifact({
86+
const uploadRes = await GitHubArtifact.upload({
10287
filename: exportRes?.dockerbuildFilename,
10388
mimeType: 'application/gzip',
10489
retentionDays: 1
10590
});
10691
expect(uploadRes).toBeDefined();
10792
expect(uploadRes?.url).toBeDefined();
10893

109-
await GitHub.writeBuildSummary({
94+
await GitHubSummary.writeBuildSummary({
11095
exportRes: exportRes,
11196
uploadRes: uploadRes,
11297
inputs: {
@@ -178,15 +163,15 @@ maybe('writeBuildSummary', () => {
178163
expect(exportRes?.dockerbuildSize).toBeDefined();
179164
expect(exportRes?.summaries).toBeDefined();
180165

181-
const uploadRes = await GitHub.uploadArtifact({
166+
const uploadRes = await GitHubArtifact.upload({
182167
filename: exportRes?.dockerbuildFilename,
183168
mimeType: 'application/gzip',
184169
retentionDays: 1
185170
});
186171
expect(uploadRes).toBeDefined();
187172
expect(uploadRes?.url).toBeDefined();
188173

189-
await GitHub.writeBuildSummary({
174+
await GitHubSummary.writeBuildSummary({
190175
exportRes: exportRes,
191176
uploadRes: uploadRes,
192177
inputs: {
@@ -233,15 +218,15 @@ maybe('writeBuildSummary', () => {
233218
expect(exportRes?.dockerbuildSize).toBeDefined();
234219
expect(exportRes?.summaries).toBeDefined();
235220

236-
const uploadRes = await GitHub.uploadArtifact({
221+
const uploadRes = await GitHubArtifact.upload({
237222
filename: exportRes?.dockerbuildFilename,
238223
mimeType: 'application/gzip',
239224
retentionDays: 1
240225
});
241226
expect(uploadRes).toBeDefined();
242227
expect(uploadRes?.url).toBeDefined();
243228

244-
await GitHub.writeBuildSummary({
229+
await GitHubSummary.writeBuildSummary({
245230
exportRes: exportRes,
246231
uploadRes: uploadRes,
247232
inputs: {
@@ -288,7 +273,7 @@ maybe('writeBuildSummary', () => {
288273
expect(exportRes?.dockerbuildSize).toBeDefined();
289274
expect(exportRes?.summaries).toBeDefined();
290275

291-
await GitHub.writeBuildSummary({
276+
await GitHubSummary.writeBuildSummary({
292277
exportRes: exportRes,
293278
inputs: {
294279
context: fixturesDir,

src/buildx/build.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {parse} from 'csv-parse/sync';
2121

2222
import {Buildx} from './buildx.js';
2323
import {Context} from '../context.js';
24-
import {GitHub} from '../github.js';
24+
import {GitHub} from '../github/github.js';
2525
import {Util} from '../util.js';
2626

2727
import {BuildMetadata} from '../types/buildx/build.js';

src/buildx/buildx.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ import * as semver from 'semver';
2121

2222
import {Git} from '../buildkit/git.js';
2323
import {Docker} from '../docker/docker.js';
24-
import {GitHub} from '../github.js';
24+
import {GitHub} from '../github/github.js';
2525
import {Exec} from '../exec.js';
2626
import {Util} from '../util.js';
2727

2828
import {VertexWarning} from '../types/buildkit/client.js';
2929
import {GitURL} from '../types/buildkit/git.js';
3030
import {Cert, LocalRefsOpts, LocalRefsResponse, LocalState} from '../types/buildx/buildx.js';
31-
import {GitHubAnnotation} from '../types/github.js';
31+
import {GitHubAnnotation} from '../types/github/github.js';
3232

3333
export interface BuildxOpts {
3434
standalone?: boolean;

src/buildx/history.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import {Buildx} from './buildx.js';
2525
import {Context} from '../context.js';
2626
import {Docker} from '../docker/docker.js';
2727
import {Exec} from '../exec.js';
28-
import {GitHub} from '../github.js';
28+
import {GitHub} from '../github/github.js';
2929
import {Util} from '../util.js';
3030

3131
import {ExportOpts, ExportResponse, InspectOpts, InspectResponse, Summaries} from '../types/buildx/history.js';

src/buildx/install.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ import {Context} from '../context.js';
2929
import {Exec} from '../exec.js';
3030
import {Docker} from '../docker/docker.js';
3131
import {Git} from '../git.js';
32-
import {GitHub} from '../github.js';
32+
import {GitHub} from '../github/github.js';
3333
import {Sigstore} from '../sigstore/sigstore.js';
3434
import {Util} from '../util.js';
3535

3636
import {DownloadVersion} from '../types/buildx/buildx.js';
37-
import {GitHubRelease} from '../types/github.js';
37+
import {GitHubRelease} from '../types/github/github.js';
3838
import {SEARCH_URL} from '../types/sigstore/sigstore.js';
3939

4040
export interface DownloadOpts {

src/compose/install.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ import * as util from 'util';
2525
import {Cache} from '../cache.js';
2626
import {Context} from '../context.js';
2727
import {Docker} from '../docker/docker.js';
28-
import {GitHub} from '../github.js';
28+
import {GitHub} from '../github/github.js';
2929

3030
import {DownloadVersion} from '../types/compose/compose.js';
31-
import {GitHubRelease} from '../types/github.js';
31+
import {GitHubRelease} from '../types/github/github.js';
3232

3333
export interface InstallOpts {
3434
standalone?: boolean;

src/context.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import path from 'path';
2020
import * as tmp from 'tmp';
2121
import * as github from '@actions/github';
2222

23-
import {GitHub} from './github.js';
23+
import {GitHub} from './github/github.js';
2424

2525
export class Context {
2626
private static readonly _tmpDir = fs.mkdtempSync(path.join(Context.ensureDirExists(process.env.RUNNER_TEMP || os.tmpdir()), 'docker-actions-toolkit-'));

src/cosign/install.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ import {Cache} from '../cache.js';
2727
import {Context} from '../context.js';
2828
import {Exec} from '../exec.js';
2929
import {Git} from '../git.js';
30-
import {GitHub} from '../github.js';
30+
import {GitHub} from '../github/github.js';
3131
import {Sigstore} from '../sigstore/sigstore.js';
3232
import {Util} from '../util.js';
3333

3434
import {DownloadVersion} from '../types/cosign/cosign.js';
35-
import {GitHubRelease} from '../types/github.js';
35+
import {GitHubRelease} from '../types/github/github.js';
3636
import {dockerfileContent} from './dockerfile.js';
3737
import {SEARCH_URL} from '../types/sigstore/sigstore.js';
3838

0 commit comments

Comments
 (0)