Skip to content

Commit fda3be9

Browse files
authored
Merge pull request #58 from crazy-max/docker-install
docker: install, download and tearDown methods
2 parents 53ca96f + 70390c8 commit fda3be9

File tree

18 files changed

+967
-8
lines changed

18 files changed

+967
-8
lines changed

.github/workflows/build.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: build
2+
3+
on:
4+
push:
5+
branches:
6+
- 'main'
7+
pull_request:
8+
paths-ignore:
9+
- '.github/buildx-releases.json'
10+
11+
jobs:
12+
build:
13+
runs-on: ubuntu-latest
14+
steps:
15+
-
16+
name: Checkout
17+
uses: actions/checkout@v3
18+
-
19+
name: Build
20+
uses: docker/bake-action@v2
21+
with:
22+
targets: build

.github/workflows/e2e.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: e2e
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- 'main'
8+
pull_request:
9+
paths-ignore:
10+
- '.github/buildx-releases.json'
11+
12+
jobs:
13+
test:
14+
runs-on: ${{ matrix.os }}
15+
strategy:
16+
fail-fast: false
17+
matrix:
18+
os:
19+
- ubuntu-latest
20+
- macos-latest
21+
- windows-latest
22+
steps:
23+
-
24+
name: Checkout
25+
uses: actions/checkout@v3
26+
-
27+
name: Setup Node
28+
uses: actions/setup-node@v3
29+
with:
30+
node-version: 16
31+
cache: 'yarn'
32+
-
33+
name: Install
34+
run: yarn install
35+
-
36+
name: Test
37+
run: yarn test-coverage:e2e --coverageDirectory=./coverage
38+
env:
39+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
40+
-
41+
name: Upload coverage
42+
uses: codecov/codecov-action@v3
43+
with:
44+
file: ./coverage/clover.xml
45+
flags: e2e

.github/workflows/test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,4 @@ jobs:
4646
uses: codecov/codecov-action@v3
4747
with:
4848
file: ./coverage/clover.xml
49+
flags: unit

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
[![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)
22
[![Downloads](https://img.shields.io/npm/dw/@docker/actions-toolkit?logo=npm&style=flat-square)](https://www.npmjs.com/package/@docker/actions-toolkit)
3+
[![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)
34
[![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)
5+
[![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)
46
[![Codecov](https://img.shields.io/codecov/c/github/docker/actions-toolkit?logo=codecov&style=flat-square)](https://codecov.io/gh/docker/actions-toolkit)
57

68
# Actions Toolkit

__tests__/docker.test.ts renamed to __tests__/docker/docker.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ import path from 'path';
1919
import * as io from '@actions/io';
2020
import osm = require('os');
2121

22-
import {Docker} from '../src/docker';
23-
import {Exec} from '../src/exec';
22+
import {Docker} from '../../src/docker/docker';
23+
import {Exec} from '../../src/exec';
2424

2525
beforeEach(() => {
2626
jest.clearAllMocks();
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* Copyright 2023 actions-toolkit authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import path from 'path';
18+
import {describe, expect, test} from '@jest/globals';
19+
20+
import {Install} from '../../src/docker/install';
21+
import {Docker} from '../../src/docker/docker';
22+
23+
// prettier-ignore
24+
const tmpDir = path.join(process.env.TEMP || '/tmp', 'buildx-jest');
25+
26+
describe('install', () => {
27+
// prettier-ignore
28+
test.each(['23.0.0'])(
29+
'install docker %s', async (version) => {
30+
await expect((async () => {
31+
const install = new Install();
32+
const toolPath = await install.download(version);
33+
await install.install(toolPath, tmpDir, version);
34+
await Docker.printVersion();
35+
await Docker.printInfo();
36+
await install.tearDown(tmpDir);
37+
})()).resolves.not.toThrow();
38+
});
39+
});

__tests__/docker/install.test.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/**
2+
* Copyright 2023 actions-toolkit authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import {describe, expect, jest, test, beforeEach, afterEach} from '@jest/globals';
18+
import * as fs from 'fs';
19+
import * as path from 'path';
20+
import * as rimraf from 'rimraf';
21+
import osm = require('os');
22+
23+
import {Install} from '../../src/docker/install';
24+
25+
// prettier-ignore
26+
const tmpDir = path.join(process.env.TEMP || '/tmp', 'buildx-jest');
27+
28+
beforeEach(() => {
29+
jest.clearAllMocks();
30+
});
31+
32+
afterEach(function () {
33+
rimraf.sync(tmpDir);
34+
});
35+
36+
describe('download', () => {
37+
// prettier-ignore
38+
test.each([
39+
['19.03.6', 'linux'],
40+
['20.10.22', 'linux'],
41+
['20.10.22', 'darwin'],
42+
['20.10.22', 'win32'],
43+
])(
44+
'acquires %p of docker (%s)', async (version, platformOS) => {
45+
jest.spyOn(osm, 'platform').mockImplementation(() => platformOS);
46+
const install = new Install();
47+
const toolPath = await install.download(version);
48+
expect(fs.existsSync(toolPath)).toBe(true);
49+
}, 100000);
50+
});

hack/dockerfiles/license.Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

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

2222
FROM ghcr.io/google/addlicense:${ADDLICENSE_VERSION} AS addlicense

jest.config.e2e.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* Copyright 2023 actions-toolkit authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
module.exports = {
18+
clearMocks: true,
19+
testEnvironment: 'node',
20+
moduleFileExtensions: ['js', 'ts'],
21+
setupFiles: ['dotenv/config'],
22+
testMatch: ['**/*.test.e2e.ts'],
23+
testTimeout: 1800000, // 30 minutes
24+
transform: {
25+
'^.+\\.ts$': 'ts-jest'
26+
},
27+
moduleNameMapper: {
28+
'^csv-parse/sync': '<rootDir>/node_modules/csv-parse/dist/cjs/sync.cjs'
29+
},
30+
verbose: false
31+
};

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
"prettier": "prettier --check \"./**/*.ts\"",
1212
"prettier:fix": "prettier --write \"./**/*.ts\"",
1313
"test": "jest",
14-
"test-coverage": "jest --coverage"
14+
"test:e2e": "jest -c jest.config.e2e.ts --runInBand --detectOpenHandles",
15+
"test-coverage": "jest --coverage",
16+
"test-coverage:e2e": "jest --coverage -c jest.config.e2e.ts --runInBand --detectOpenHandles"
1517
},
1618
"repository": {
1719
"type": "git",
@@ -48,7 +50,9 @@
4850
"@actions/http-client": "^2.0.1",
4951
"@actions/io": "^1.1.2",
5052
"@actions/tool-cache": "^2.0.1",
53+
"async-retry": "^1.3.3",
5154
"csv-parse": "^5.3.5",
55+
"handlebars": "^4.7.7",
5256
"jwt-decode": "^3.1.2",
5357
"semver": "^7.3.8",
5458
"tmp": "^0.2.1"

0 commit comments

Comments
 (0)