Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
17 changes: 14 additions & 3 deletions src/types/git.ts → __tests__/.helpers/os.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2023 actions-toolkit authors
* Copyright 2025 actions-toolkit authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,6 +14,17 @@
* limitations under the License.
*/

import {Context as GitHubContext} from '@actions/github/lib/context';
import {jest} from '@jest/globals';
import os from 'os';

export type Context = GitHubContext;
export const mockPlatform = (platform: NodeJS.Platform) => {
return jest.spyOn(os, 'platform').mockImplementation(() => platform);
};

export const mockArch = (arch: string) => {
return jest.spyOn(os, 'arch').mockImplementation(() => arch);
};

export const mockHomedir = (dir: string) => {
return jest.spyOn(os, 'homedir').mockImplementation(() => dir);
};
9 changes: 5 additions & 4 deletions __tests__/buildx/install.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
* limitations under the License.
*/

import {describe, expect, it, jest, test, afterEach} from '@jest/globals';
import {describe, expect, it, test, afterEach} from '@jest/globals';
import fs from 'fs';
import os from 'os';
import path from 'path';
import * as rimraf from 'rimraf';
import osm = require('os');

import {mockArch, mockPlatform} from '../.helpers/os';

import {Install} from '../../src/buildx/install';

Expand Down Expand Up @@ -85,8 +86,8 @@ describe('download', () => {
['linux', 's390x'],
])(
'acquires buildx for %s/%s', async (os, arch) => {
jest.spyOn(osm, 'platform').mockImplementation(() => os as NodeJS.Platform);
jest.spyOn(osm, 'arch').mockImplementation(() => arch);
mockPlatform(os as NodeJS.Platform);
mockArch(arch);
const install = new Install();
const buildxBin = await install.download('latest');
expect(fs.existsSync(buildxBin)).toBe(true);
Expand Down
9 changes: 5 additions & 4 deletions __tests__/compose/install.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
* limitations under the License.
*/

import {describe, expect, it, jest, test, afterEach} from '@jest/globals';
import {describe, expect, it, test, afterEach} from '@jest/globals';
import fs from 'fs';
import os from 'os';
import path from 'path';
import * as rimraf from 'rimraf';
import osm = require('os');

import {mockArch, mockPlatform} from '../.helpers/os';

import {Install} from '../../src/compose/install';

Expand Down Expand Up @@ -85,8 +86,8 @@ describe('download', () => {
['linux', 's390x'],
])(
'acquires compose for %s/%s', async (os, arch) => {
jest.spyOn(osm, 'platform').mockImplementation(() => os as NodeJS.Platform);
jest.spyOn(osm, 'arch').mockImplementation(() => arch);
mockPlatform(os as NodeJS.Platform);
mockArch(arch);
const install = new Install();
const composeBin = await install.download('latest');
expect(fs.existsSync(composeBin)).toBe(true);
Expand Down
9 changes: 5 additions & 4 deletions __tests__/cosign/install.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
* limitations under the License.
*/

import {describe, expect, it, jest, test, afterEach} from '@jest/globals';
import {describe, expect, it, test, afterEach} from '@jest/globals';
import fs from 'fs';
import os from 'os';
import path from 'path';
import * as rimraf from 'rimraf';
import osm = require('os');

import {mockArch, mockPlatform} from '../.helpers/os';

import {Install} from '../../src/cosign/install';

Expand Down Expand Up @@ -80,8 +81,8 @@ describe('download', () => {
['linux', 'arm64']
])(
'acquires undock for %s/%s', async (os, arch) => {
jest.spyOn(osm, 'platform').mockImplementation(() => os as NodeJS.Platform);
jest.spyOn(osm, 'arch').mockImplementation(() => arch);
mockPlatform(os as NodeJS.Platform);
mockArch(arch);
const install = new Install();
const cosignBin = await install.download({
version: 'latest'
Expand Down
5 changes: 3 additions & 2 deletions __tests__/docker/docker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ import fs from 'fs';
import os from 'os';
import path from 'path';
import * as io from '@actions/io';
import osm = require('os');
import * as rimraf from 'rimraf';

import {mockHomedir} from '../.helpers/os';

import {Docker} from '../../src/docker/docker';

import {ConfigFile} from '../../src/types/docker/docker';
Expand All @@ -47,7 +48,7 @@ describe('configDir', () => {
});
it('returns default', async () => {
process.env.DOCKER_CONFIG = '';
jest.spyOn(osm, 'homedir').mockImplementation(() => path.join('/tmp', 'home'));
mockHomedir(path.join('/tmp', 'home'));
expect(Docker.configDir).toEqual(path.join('/tmp', 'home', '.docker'));
});
it('returns from env', async () => {
Expand Down
7 changes: 4 additions & 3 deletions __tests__/docker/install.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import fs from 'fs';
import os from 'os';
import path from 'path';
import * as rimraf from 'rimraf';
import osm = require('os');

import {mockArch, mockPlatform} from '../.helpers/os';

import {Install, InstallSourceArchive, InstallSourceImage} from '../../src/docker/install';

Expand Down Expand Up @@ -60,8 +61,8 @@ describe('download', () => {
[image('27.3.1'), 'win32'],
])(
'acquires %p of docker (%s)', async (source, platformOS) => {
jest.spyOn(osm, 'platform').mockImplementation(() => platformOS as NodeJS.Platform);
jest.spyOn(osm, 'arch').mockImplementation(() => 'x64');
mockPlatform(platformOS as NodeJS.Platform);
mockArch('x64');
const install = new Install({
source: source,
runDir: tmpDir
Expand Down
9 changes: 5 additions & 4 deletions __tests__/oci/oci.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
* limitations under the License.
*/

import {afterEach, describe, expect, jest, test} from '@jest/globals';
import {afterEach, describe, expect, test} from '@jest/globals';
import fs from 'fs';
import os from 'os';
import path from 'path';
import * as rimraf from 'rimraf';
import osm = require('os');

import {mockArch, mockPlatform} from '../.helpers/os';

import {OCI} from '../../src/oci/oci';

Expand All @@ -44,8 +45,8 @@ describe('defaultPlatform', () => {
['linux', 'ppc64', {architecture: 'ppc64le', os: 'linux'}],
['linux', 's390x', {architecture: 's390x', os: 'linux'}]
])('default platform for %s/%s', async (os: string, arch: string, expected: Platform) => {
jest.spyOn(osm, 'platform').mockImplementation(() => os as NodeJS.Platform);
jest.spyOn(osm, 'arch').mockImplementation(() => arch);
mockPlatform(os as NodeJS.Platform);
mockArch(arch);
const res = OCI.defaultPlatform();
expect(res).toEqual(expected);
});
Expand Down
9 changes: 5 additions & 4 deletions __tests__/regclient/install.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
* limitations under the License.
*/

import {describe, expect, it, jest, test, afterEach} from '@jest/globals';
import {describe, expect, it, test, afterEach} from '@jest/globals';
import fs from 'fs';
import os from 'os';
import path from 'path';
import * as rimraf from 'rimraf';
import osm = require('os');

import {mockArch, mockPlatform} from '../.helpers/os';

import {Install} from '../../src/regclient/install';

Expand Down Expand Up @@ -75,8 +76,8 @@ describe('download', () => {
['linux', 's390x'],
])(
'acquires regclient for %s/%s', async (os, arch) => {
jest.spyOn(osm, 'platform').mockImplementation(() => os as NodeJS.Platform);
jest.spyOn(osm, 'arch').mockImplementation(() => arch);
mockPlatform(os as NodeJS.Platform);
mockArch(arch);
const install = new Install();
const regclientBin = await install.download('latest');
expect(fs.existsSync(regclientBin)).toBe(true);
Expand Down
File renamed without changes.
9 changes: 5 additions & 4 deletions __tests__/undock/install.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
* limitations under the License.
*/

import {describe, expect, it, jest, test, afterEach} from '@jest/globals';
import {describe, expect, it, test, afterEach} from '@jest/globals';
import fs from 'fs';
import os from 'os';
import path from 'path';
import * as rimraf from 'rimraf';
import osm = require('os');

import {mockArch, mockPlatform} from '../.helpers/os';

import {Install} from '../../src/undock/install';

Expand Down Expand Up @@ -80,8 +81,8 @@ describe('download', () => {
['linux', 's390x'],
])(
'acquires undock for %s/%s', async (os, arch) => {
jest.spyOn(osm, 'platform').mockImplementation(() => os as NodeJS.Platform);
jest.spyOn(osm, 'arch').mockImplementation(() => arch);
mockPlatform(os as NodeJS.Platform);
mockArch(arch);
const install = new Install();
const undockBin = await install.download('latest');
expect(fs.existsSync(undockBin)).toBe(true);
Expand Down
4 changes: 2 additions & 2 deletions eslint.config.js → eslint.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ module.exports = defineConfig([
},
parser: tsParser,
ecmaVersion: 2023,
sourceType: 'commonjs'
sourceType: 'module'
},

rules: {
Expand All @@ -75,7 +75,7 @@ module.exports = defineConfig([
'import/no-unresolved': [
'error',
{
ignore: ['csv-parse/sync', '@octokit/openapi-types']
ignore: ['\\.js$', 'csv-parse/sync', '@octokit/openapi-types', '@octokit/core', '@octokit/plugin-rest-endpoint-methods']
}
],
'jest/no-disabled-tests': 0
Expand Down
13 changes: 10 additions & 3 deletions jest.config.js → jest.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,20 @@ module.exports = {
setupFiles: ['dotenv/config'],
testMatch: ['**/*.test.ts'],
transform: {
'^.+\\.ts$': 'ts-jest'
'^.+\\.ts$': [
'ts-jest',
{
useESM: true,
tsconfig: '<rootDir>/tsconfig.test.json'
}
]
},
moduleNameMapper: {
'^csv-parse/sync': '<rootDir>/node_modules/csv-parse/dist/cjs/sync.cjs'
'^(\\.{1,2}/.*)\\.js$': '$1'
},
extensionsToTreatAsEsm: ['.ts'],
collectCoverageFrom: ['src/**/{!(index.ts),}.ts'],
coveragePathIgnorePatterns: ['lib/', 'node_modules/', '__mocks__/', '__tests__/'],
testResultsProcessor: '<rootDir>/__tests__/testResultsProcessor.js',
testResultsProcessor: '<rootDir>/__tests__/testResultsProcessor.cjs',
verbose: true
};
13 changes: 10 additions & 3 deletions jest.config.itg.js → jest.config.itg.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,18 @@ module.exports = {
testMatch: ['**/*.test.itg.ts'],
testTimeout: 1800000, // 30 minutes
transform: {
'^.+\\.ts$': 'ts-jest'
'^.+\\.ts$': [
'ts-jest',
{
useESM: true,
tsconfig: '<rootDir>/tsconfig.test.json'
}
]
},
moduleNameMapper: {
'^csv-parse/sync': '<rootDir>/node_modules/csv-parse/dist/cjs/sync.cjs'
'^(\\.{1,2}/.*)\\.js$': '$1'
},
testResultsProcessor: '<rootDir>/__tests__/testResultsProcessor.js',
extensionsToTreatAsEsm: ['.ts'],
testResultsProcessor: '<rootDir>/__tests__/testResultsProcessor.cjs',
verbose: false
};
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "@docker/actions-toolkit",
"version": "0.0.0+unknown",
"description": "Toolkit for Docker (GitHub) Actions",
"type": "module",
"scripts": {
"build": "tsc",
"lint": "yarn run prettier && yarn run eslint",
Expand All @@ -12,9 +13,9 @@
"prettier:fix": "prettier --write \"./**/*.ts\"",
"test": "jest",
"test:coverage": "jest --coverage",
"test:itg": "jest -c jest.config.itg.js --runInBand",
"test:itg-list": "jest -c jest.config.itg.js --listTests",
"test:itg-coverage": "jest -c jest.config.itg.js --coverage --runInBand"
"test:itg": "jest -c jest.config.itg.cjs --runInBand",
"test:itg-list": "jest -c jest.config.itg.cjs --listTests",
"test:itg-coverage": "jest -c jest.config.itg.cjs --coverage --runInBand"
},
"repository": {
"type": "git",
Expand Down
10 changes: 5 additions & 5 deletions src/buildkit/buildkit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
import * as core from '@actions/core';
import * as semver from 'semver';

import {Buildx} from '../buildx/buildx';
import {Builder} from '../buildx/builder';
import {Docker} from '../docker/docker';
import {Config} from './config';
import {Buildx} from '../buildx/buildx.js';
import {Builder} from '../buildx/builder.js';
import {Docker} from '../docker/docker.js';
import {Config} from './config.js';

import {BuilderInfo, NodeInfo} from '../types/buildx/builder';
import {BuilderInfo, NodeInfo} from '../types/buildx/builder.js';

export interface BuildKitOpts {
buildx?: Buildx;
Expand Down
2 changes: 1 addition & 1 deletion src/buildkit/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import fs from 'fs';

import {Context} from '../context';
import {Context} from '../context.js';

export class Config {
public resolveFromString(s: string): string {
Expand Down
2 changes: 1 addition & 1 deletion src/buildkit/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import {GitRef, GitURL, GitURLFragment, URLUserInfo} from '../types/buildkit/git';
import {GitRef, GitURL, GitURLFragment, URLUserInfo} from '../types/buildkit/git.js';

export class Git {
private static protoRegexp = new RegExp('^[a-zA-Z0-9]+://');
Expand Down
14 changes: 7 additions & 7 deletions src/buildx/bake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ import fs from 'fs';
import path from 'path';
import {parse} from 'csv-parse/sync';

import {Buildx} from './buildx';
import {Context} from '../context';
import {Exec} from '../exec';
import {Util} from '../util';
import {Buildx} from './buildx.js';
import {Context} from '../context.js';
import {Exec} from '../exec.js';
import {Util} from '../util.js';

import {ExecOptions} from '@actions/exec';
import {AttestEntry, BakeDefinition, CacheEntry, ExportEntry, SecretEntry, SSHEntry} from '../types/buildx/bake';
import {BuildMetadata} from '../types/buildx/build';
import {VertexWarning} from '../types/buildkit/client';
import {AttestEntry, BakeDefinition, CacheEntry, ExportEntry, SecretEntry, SSHEntry} from '../types/buildx/bake.js';
import {BuildMetadata} from '../types/buildx/build.js';
import {VertexWarning} from '../types/buildkit/client.js';

export interface BakeOpts {
buildx?: Buildx;
Expand Down
16 changes: 8 additions & 8 deletions src/buildx/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ import path from 'path';
import * as core from '@actions/core';
import {parse} from 'csv-parse/sync';

import {Buildx} from './buildx';
import {Context} from '../context';
import {GitHub} from '../github';
import {Util} from '../util';

import {BuildMetadata} from '../types/buildx/build';
import {VertexWarning} from '../types/buildkit/client';
import {ProvenancePredicate} from '../types/intoto/slsa_provenance/v0.2/provenance';
import {Buildx} from './buildx.js';
import {Context} from '../context.js';
import {GitHub} from '../github.js';
import {Util} from '../util.js';

import {BuildMetadata} from '../types/buildx/build.js';
import {VertexWarning} from '../types/buildkit/client.js';
import {ProvenancePredicate} from '../types/intoto/slsa_provenance/v0.2/provenance.js';

export interface BuildOpts {
buildx?: Buildx;
Expand Down
Loading
Loading