setup: Initialize project settings (#1)

This commit is contained in:
Jeongseok Kang 2024-02-18 03:37:46 +09:00 committed by GitHub
parent cb810abaf7
commit a44709eaba
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
14 changed files with 4232 additions and 6936 deletions

View File

@ -1 +1 @@
20.6.0
20.7.0

View File

@ -2,11 +2,11 @@
"printWidth": 80,
"tabWidth": 2,
"useTabs": false,
"semi": false,
"singleQuote": true,
"semi": true,
"singleQuote": false,
"quoteProps": "as-needed",
"jsxSingleQuote": false,
"trailingComma": "none",
"trailingComma": "es5",
"bracketSpacing": true,
"bracketSameLine": true,
"arrowParens": "avoid",

View File

@ -1,3 +0,0 @@
# Repository CODEOWNERS
* @actions/actions-oss-maintainers

View File

@ -4,7 +4,6 @@
![CI](https://github.com/actions/typescript-action/actions/workflows/ci.yml/badge.svg)
[![Check dist/](https://github.com/actions/typescript-action/actions/workflows/check-dist.yml/badge.svg)](https://github.com/actions/typescript-action/actions/workflows/check-dist.yml)
[![CodeQL](https://github.com/actions/typescript-action/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/actions/typescript-action/actions/workflows/codeql-analysis.yml)
[![Coverage](./badges/coverage.svg)](./badges/coverage.svg)
Use this template to bootstrap the creation of a TypeScript action. :rocket:

View File

@ -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 () => {
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();
});
});

View File

@ -6,84 +6,87 @@
* variables following the pattern `INPUT_<INPUT_NAME>`.
*/
import * as core from '@actions/core'
import * as main from '../src/main'
import * as core from "@actions/core";
import * as main from "../src/main";
// Mock the action's main function
const runMock = jest.spyOn(main, 'run')
const runMock = jest.spyOn(main, "run");
// Other utilities
const timeRegex = /^\d{2}:\d{2}:\d{2}/
const timeRegex = /^\d{2}:\d{2}:\d{2}/;
// Mock the GitHub Actions core library
let debugMock: jest.SpyInstance
let errorMock: jest.SpyInstance
let getInputMock: jest.SpyInstance
let setFailedMock: jest.SpyInstance
let setOutputMock: jest.SpyInstance
let debugMock: jest.SpyInstance;
let errorMock: jest.SpyInstance;
let getInputMock: jest.SpyInstance;
let setFailedMock: jest.SpyInstance;
let setOutputMock: jest.SpyInstance;
describe('action', () => {
describe("action", () => {
beforeEach(() => {
jest.clearAllMocks()
jest.clearAllMocks();
debugMock = jest.spyOn(core, 'debug').mockImplementation()
errorMock = jest.spyOn(core, 'error').mockImplementation()
getInputMock = jest.spyOn(core, 'getInput').mockImplementation()
setFailedMock = jest.spyOn(core, 'setFailed').mockImplementation()
setOutputMock = jest.spyOn(core, 'setOutput').mockImplementation()
})
debugMock = jest.spyOn(core, "debug").mockImplementation();
errorMock = jest.spyOn(core, "error").mockImplementation();
getInputMock = jest.spyOn(core, "getInput").mockImplementation();
setFailedMock = jest.spyOn(core, "setFailed").mockImplementation();
setOutputMock = jest.spyOn(core, "setOutput").mockImplementation();
});
it('sets the time output', async () => {
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'
case "milliseconds":
return "500";
default:
return ''
return "";
}
})
});
await main.run()
expect(runMock).toHaveReturned()
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(
1,
"Waiting 500 milliseconds ..."
);
expect(debugMock).toHaveBeenNthCalledWith(
2,
expect.stringMatching(timeRegex)
)
);
expect(debugMock).toHaveBeenNthCalledWith(
3,
expect.stringMatching(timeRegex)
)
);
expect(setOutputMock).toHaveBeenNthCalledWith(
1,
'time',
"time",
expect.stringMatching(timeRegex)
)
expect(errorMock).not.toHaveBeenCalled()
})
);
expect(errorMock).not.toHaveBeenCalled();
});
it('sets a failed status', async () => {
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'
case "milliseconds":
return "this is not a number";
default:
return ''
return "";
}
})
});
await main.run()
expect(runMock).toHaveReturned()
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'
)
expect(errorMock).not.toHaveBeenCalled()
})
})
"milliseconds not a number"
);
expect(errorMock).not.toHaveBeenCalled();
});
});

View File

@ -2,24 +2,24 @@
* Unit tests for src/wait.ts
*/
import { wait } from '../src/wait'
import { expect } from '@jest/globals'
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)
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')
})
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()
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())
const delta = Math.abs(end.getTime() - start.getTime());
expect(delta).toBeGreaterThan(450)
})
})
expect(delta).toBeGreaterThan(450);
});
});

View File

@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="106" height="20" role="img" aria-label="Coverage: 100%"><title>Coverage: 100%</title><linearGradient id="s" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><clipPath id="r"><rect width="106" height="20" rx="3" fill="#fff"/></clipPath><g clip-path="url(#r)"><rect width="63" height="20" fill="#555"/><rect x="63" width="43" height="20" fill="#4c1"/><rect width="106" height="20" fill="url(#s)"/></g><g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110"><text aria-hidden="true" x="325" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="530">Coverage</text><text x="325" y="140" transform="scale(.1)" fill="#fff" textLength="530">Coverage</text><text aria-hidden="true" x="835" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="330">100%</text><text x="835" y="140" transform="scale(.1)" fill="#fff" textLength="330">100%</text></g></svg>

Before

Width:  |  Height:  |  Size: 1.1 KiB

6840
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,16 +1,16 @@
{
"name": "typescript-action",
"description": "GitHub Actions TypeScript template",
"name": "git-branch-strategy-action",
"description": "GitHub Actions workflow for custom git branch strategy",
"version": "0.0.0",
"author": "",
"author": "Jeongseok Kang <piono623@naver.com>",
"private": true,
"homepage": "https://github.com/actions/typescript-action",
"homepage": "https://github.com/rapsealk/git-branch-strategy-action",
"repository": {
"type": "git",
"url": "git+https://github.com/actions/typescript-action.git"
"url": "git+https://github.com/rapsealk/git-branch-strategy-action.git"
},
"bugs": {
"url": "https://github.com/actions/typescript-action/issues"
"url": "https://github.com/rapsealk/git-branch-strategy-action/issues"
},
"keywords": [
"actions",

View File

@ -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();

View File

@ -1,5 +1,5 @@
import * as core from '@actions/core'
import { wait } from './wait'
import * as core from "@actions/core";
import { wait } from "./wait";
/**
* The main function for the action.
@ -7,20 +7,20 @@ import { wait } from './wait'
*/
export async function run(): Promise<void> {
try {
const ms: string = core.getInput('milliseconds')
const ms: string = core.getInput("milliseconds");
// Debug logs are only output if the `ACTIONS_STEP_DEBUG` secret is true
core.debug(`Waiting ${ms} milliseconds ...`)
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())
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())
core.setOutput("time", new Date().toTimeString());
} 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);
}
}

View File

@ -6,9 +6,9 @@
export async function wait(milliseconds: number): Promise<string> {
return new Promise(resolve => {
if (isNaN(milliseconds)) {
throw new Error('milliseconds not a number')
throw new Error("milliseconds not a number");
}
setTimeout(() => resolve('done!'), milliseconds)
})
setTimeout(() => resolve("done!"), milliseconds);
});
}

4138
yarn.lock Normal file

File diff suppressed because it is too large Load Diff