From 9b47e1591d5a772b13c9c0fe3e166d196f08bad9 Mon Sep 17 00:00:00 2001 From: nejdetkadir Date: Sun, 8 Oct 2023 13:24:20 +0300 Subject: [PATCH] chore: remove default files and configs --- .github/linters/.eslintrc.yml | 4 +- .prettierrc.json | 2 +- README.md | 4 +- __tests__/index.test.ts | 12 +++--- __tests__/main.test.ts | 80 ----------------------------------- __tests__/wait.test.ts | 25 ----------- dist/index.js | 36 +--------------- package-lock.json | 2 +- package.json | 2 +- src/constants/index.ts | 1 + src/index.ts | 4 +- src/lib/index.ts | 1 + src/main.ts | 18 ++------ src/wait.ts | 14 ------ tsconfig.json | 6 ++- 15 files changed, 26 insertions(+), 185 deletions(-) delete mode 100644 __tests__/main.test.ts delete mode 100644 __tests__/wait.test.ts create mode 100644 src/constants/index.ts create mode 100644 src/lib/index.ts delete mode 100644 src/wait.ts diff --git a/.github/linters/.eslintrc.yml b/.github/linters/.eslintrc.yml index f452aba..189e52c 100644 --- a/.github/linters/.eslintrc.yml +++ b/.github/linters/.eslintrc.yml @@ -44,7 +44,7 @@ rules: 'no-console': 'off', 'no-unused-vars': 'off', 'prettier/prettier': 'error', - 'semi': 'off', + 'semi': 'error', '@typescript-eslint/array-type': 'error', '@typescript-eslint/await-thenable': 'error', '@typescript-eslint/ban-ts-comment': 'error', @@ -76,7 +76,7 @@ rules: '@typescript-eslint/promise-function-async': 'error', '@typescript-eslint/require-array-sort-compare': 'error', '@typescript-eslint/restrict-plus-operands': 'error', - '@typescript-eslint/semi': ['error', 'never'], + '@typescript-eslint/semi': 'error', '@typescript-eslint/space-before-function-paren': 'off', '@typescript-eslint/type-annotation-spacing': 'error', '@typescript-eslint/unbound-method': 'error' diff --git a/.prettierrc.json b/.prettierrc.json index a378146..d068818 100644 --- a/.prettierrc.json +++ b/.prettierrc.json @@ -2,7 +2,7 @@ "printWidth": 80, "tabWidth": 2, "useTabs": false, - "semi": false, + "semi": true, "singleQuote": true, "quoteProps": "as-needed", "jsxSingleQuote": false, diff --git a/README.md b/README.md index 8aa27aa..9a639db 100644 --- a/README.md +++ b/README.md @@ -82,14 +82,14 @@ There are a few things to keep in mind when writing your action code: In `main.ts`, you will see that the action is run in an `async` function. ```javascript - import * as core from '@actions/core' + import * as core from '@actions/core'; //... async function run() { try { //... } catch (error) { - core.setFailed(error.message) + core.setFailed(error.message); } } ``` diff --git a/__tests__/index.test.ts b/__tests__/index.test.ts index 34a4dfe..93a2183 100644 --- a/__tests__/index.test.ts +++ b/__tests__/index.test.ts @@ -2,16 +2,16 @@ * Unit tests for the action's entrypoint, src/index.ts */ -import * as main from '../src/main' +import * as main from '../src/main'; // Mock the action's entrypoint -const runMock = jest.spyOn(main, 'run').mockImplementation() +const runMock = jest.spyOn(main, 'run').mockImplementation(); describe('index', () => { it('calls run when imported', async () => { // eslint-disable-next-line @typescript-eslint/no-require-imports - require('../src/index') + require('../src/index'); - expect(runMock).toHaveBeenCalled() - }) -}) + expect(runMock).toHaveBeenCalled(); + }); +}); diff --git a/__tests__/main.test.ts b/__tests__/main.test.ts deleted file mode 100644 index 7a25abc..0000000 --- a/__tests__/main.test.ts +++ /dev/null @@ -1,80 +0,0 @@ -/** - * Unit tests for the action's main functionality, src/main.ts - * - * These should be run as if the action was called from a workflow. - * Specifically, the inputs listed in `action.yml` should be set as environment - * variables following the pattern `INPUT_`. - */ - -import * as core from '@actions/core' -import * as main from '../src/main' - -// Mock the GitHub Actions core library -const debugMock = jest.spyOn(core, 'debug') -const getInputMock = jest.spyOn(core, 'getInput') -const setFailedMock = jest.spyOn(core, 'setFailed') -const setOutputMock = jest.spyOn(core, 'setOutput') - -// Mock the action's main function -const runMock = jest.spyOn(main, 'run') - -// Other utilities -const timeRegex = /^\d{2}:\d{2}:\d{2}/ - -describe('action', () => { - beforeEach(() => { - jest.clearAllMocks() - }) - - it('sets the time output', async () => { - // Set the action's inputs as return values from core.getInput() - getInputMock.mockImplementation((name: string): string => { - switch (name) { - case 'milliseconds': - return '500' - default: - return '' - } - }) - - await main.run() - expect(runMock).toHaveReturned() - - // Verify that all of the core library functions were called correctly - expect(debugMock).toHaveBeenNthCalledWith(1, 'Waiting 500 milliseconds ...') - expect(debugMock).toHaveBeenNthCalledWith( - 2, - expect.stringMatching(timeRegex) - ) - expect(debugMock).toHaveBeenNthCalledWith( - 3, - expect.stringMatching(timeRegex) - ) - expect(setOutputMock).toHaveBeenNthCalledWith( - 1, - 'time', - expect.stringMatching(timeRegex) - ) - }) - - it('sets a failed status', async () => { - // Set the action's inputs as return values from core.getInput() - getInputMock.mockImplementation((name: string): string => { - switch (name) { - case 'milliseconds': - return 'this is not a number' - default: - return '' - } - }) - - await main.run() - expect(runMock).toHaveReturned() - - // Verify that all of the core library functions were called correctly - expect(setFailedMock).toHaveBeenNthCalledWith( - 1, - 'milliseconds not a number' - ) - }) -}) diff --git a/__tests__/wait.test.ts b/__tests__/wait.test.ts deleted file mode 100644 index 1336aaa..0000000 --- a/__tests__/wait.test.ts +++ /dev/null @@ -1,25 +0,0 @@ -/** - * Unit tests for src/wait.ts - */ - -import { wait } from '../src/wait' -import { expect } from '@jest/globals' - -describe('wait.ts', () => { - it('throws an invalid number', async () => { - const input = parseInt('foo', 10) - expect(isNaN(input)).toBe(true) - - await expect(wait(input)).rejects.toThrow('milliseconds not a number') - }) - - it('waits with a valid number', async () => { - const start = new Date() - await wait(500) - const end = new Date() - - const delta = Math.abs(end.getTime() - start.getTime()) - - expect(delta).toBeGreaterThan(450) - }) -}) diff --git a/dist/index.js b/dist/index.js index 9bbc394..27af538 100644 --- a/dist/index.js +++ b/dist/index.js @@ -2753,22 +2753,13 @@ var __importStar = (this && this.__importStar) || function (mod) { Object.defineProperty(exports, "__esModule", ({ value: true })); exports.run = void 0; const core = __importStar(__nccwpck_require__(186)); -const wait_1 = __nccwpck_require__(259); /** * The main function for the action. * @returns {Promise} Resolves when the action is complete. */ async function run() { try { - const ms = core.getInput('milliseconds'); - // Debug logs are only output if the `ACTIONS_STEP_DEBUG` secret is true - core.debug(`Waiting ${ms} milliseconds ...`); - // Log the current timestamp, wait, then log the new timestamp - core.debug(new Date().toTimeString()); - await (0, wait_1.wait)(parseInt(ms, 10)); - core.debug(new Date().toTimeString()); - // Set outputs for other workflow steps to use - core.setOutput('time', new Date().toTimeString()); + // Call the your action code here } catch (error) { // Fail the workflow run if an error occurs @@ -2779,31 +2770,6 @@ async function run() { exports.run = run; -/***/ }), - -/***/ 259: -/***/ ((__unused_webpack_module, exports) => { - -"use strict"; - -Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.wait = void 0; -/** - * Wait for a number of milliseconds. - * @param milliseconds The number of milliseconds to wait. - * @returns {Promise} Resolves with 'done!' after the wait is over. - */ -async function wait(milliseconds) { - return new Promise(resolve => { - if (isNaN(milliseconds)) { - throw new Error('milliseconds not a number'); - } - setTimeout(() => resolve('done!'), milliseconds); - }); -} -exports.wait = wait; - - /***/ }), /***/ 491: diff --git a/package-lock.json b/package-lock.json index d80e576..12680e9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -31,7 +31,7 @@ "typescript": "^5.2.2" }, "engines": { - "node": ">=20" + "node": ">=18" } }, "node_modules/@aashutoshrathi/word-wrap": { diff --git a/package.json b/package.json index 1f679d3..0f83989 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ ".": "./dist/index.js" }, "engines": { - "node": ">=20" + "node": ">=18" }, "scripts": { "bundle": "npm run format:write && npm run package", diff --git a/src/constants/index.ts b/src/constants/index.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/src/constants/index.ts @@ -0,0 +1 @@ +export {}; diff --git a/src/index.ts b/src/index.ts index b08f970..8395471 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,7 +1,7 @@ /** * The entrypoint for the action. */ -import { run } from './main' +import { run } from './main'; // eslint-disable-next-line @typescript-eslint/no-floating-promises -run() +run(); diff --git a/src/lib/index.ts b/src/lib/index.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/src/lib/index.ts @@ -0,0 +1 @@ +export {}; diff --git a/src/main.ts b/src/main.ts index c804f90..fa0d39f 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,5 +1,4 @@ -import * as core from '@actions/core' -import { wait } from './wait' +import * as core from '@actions/core'; /** * The main function for the action. @@ -7,20 +6,9 @@ import { wait } from './wait' */ export async function run(): Promise { try { - const ms: string = core.getInput('milliseconds') - - // Debug logs are only output if the `ACTIONS_STEP_DEBUG` secret is true - core.debug(`Waiting ${ms} milliseconds ...`) - - // Log the current timestamp, wait, then log the new timestamp - core.debug(new Date().toTimeString()) - await wait(parseInt(ms, 10)) - core.debug(new Date().toTimeString()) - - // Set outputs for other workflow steps to use - core.setOutput('time', new Date().toTimeString()) + // Call the your action code here } catch (error) { // Fail the workflow run if an error occurs - if (error instanceof Error) core.setFailed(error.message) + if (error instanceof Error) core.setFailed(error.message); } } diff --git a/src/wait.ts b/src/wait.ts deleted file mode 100644 index 0ddf692..0000000 --- a/src/wait.ts +++ /dev/null @@ -1,14 +0,0 @@ -/** - * Wait for a number of milliseconds. - * @param milliseconds The number of milliseconds to wait. - * @returns {Promise} Resolves with 'done!' after the wait is over. - */ -export async function wait(milliseconds: number): Promise { - return new Promise(resolve => { - if (isNaN(milliseconds)) { - throw new Error('milliseconds not a number') - } - - setTimeout(() => resolve('done!'), milliseconds) - }) -} diff --git a/tsconfig.json b/tsconfig.json index 2f26aac..ed6c069 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -13,7 +13,11 @@ "forceConsistentCasingInFileNames": true, "strict": true, "skipLibCheck": true, - "newLine": "lf" + "newLine": "lf", + "paths": { + "@app/lib": ["src/lib"], + "@app/constants": ["src/constants"] + } }, "exclude": ["./dist", "./node_modules", "./__tests__", "./coverage"] }