Skip to content

Commit

Permalink
Merge pull request #58 from crazy-max/docker-install
Browse files Browse the repository at this point in the history
docker: install, download and tearDown methods
  • Loading branch information
crazy-max committed Mar 2, 2023
2 parents 53ca96f + 70390c8 commit fda3be9
Show file tree
Hide file tree
Showing 18 changed files with 967 additions and 8 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: build

on:
push:
branches:
- 'main'
pull_request:
paths-ignore:
- '.github/buildx-releases.json'

jobs:
build:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v3
-
name: Build
uses: docker/bake-action@v2
with:
targets: build
45 changes: 45 additions & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: e2e

on:
workflow_dispatch:
push:
branches:
- 'main'
pull_request:
paths-ignore:
- '.github/buildx-releases.json'

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- macos-latest
- windows-latest
steps:
-
name: Checkout
uses: actions/checkout@v3
-
name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 16
cache: 'yarn'
-
name: Install
run: yarn install
-
name: Test
run: yarn test-coverage:e2e --coverageDirectory=./coverage
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
-
name: Upload coverage
uses: codecov/codecov-action@v3
with:
file: ./coverage/clover.xml
flags: e2e
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@ jobs:
uses: codecov/codecov-action@v3
with:
file: ./coverage/clover.xml
flags: unit
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
[![Version](https://img.shields.io/npm/v/@docker/actions-toolkit?label=version&logo=npm&style=flat-square)](https://www.npmjs.com/package/@docker/actions-toolkit)
[![Downloads](https://img.shields.io/npm/dw/@docker/actions-toolkit?logo=npm&style=flat-square)](https://www.npmjs.com/package/@docker/actions-toolkit)
[![Build workflow](https://img.shields.io/github/actions/workflow/status/docker/actions-toolkit/build.yml?label=build&logo=github&style=flat-square)](https://github.com/docker/actions-toolkit/actions?workflow=build)
[![Test workflow](https://img.shields.io/github/actions/workflow/status/docker/actions-toolkit/test.yml?label=test&logo=github&style=flat-square)](https://github.com/docker/actions-toolkit/actions?workflow=test)
[![E2E workflow](https://img.shields.io/github/actions/workflow/status/docker/actions-toolkit/e2e.yml?label=e2e&logo=github&style=flat-square)](https://github.com/docker/actions-toolkit/actions?workflow=e2e)
[![Codecov](https://img.shields.io/codecov/c/github/docker/actions-toolkit?logo=codecov&style=flat-square)](https://codecov.io/gh/docker/actions-toolkit)

# Actions Toolkit
Expand Down
4 changes: 2 additions & 2 deletions __tests__/docker.test.ts → __tests__/docker/docker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import path from 'path';
import * as io from '@actions/io';
import osm = require('os');

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

beforeEach(() => {
jest.clearAllMocks();
Expand Down
39 changes: 39 additions & 0 deletions __tests__/docker/install.test.e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* Copyright 2023 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import path from 'path';
import {describe, expect, test} from '@jest/globals';

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

// prettier-ignore
const tmpDir = path.join(process.env.TEMP || '/tmp', 'buildx-jest');

describe('install', () => {
// prettier-ignore
test.each(['23.0.0'])(
'install docker %s', async (version) => {
await expect((async () => {
const install = new Install();
const toolPath = await install.download(version);
await install.install(toolPath, tmpDir, version);
await Docker.printVersion();
await Docker.printInfo();
await install.tearDown(tmpDir);
})()).resolves.not.toThrow();
});
});
50 changes: 50 additions & 0 deletions __tests__/docker/install.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* Copyright 2023 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

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

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

// prettier-ignore
const tmpDir = path.join(process.env.TEMP || '/tmp', 'buildx-jest');

beforeEach(() => {
jest.clearAllMocks();
});

afterEach(function () {
rimraf.sync(tmpDir);
});

describe('download', () => {
// prettier-ignore
test.each([
['19.03.6', 'linux'],
['20.10.22', 'linux'],
['20.10.22', 'darwin'],
['20.10.22', 'win32'],
])(
'acquires %p of docker (%s)', async (version, platformOS) => {
jest.spyOn(osm, 'platform').mockImplementation(() => platformOS);
const install = new Install();
const toolPath = await install.download(version);
expect(fs.existsSync(toolPath)).toBe(true);
}, 100000);
});
2 changes: 1 addition & 1 deletion hack/dockerfiles/license.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

ARG LICENSE_HOLDER="actions-toolkit authors"
ARG LICENSE_TYPE="apache"
ARG LICENSE_FILES=".*\(Dockerfile\|Makefile\|\.js\|\.ts\|\.hcl\|\.sh\)"
ARG LICENSE_FILES=".*\(Dockerfile\|Makefile\|\.js\|\.ts\|\.hcl\|\.sh|\.ps1\)"
ARG ADDLICENSE_VERSION="v1.0.0"

FROM ghcr.io/google/addlicense:${ADDLICENSE_VERSION} AS addlicense
Expand Down
31 changes: 31 additions & 0 deletions jest.config.e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Copyright 2023 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

module.exports = {
clearMocks: true,
testEnvironment: 'node',
moduleFileExtensions: ['js', 'ts'],
setupFiles: ['dotenv/config'],
testMatch: ['**/*.test.e2e.ts'],
testTimeout: 1800000, // 30 minutes
transform: {
'^.+\\.ts$': 'ts-jest'
},
moduleNameMapper: {
'^csv-parse/sync': '<rootDir>/node_modules/csv-parse/dist/cjs/sync.cjs'
},
verbose: false
};
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
"prettier": "prettier --check \"./**/*.ts\"",
"prettier:fix": "prettier --write \"./**/*.ts\"",
"test": "jest",
"test-coverage": "jest --coverage"
"test:e2e": "jest -c jest.config.e2e.ts --runInBand --detectOpenHandles",
"test-coverage": "jest --coverage",
"test-coverage:e2e": "jest --coverage -c jest.config.e2e.ts --runInBand --detectOpenHandles"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -48,7 +50,9 @@
"@actions/http-client": "^2.0.1",
"@actions/io": "^1.1.2",
"@actions/tool-cache": "^2.0.1",
"async-retry": "^1.3.3",
"csv-parse": "^5.3.5",
"handlebars": "^4.7.7",
"jwt-decode": "^3.1.2",
"semver": "^7.3.8",
"tmp": "^0.2.1"
Expand Down
2 changes: 1 addition & 1 deletion src/buildx/buildx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import path from 'path';
import * as core from '@actions/core';
import * as semver from 'semver';

import {Docker} from '../docker';
import {Docker} from '../docker/docker';
import {Exec} from '../exec';
import {Inputs} from './inputs';

Expand Down
2 changes: 1 addition & 1 deletion src/buildx/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import * as util from 'util';
import {Buildx} from './buildx';
import {Context} from '../context';
import {Exec} from '../exec';
import {Docker} from '../docker';
import {Docker} from '../docker/docker';
import {Git} from '../git';

import {GitHubRelease} from '../types/github';
Expand Down
Loading

0 comments on commit fda3be9

Please sign in to comment.