From 71d586a48cba15994d119318eed830301cfd9190 Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Wed, 21 Oct 2020 02:46:41 +0200 Subject: [PATCH] Fix tmpDir and defaultContext func Signed-off-by: CrazyMax --- .github/workflows/ci.yml | 7 +++++++ __tests__/context.test.ts | 22 ++++++++++++++++++++++ dist/index.js | 11 +++++++++-- src/context.ts | 16 ++++++++++++---- 4 files changed, 50 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 111bc64..015490c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -178,6 +178,13 @@ jobs: - name: Image digest run: echo ${{ steps.docker_build.outputs.digest }} + - + name: Check digest + run: | + if [ -z "${{ steps.docker_build.outputs.digest }}" ]; then + echo "::error::Digest should not be empty" + exit 1 + fi - name: Dump context if: always() diff --git a/__tests__/context.test.ts b/__tests__/context.test.ts index b373188..24ca2c2 100644 --- a/__tests__/context.test.ts +++ b/__tests__/context.test.ts @@ -104,6 +104,28 @@ describe('getArgs', () => { '--file', 'Dockerfile', 'https://github.com/docker/build-push-action.git#test-jest' ] + ], + [ + '0.4.2', + new Map([ + ['context', 'https://github.com/docker/build-push-action.git#heads/master'], + ['tag', 'localhost:5000/name/app:latest'], + ['platforms', 'linux/amd64,linux/arm64'], + ['secrets', 'GIT_AUTH_TOKEN=abcdefghijklmno0123456789'], + ['file', './test/Dockerfile'], + ['builder', 'builder-git-context-2'], + ['push', 'true'] + ]), + [ + 'buildx', + 'build', + '--platform', 'linux/amd64,linux/arm64', + '--secret', 'id=GIT_AUTH_TOKEN,src=/tmp/.docker-build-push-jest/.tmpname-jest', + '--file', './test/Dockerfile', + '--builder', 'builder-git-context-2', + '--push', + 'https://github.com/docker/build-push-action.git#heads/master' + ] ] ])( 'given %p with %p as inputs, returns %p', diff --git a/dist/index.js b/dist/index.js index 7bdb2e0..673d773 100644 --- a/dist/index.js +++ b/dist/index.js @@ -14849,13 +14849,20 @@ const tmp = __importStar(__webpack_require__(517)); const buildx = __importStar(__webpack_require__(295)); const core = __importStar(__webpack_require__(186)); const github = __importStar(__webpack_require__(438)); +let _defaultContext, _tmpDir; function defaultContext() { var _a, _b; - return `https://github.com/${github.context.repo.owner}/${github.context.repo.repo}.git#${(_b = (_a = github.context) === null || _a === void 0 ? void 0 : _a.ref) === null || _b === void 0 ? void 0 : _b.replace(/^refs\//, '')}`; + if (!_defaultContext) { + _defaultContext = `https://github.com/${github.context.repo.owner}/${github.context.repo.repo}.git#${(_b = (_a = github.context) === null || _a === void 0 ? void 0 : _a.ref) === null || _b === void 0 ? void 0 : _b.replace(/^refs\//, '')}`; + } + return _defaultContext; } exports.defaultContext = defaultContext; function tmpDir() { - return fs.mkdtempSync(path.join(os.tmpdir(), 'docker-build-push-')).split(path.sep).join(path.posix.sep); + if (!_tmpDir) { + _tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'docker-build-push-')).split(path.sep).join(path.posix.sep); + } + return _tmpDir; } exports.tmpDir = tmpDir; function tmpNameSync(options) { diff --git a/src/context.ts b/src/context.ts index ab11146..cfe3f63 100644 --- a/src/context.ts +++ b/src/context.ts @@ -7,6 +7,8 @@ import * as buildx from './buildx'; import * as core from '@actions/core'; import * as github from '@actions/github'; +let _defaultContext, _tmpDir: string; + export interface Inputs { context: string; file: string; @@ -29,13 +31,19 @@ export interface Inputs { } export function defaultContext(): string { - return `https://github.com/${github.context.repo.owner}/${ - github.context.repo.repo - }.git#${github.context?.ref?.replace(/^refs\//, '')}`; + if (!_defaultContext) { + _defaultContext = `https://github.com/${github.context.repo.owner}/${ + github.context.repo.repo + }.git#${github.context?.ref?.replace(/^refs\//, '')}`; + } + return _defaultContext; } export function tmpDir(): string { - return fs.mkdtempSync(path.join(os.tmpdir(), 'docker-build-push-')).split(path.sep).join(path.posix.sep); + if (!_tmpDir) { + _tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'docker-build-push-')).split(path.sep).join(path.posix.sep); + } + return _tmpDir; } export function tmpNameSync(options?: tmp.TmpNameOptions): string {