From b193ec6e9edd3809fdd287ae43df23ef7459e561 Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Wed, 1 Feb 2023 14:29:53 +0100 Subject: [PATCH] common base tmpDir for tests Signed-off-by: CrazyMax --- __tests__/buildkit/config.test.ts | 3 ++- __tests__/buildx/buildx.test.ts | 3 ++- __tests__/buildx/inputs.test.ts | 3 ++- __tests__/buildx/install.test.ts | 10 ++++++++-- __tests__/context.test.ts | 3 ++- jest.config.ts | 7 +++++-- src/buildx/install.ts | 8 ++++---- 7 files changed, 25 insertions(+), 12 deletions(-) diff --git a/__tests__/buildkit/config.test.ts b/__tests__/buildkit/config.test.ts index 8e3d30c..7a90ec9 100644 --- a/__tests__/buildkit/config.test.ts +++ b/__tests__/buildkit/config.test.ts @@ -23,7 +23,8 @@ import {BuildKit} from '../../src/buildkit/buildkit'; import {Context} from '../../src/context'; const fixturesDir = path.join(__dirname, '..', 'fixtures'); -const tmpDir = path.join('/tmp/.docker-actions-toolkit-jest').split(path.sep).join(path.posix.sep); +// prettier-ignore +const tmpDir = path.join(process.env.TEMP || '/tmp', 'buildkit-config-jest').split(path.sep).join(path.posix.sep); const tmpName = path.join(tmpDir, '.tmpname-jest').split(path.sep).join(path.posix.sep); jest.spyOn(Context.prototype, 'tmpDir').mockImplementation((): string => { diff --git a/__tests__/buildx/buildx.test.ts b/__tests__/buildx/buildx.test.ts index cf07892..c3abad0 100644 --- a/__tests__/buildx/buildx.test.ts +++ b/__tests__/buildx/buildx.test.ts @@ -24,7 +24,8 @@ import * as exec from '@actions/exec'; import {Buildx} from '../../src/buildx/buildx'; import {Context} from '../../src/context'; -const tmpDir = path.join('/tmp/.docker-actions-toolkit-jest').split(path.sep).join(path.posix.sep); +// prettier-ignore +const tmpDir = path.join(process.env.TEMP || '/tmp', 'buildx-jest').split(path.sep).join(path.posix.sep); const tmpName = path.join(tmpDir, '.tmpname-jest').split(path.sep).join(path.posix.sep); jest.spyOn(Context.prototype, 'tmpDir').mockImplementation((): string => { diff --git a/__tests__/buildx/inputs.test.ts b/__tests__/buildx/inputs.test.ts index 72cf40a..15b15fc 100644 --- a/__tests__/buildx/inputs.test.ts +++ b/__tests__/buildx/inputs.test.ts @@ -24,7 +24,8 @@ import {Buildx} from '../../src/buildx/buildx'; import {Inputs} from '../../src/buildx/inputs'; const fixturesDir = path.join(__dirname, '..', 'fixtures'); -const tmpDir = path.join('/tmp/.docker-actions-toolkit-jest').split(path.sep).join(path.posix.sep); +// prettier-ignore +const tmpDir = path.join(process.env.TEMP || '/tmp', 'buildx-inputs-jest').split(path.sep).join(path.posix.sep); const tmpName = path.join(tmpDir, '.tmpname-jest').split(path.sep).join(path.posix.sep); const metadata = `{ "containerimage.config.digest": "sha256:059b68a595b22564a1cbc167af369349fdc2ecc1f7bc092c2235cbf601a795fd", diff --git a/__tests__/buildx/install.test.ts b/__tests__/buildx/install.test.ts index 1e996b4..ce92742 100644 --- a/__tests__/buildx/install.test.ts +++ b/__tests__/buildx/install.test.ts @@ -16,7 +16,6 @@ import {describe, expect, it, jest, test, beforeEach} from '@jest/globals'; import * as fs from 'fs'; -import os from 'os'; import * as path from 'path'; import osm = require('os'); @@ -27,7 +26,8 @@ beforeEach(() => { }); describe('install', () => { - const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'actions-toolkit-')); + // prettier-ignore + const tmpDir = path.join(process.env.TEMP || '/tmp', 'buildx-install-jest').split(path.sep).join(path.posix.sep); // prettier-ignore test.each([ @@ -65,6 +65,12 @@ describe('install', () => { }, 100000 ); + + it('returns latest buildx GitHub release', async () => { + const release = await Install.getRelease('latest'); + expect(release).not.toBeNull(); + expect(release?.tag_name).not.toEqual(''); + }); }); describe('getRelease', () => { diff --git a/__tests__/context.test.ts b/__tests__/context.test.ts index 32339c2..8da6469 100644 --- a/__tests__/context.test.ts +++ b/__tests__/context.test.ts @@ -21,7 +21,8 @@ import {describe, expect, jest, it, beforeEach, afterEach} from '@jest/globals'; import {Context} from '../src/context'; -const tmpDir = path.join('/tmp/.docker-actions-toolkit-jest').split(path.sep).join(path.posix.sep); +// prettier-ignore +const tmpDir = path.join(process.env.TEMP || '/tmp', 'context-jest').split(path.sep).join(path.posix.sep); const tmpName = path.join(tmpDir, '.tmpname-jest').split(path.sep).join(path.posix.sep); jest.spyOn(Context.prototype, 'tmpDir').mockImplementation((): string => { diff --git a/jest.config.ts b/jest.config.ts index c251b91..d446ddb 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -18,10 +18,13 @@ import fs from 'fs'; import os from 'os'; import path from 'path'; +const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'docker-actions-toolkit-')).split(path.sep).join(path.posix.sep); + process.env = Object.assign({}, process.env, { + TEMP: tmpDir, GITHUB_REPOSITORY: 'docker/actions-toolkit', - RUNNER_TEMP: fs.mkdtempSync(path.join(os.tmpdir(), 'docker-actions-toolkit-github-runner-')).split(path.sep).join(path.posix.sep), - RUNNER_TOOL_CACHE: fs.mkdtempSync(path.join(os.tmpdir(), 'docker-actions-toolkit-github-tool-cache-')).split(path.sep).join(path.posix.sep) + RUNNER_TEMP: path.join(tmpDir, 'runner-temp').split(path.sep).join(path.posix.sep), + RUNNER_TOOL_CACHE: path.join(tmpDir, 'runner-tool-cache').split(path.sep).join(path.posix.sep) }) as { [key: string]: string; }; diff --git a/src/buildx/install.ts b/src/buildx/install.ts index f95ad26..b95f720 100644 --- a/src/buildx/install.ts +++ b/src/buildx/install.ts @@ -83,10 +83,10 @@ export class Install { private async download(version: string): Promise { const targetFile: string = os.platform() == 'win32' ? 'docker-buildx.exe' : 'docker-buildx'; - const downloadUrl = util.format('https://github.com/docker/buildx/releases/download/v%s/%s', version, this.filename(version)); - const downloadPath = await tc.downloadTool(downloadUrl); - core.debug(`downloadUrl=${downloadUrl}`); - core.debug(`downloadPath=${downloadPath}`); + const downloadURL = util.format('https://github.com/docker/buildx/releases/download/v%s/%s', version, this.filename(version)); + const downloadPath = await tc.downloadTool(downloadURL); + core.debug(`downloadURL: ${downloadURL}`); + core.debug(`downloadPath: ${downloadPath}`); return await tc.cacheFile(downloadPath, targetFile, 'buildx', version); }