Skip to content

Commit d2d8fc9

Browse files
committed
move runtime-basedir default to context
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
1 parent de8d0f3 commit d2d8fc9

3 files changed

Lines changed: 23 additions & 11 deletions

File tree

__tests__/context.test.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import {beforeEach, describe, expect, test} from '@jest/globals';
2+
import * as os from 'os';
3+
import * as path from 'path';
24

35
import * as context from '../src/context';
46

@@ -30,7 +32,8 @@ describe('getInputs', () => {
3032
context: '',
3133
daemonConfig: '',
3234
rootless: false,
33-
setHost: false
35+
setHost: false,
36+
runtimeBasedir: path.join(os.homedir(), `setup-docker-action`),
3437
} as context.Inputs
3538
],
3639
[
@@ -52,7 +55,8 @@ describe('getInputs', () => {
5255
context: 'foo',
5356
daemonConfig: `{"debug":true,"features":{"containerd-snapshotter":true}}`,
5457
rootless: false,
55-
setHost: false
58+
setHost: false,
59+
runtimeBasedir: path.join(os.homedir(), `setup-docker-action`),
5660
} as context.Inputs
5761
],
5862
[
@@ -70,7 +74,8 @@ describe('getInputs', () => {
7074
context: '',
7175
daemonConfig: '',
7276
rootless: false,
73-
setHost: true
77+
setHost: true,
78+
runtimeBasedir: path.join(os.homedir(), `setup-docker-action`),
7479
} as context.Inputs
7580
],
7681
[
@@ -90,7 +95,8 @@ describe('getInputs', () => {
9095
context: 'foo',
9196
daemonConfig: `{"debug":true,"features":{"containerd-snapshotter":true}}`,
9297
rootless: false,
93-
setHost: false
98+
setHost: false,
99+
runtimeBasedir: path.join(os.homedir(), `setup-docker-action`),
94100
} as context.Inputs
95101
],
96102
[
@@ -108,7 +114,8 @@ describe('getInputs', () => {
108114
context: '',
109115
daemonConfig: '',
110116
rootless: false,
111-
setHost: false
117+
setHost: false,
118+
runtimeBasedir: path.join(os.homedir(), `setup-docker-action`),
112119
} as context.Inputs
113120
],
114121
[
@@ -128,6 +135,7 @@ describe('getInputs', () => {
128135
context: '',
129136
daemonConfig: '',
130137
rootless: false,
138+
runtimeBasedir: path.join(os.homedir(), `setup-docker-action`),
131139
} as context.Inputs
132140
],
133141
[
@@ -147,6 +155,7 @@ describe('getInputs', () => {
147155
context: '',
148156
daemonConfig: '',
149157
rootless: false,
158+
runtimeBasedir: path.join(os.homedir(), `setup-docker-action`),
150159
} as context.Inputs
151160
],
152161
[
@@ -165,6 +174,7 @@ describe('getInputs', () => {
165174
context: '',
166175
daemonConfig: '',
167176
rootless: false,
177+
runtimeBasedir: path.join(os.homedir(), `setup-docker-action`),
168178
} as context.Inputs
169179
],
170180
[
@@ -183,6 +193,7 @@ describe('getInputs', () => {
183193
context: '',
184194
daemonConfig: '',
185195
rootless: true,
196+
runtimeBasedir: path.join(os.homedir(), `setup-docker-action`),
186197
} as context.Inputs
187198
],
188199
[
@@ -203,7 +214,8 @@ describe('getInputs', () => {
203214
daemonConfig: '',
204215
tcpPort: 2378,
205216
rootless: false,
206-
setHost: false
217+
setHost: false,
218+
runtimeBasedir: path.join(os.homedir(), `setup-docker-action`),
207219
} as context.Inputs
208220
],
209221
])(

src/context.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import os from 'os';
2+
import path from 'path';
13
import * as core from '@actions/core';
24
import {parse} from 'csv-parse/sync';
35

@@ -11,7 +13,7 @@ export interface Inputs {
1113
context: string;
1214
setHost: boolean;
1315
rootless: boolean;
14-
runtimeBasedir?: string;
16+
runtimeBasedir: string;
1517
}
1618

1719
export function getInputs(): Inputs {
@@ -29,7 +31,7 @@ export function getInputs(): Inputs {
2931
context: core.getInput('context'),
3032
setHost: core.getBooleanInput('set-host'),
3133
rootless: core.getBooleanInput('rootless'),
32-
runtimeBasedir: core.getInput('runtime-basedir')
34+
runtimeBasedir: core.getInput('runtime-basedir') || path.join(os.homedir(), `setup-docker-action`)
3335
};
3436
}
3537

src/main.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import * as crypto from 'crypto';
2-
import os from 'os';
32
import path from 'path';
43
import * as core from '@actions/core';
54
import * as actionsToolkit from '@docker/actions-toolkit';
@@ -18,8 +17,7 @@ actionsToolkit.run(
1817
// main
1918
async () => {
2019
const input: context.Inputs = context.getInputs();
21-
const runBasedir = input.runtimeBasedir || path.join(os.homedir(), `setup-docker-action`);
22-
const runDir = path.join(runBasedir, `run-${crypto.randomUUID().slice(0, 8)}`);
20+
const runDir = path.join(input.runtimeBasedir, `run-${crypto.randomUUID().slice(0, 8)}`);
2321

2422
if (input.context == 'default') {
2523
throw new Error(`'default' context cannot be used.`);

0 commit comments

Comments
 (0)