Skip to content

Commit

Permalink
Merge pull request #409 from crazy-max/switch-toolkit
Browse files Browse the repository at this point in the history
switch to actions-toolkit implementation
  • Loading branch information
crazy-max committed Feb 24, 2023
2 parents 3da7dc6 + d01f5a4 commit ec9cdf0
Show file tree
Hide file tree
Showing 13 changed files with 469 additions and 90 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"env": {
"node": true,
"es2021": true,
"jest/globals": true
"jest": true
},
"extends": [
"eslint:recommended",
Expand Down
5 changes: 0 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
/.dev
node_modules/
lib

# Jetbrains
/.idea
/*.iml

# Rest of the file pulled from https://github.com/github/gitignore/blob/master/Node.gitignore
# Logs
logs
Expand Down
13 changes: 4 additions & 9 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
import {expect, jest, test} from '@jest/globals';
import osm = require('os');

import {run} from '../src/main';
import {main} from '../src/main';
import * as docker from '../src/docker';
import * as stateHelper from '../src/state-helper';

import * as core from '@actions/core';

test('errors without username and password', async () => {
jest.spyOn(osm, 'platform').mockImplementation(() => 'linux');
process.env['INPUT_LOGOUT'] = 'true'; // default value
const coreSpy = jest.spyOn(core, 'setFailed');

await run();
expect(coreSpy).toHaveBeenCalledWith('Username and password required');
await expect(main()).rejects.toThrowError(new Error('Username and password required'));
});

test('successful with username and password', async () => {
Expand All @@ -34,7 +29,7 @@ test('successful with username and password', async () => {
const logout = false;
process.env['INPUT_LOGOUT'] = String(logout);

await run();
await main();

expect(setRegistrySpy).toHaveBeenCalledWith('');
expect(setLogoutSpy).toHaveBeenCalledWith(logout);
Expand Down Expand Up @@ -63,7 +58,7 @@ test('calls docker login', async () => {
const logout = true;
process.env['INPUT_LOGOUT'] = String(logout);

await run();
await main();

expect(setRegistrySpy).toHaveBeenCalledWith(registry);
expect(setLogoutSpy).toHaveBeenCalledWith(logout);
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

195 changes: 195 additions & 0 deletions dist/licenses.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 21 additions & 2 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,29 @@
import fs from 'fs';
import os from 'os';
import path from 'path';

const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'docker-login-action-')).split(path.sep).join(path.posix.sep);

process.env = Object.assign({}, process.env, {
TEMP: tmpDir,
GITHUB_REPOSITORY: 'docker/login-action',
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;
};

module.exports = {
clearMocks: true,
moduleFileExtensions: ['js', 'ts'],
setupFiles: ["dotenv/config"],
testMatch: ['**/*.test.ts'],
transform: {
'^.+\\.ts$': 'ts-jest'
},
moduleNameMapper: {
'^csv-parse/sync': '<rootDir>/node_modules/csv-parse/dist/cjs/sync.cjs'
},
collectCoverageFrom: ['src/**/{!(main.ts),}.ts'],
coveragePathIgnorePatterns: ['lib/', 'node_modules/', '__tests__/'],
verbose: true
}
};
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@
"license": "MIT",
"dependencies": {
"@actions/core": "^1.10.0",
"@actions/exec": "^1.1.1",
"@actions/io": "^1.1.2",
"@aws-sdk/client-ecr": "^3.231.0",
"@aws-sdk/client-ecr-public": "^3.231.0",
"@docker/actions-toolkit": "^0.1.0-beta.14",
"http-proxy-agent": "^5.0.0",
"https-proxy-agent": "^5.0.1"
},
Expand All @@ -40,7 +39,6 @@
"@typescript-eslint/eslint-plugin": "^5.14.0",
"@typescript-eslint/parser": "^5.14.0",
"@vercel/ncc": "^0.33.3",
"dotenv": "^16.0.0",
"eslint": "^8.11.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-jest": "^26.1.1",
Expand Down
Loading

0 comments on commit ec9cdf0

Please sign in to comment.