move runtime-basedir default to context

Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax 2025-08-06 21:35:02 +02:00
parent de8d0f39ec
commit d2d8fc9bf5
No known key found for this signature in database
GPG Key ID: ADE44D8C9D44FBE4
3 changed files with 23 additions and 11 deletions

View File

@ -1,4 +1,6 @@
import {beforeEach, describe, expect, test} from '@jest/globals'; import {beforeEach, describe, expect, test} from '@jest/globals';
import * as os from 'os';
import * as path from 'path';
import * as context from '../src/context'; import * as context from '../src/context';
@ -30,7 +32,8 @@ describe('getInputs', () => {
context: '', context: '',
daemonConfig: '', daemonConfig: '',
rootless: false, rootless: false,
setHost: false setHost: false,
runtimeBasedir: path.join(os.homedir(), `setup-docker-action`),
} as context.Inputs } as context.Inputs
], ],
[ [
@ -52,7 +55,8 @@ describe('getInputs', () => {
context: 'foo', context: 'foo',
daemonConfig: `{"debug":true,"features":{"containerd-snapshotter":true}}`, daemonConfig: `{"debug":true,"features":{"containerd-snapshotter":true}}`,
rootless: false, rootless: false,
setHost: false setHost: false,
runtimeBasedir: path.join(os.homedir(), `setup-docker-action`),
} as context.Inputs } as context.Inputs
], ],
[ [
@ -70,7 +74,8 @@ describe('getInputs', () => {
context: '', context: '',
daemonConfig: '', daemonConfig: '',
rootless: false, rootless: false,
setHost: true setHost: true,
runtimeBasedir: path.join(os.homedir(), `setup-docker-action`),
} as context.Inputs } as context.Inputs
], ],
[ [
@ -90,7 +95,8 @@ describe('getInputs', () => {
context: 'foo', context: 'foo',
daemonConfig: `{"debug":true,"features":{"containerd-snapshotter":true}}`, daemonConfig: `{"debug":true,"features":{"containerd-snapshotter":true}}`,
rootless: false, rootless: false,
setHost: false setHost: false,
runtimeBasedir: path.join(os.homedir(), `setup-docker-action`),
} as context.Inputs } as context.Inputs
], ],
[ [
@ -108,7 +114,8 @@ describe('getInputs', () => {
context: '', context: '',
daemonConfig: '', daemonConfig: '',
rootless: false, rootless: false,
setHost: false setHost: false,
runtimeBasedir: path.join(os.homedir(), `setup-docker-action`),
} as context.Inputs } as context.Inputs
], ],
[ [
@ -128,6 +135,7 @@ describe('getInputs', () => {
context: '', context: '',
daemonConfig: '', daemonConfig: '',
rootless: false, rootless: false,
runtimeBasedir: path.join(os.homedir(), `setup-docker-action`),
} as context.Inputs } as context.Inputs
], ],
[ [
@ -147,6 +155,7 @@ describe('getInputs', () => {
context: '', context: '',
daemonConfig: '', daemonConfig: '',
rootless: false, rootless: false,
runtimeBasedir: path.join(os.homedir(), `setup-docker-action`),
} as context.Inputs } as context.Inputs
], ],
[ [
@ -165,6 +174,7 @@ describe('getInputs', () => {
context: '', context: '',
daemonConfig: '', daemonConfig: '',
rootless: false, rootless: false,
runtimeBasedir: path.join(os.homedir(), `setup-docker-action`),
} as context.Inputs } as context.Inputs
], ],
[ [
@ -183,6 +193,7 @@ describe('getInputs', () => {
context: '', context: '',
daemonConfig: '', daemonConfig: '',
rootless: true, rootless: true,
runtimeBasedir: path.join(os.homedir(), `setup-docker-action`),
} as context.Inputs } as context.Inputs
], ],
[ [
@ -203,7 +214,8 @@ describe('getInputs', () => {
daemonConfig: '', daemonConfig: '',
tcpPort: 2378, tcpPort: 2378,
rootless: false, rootless: false,
setHost: false setHost: false,
runtimeBasedir: path.join(os.homedir(), `setup-docker-action`),
} as context.Inputs } as context.Inputs
], ],
])( ])(

View File

@ -1,3 +1,5 @@
import os from 'os';
import path from 'path';
import * as core from '@actions/core'; import * as core from '@actions/core';
import {parse} from 'csv-parse/sync'; import {parse} from 'csv-parse/sync';
@ -11,7 +13,7 @@ export interface Inputs {
context: string; context: string;
setHost: boolean; setHost: boolean;
rootless: boolean; rootless: boolean;
runtimeBasedir?: string; runtimeBasedir: string;
} }
export function getInputs(): Inputs { export function getInputs(): Inputs {
@ -29,7 +31,7 @@ export function getInputs(): Inputs {
context: core.getInput('context'), context: core.getInput('context'),
setHost: core.getBooleanInput('set-host'), setHost: core.getBooleanInput('set-host'),
rootless: core.getBooleanInput('rootless'), rootless: core.getBooleanInput('rootless'),
runtimeBasedir: core.getInput('runtime-basedir') runtimeBasedir: core.getInput('runtime-basedir') || path.join(os.homedir(), `setup-docker-action`)
}; };
} }

View File

@ -1,5 +1,4 @@
import * as crypto from 'crypto'; import * as crypto from 'crypto';
import os from 'os';
import path from 'path'; import path from 'path';
import * as core from '@actions/core'; import * as core from '@actions/core';
import * as actionsToolkit from '@docker/actions-toolkit'; import * as actionsToolkit from '@docker/actions-toolkit';
@ -18,8 +17,7 @@ actionsToolkit.run(
// main // main
async () => { async () => {
const input: context.Inputs = context.getInputs(); const input: context.Inputs = context.getInputs();
const runBasedir = input.runtimeBasedir || path.join(os.homedir(), `setup-docker-action`); const runDir = path.join(input.runtimeBasedir, `run-${crypto.randomUUID().slice(0, 8)}`);
const runDir = path.join(runBasedir, `run-${crypto.randomUUID().slice(0, 8)}`);
if (input.context == 'default') { if (input.context == 'default') {
throw new Error(`'default' context cannot be used.`); throw new Error(`'default' context cannot be used.`);