From 2dc3689d1b7471dd6e56a2675d055d3d1e81c346 Mon Sep 17 00:00:00 2001 From: Shohei Ueda <30958501+peaceiris@users.noreply.github.com> Date: Tue, 15 Sep 2020 18:13:11 +0900 Subject: [PATCH] feat: Merge sub-actions (#35) --- .../workflows/suggest-related-links-train.yml | 19 ----- .github/workflows/suggest-related-links.yml | 7 +- README.md | 26 +++++-- action.yml | 14 +++- actions/{train => }/.gitignore | 0 .../{train => }/__tests__/get-inputs.test.ts | 4 +- actions/{train => }/src/get-inputs.ts | 0 actions/{train => }/src/github-api.ts | 0 actions/{suggest => }/src/index.ts | 0 actions/{train => }/src/interfaces.ts | 0 actions/{train => }/src/main.ts | 0 actions/suggest/README.md | 9 --- actions/suggest/__tests__/get-inputs.test.ts | 74 ------------------- actions/suggest/src/get-inputs.ts | 17 ----- actions/suggest/src/interfaces.ts | 9 --- actions/suggest/src/main.ts | 27 ------- actions/train/README.md | 9 --- actions/train/action.yml | 37 ---------- actions/train/src/index.ts | 10 --- package.json | 6 +- release.sh | 6 +- 21 files changed, 46 insertions(+), 228 deletions(-) delete mode 100644 .github/workflows/suggest-related-links-train.yml rename actions/{train => }/.gitignore (100%) rename actions/{train => }/__tests__/get-inputs.test.ts (98%) rename actions/{train => }/src/get-inputs.ts (100%) rename actions/{train => }/src/github-api.ts (100%) rename actions/{suggest => }/src/index.ts (100%) rename actions/{train => }/src/interfaces.ts (100%) rename actions/{train => }/src/main.ts (100%) delete mode 100644 actions/suggest/README.md delete mode 100644 actions/suggest/__tests__/get-inputs.test.ts delete mode 100644 actions/suggest/src/get-inputs.ts delete mode 100644 actions/suggest/src/interfaces.ts delete mode 100644 actions/suggest/src/main.ts delete mode 100644 actions/train/README.md delete mode 100644 actions/train/action.yml delete mode 100644 actions/train/src/index.ts diff --git a/.github/workflows/suggest-related-links-train.yml b/.github/workflows/suggest-related-links-train.yml deleted file mode 100644 index c24a085..0000000 --- a/.github/workflows/suggest-related-links-train.yml +++ /dev/null @@ -1,19 +0,0 @@ -name: 'Suggest Related Links Train' - -on: - workflow_dispatch: - schedule: - - cron: '13 13 * * */7' - -jobs: - train: - runs-on: ubuntu-18.04 - steps: - - name: Dump GitHub context - env: - GITHUB_CONTEXT: ${{ toJson(github) }} - run: echo "$GITHUB_CONTEXT" - - name: Train - uses: peaceiris/actions-suggest-related-links/actions/train@v0.4.0 - with: - repository: 'peaceiris/actions-gh-pages' diff --git a/.github/workflows/suggest-related-links.yml b/.github/workflows/suggest-related-links.yml index bfe8bb7..f42c734 100644 --- a/.github/workflows/suggest-related-links.yml +++ b/.github/workflows/suggest-related-links.yml @@ -5,9 +5,14 @@ on: types: - opened - edited + workflow_dispatch: + schedule: + - cron: '13 13 * * */7' jobs: - suggest: + action: runs-on: ubuntu-18.04 steps: - uses: peaceiris/actions-suggest-related-links@v0.4.0 + with: + repository: 'peaceiris/actions-gh-pages' diff --git a/README.md b/README.md index 0c414bb..2ba16ae 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,31 @@ +## Suggest Related Links Action + +A GitHub Action to suggest related or similar issues, documents, and links. Based on the power of NLP and fastText. + + + +## Table of Contents + -**Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)* -- [Suggest Related Links Action](#suggest-related-links-action) + - [Maintainers](#maintainers) +- [License](#license) -## Suggest Related Links Action -A GitHub Action to suggest related or similar issues, documents, and links. Based on the power of NLP and fastText. +## Maintainers + +- [peaceiris (Shohei Ueda)](https://github.com/peaceiris) +- [S-Kaisei (Kaisei Shimura)](https://github.com/S-Kaisei) + + + +## License + +MIT License -## Maintainers +
Back to TOC ☝️
diff --git a/action.yml b/action.yml index 07d9686..70c7d03 100644 --- a/action.yml +++ b/action.yml @@ -3,7 +3,7 @@ description: 'A GitHub Action to suggest related or similar issues, documents, a author: 'peaceiris' runs: using: 'node12' - main: 'actions/suggest/dist/index.js' + main: 'actions/dist/index.js' branding: icon: 'link' color: 'orange' @@ -28,6 +28,18 @@ inputs: description: 'Set a model for suggesting.' default: 'fasttext' required: false + repository: + description: 'Set a repository name of issue source. (e.g. peaceiris/actions-gh-pages)' + default: ${{ github.repository }} + required: false + custom_training_data: + description: 'Set paths to JSON files including custom training data.' + default: '' + required: false + train_issues: + description: 'Set this to true to train issue data.' + default: 'true' + required: false outputs: json_path: description: 'A path to a JSON file that contains results.' diff --git a/actions/train/.gitignore b/actions/.gitignore similarity index 100% rename from actions/train/.gitignore rename to actions/.gitignore diff --git a/actions/train/__tests__/get-inputs.test.ts b/actions/__tests__/get-inputs.test.ts similarity index 98% rename from actions/train/__tests__/get-inputs.test.ts rename to actions/__tests__/get-inputs.test.ts index 8063379..9c757c9 100644 --- a/actions/train/__tests__/get-inputs.test.ts +++ b/actions/__tests__/get-inputs.test.ts @@ -10,7 +10,7 @@ beforeEach(() => { process.stdout.write = jest.fn(); // eslint-disable-next-line @typescript-eslint/no-explicit-any - const doc: any = yaml.safeLoad(fs.readFileSync(__dirname + '/../action.yml', 'utf8')); + const doc: any = yaml.safeLoad(fs.readFileSync(__dirname + '/../../action.yml', 'utf8')); Object.keys(doc.inputs).forEach(name => { const envVar = `INPUT_${name.replace(/ /g, '_').toUpperCase()}`; process.env[envVar] = doc.inputs[name]['default']; @@ -19,7 +19,7 @@ beforeEach(() => { afterEach(() => { // eslint-disable-next-line @typescript-eslint/no-explicit-any - const doc: any = yaml.safeLoad(fs.readFileSync(__dirname + '/../action.yml', 'utf8')); + const doc: any = yaml.safeLoad(fs.readFileSync(__dirname + '/../../action.yml', 'utf8')); Object.keys(doc.inputs).forEach(name => { const envVar = `INPUT_${name.replace(/ /g, '_').toUpperCase()}`; console.debug(`delete ${envVar}\t${process.env[envVar]}`); diff --git a/actions/train/src/get-inputs.ts b/actions/src/get-inputs.ts similarity index 100% rename from actions/train/src/get-inputs.ts rename to actions/src/get-inputs.ts diff --git a/actions/train/src/github-api.ts b/actions/src/github-api.ts similarity index 100% rename from actions/train/src/github-api.ts rename to actions/src/github-api.ts diff --git a/actions/suggest/src/index.ts b/actions/src/index.ts similarity index 100% rename from actions/suggest/src/index.ts rename to actions/src/index.ts diff --git a/actions/train/src/interfaces.ts b/actions/src/interfaces.ts similarity index 100% rename from actions/train/src/interfaces.ts rename to actions/src/interfaces.ts diff --git a/actions/train/src/main.ts b/actions/src/main.ts similarity index 100% rename from actions/train/src/main.ts rename to actions/src/main.ts diff --git a/actions/suggest/README.md b/actions/suggest/README.md deleted file mode 100644 index 7703f68..0000000 --- a/actions/suggest/README.md +++ /dev/null @@ -1,9 +0,0 @@ - - -**Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)* - -- [Suggest Action](#suggest-action) - - - -## Suggest Action diff --git a/actions/suggest/__tests__/get-inputs.test.ts b/actions/suggest/__tests__/get-inputs.test.ts deleted file mode 100644 index 86de1ba..0000000 --- a/actions/suggest/__tests__/get-inputs.test.ts +++ /dev/null @@ -1,74 +0,0 @@ -// import * as main from '../src/main'; -import {Inputs} from '../src/interfaces'; -import {showInputs, getInputs} from '../src/get-inputs'; -import os from 'os'; -import fs from 'fs'; -import yaml from 'js-yaml'; - -beforeEach(() => { - jest.resetModules(); - process.stdout.write = jest.fn(); - - // eslint-disable-next-line @typescript-eslint/no-explicit-any - const doc: any = yaml.safeLoad(fs.readFileSync(__dirname + '/../../../action.yml', 'utf8')); - Object.keys(doc.inputs).forEach(name => { - const envVar = `INPUT_${name.replace(/ /g, '_').toUpperCase()}`; - process.env[envVar] = doc.inputs[name]['default']; - }); -}); - -afterEach(() => { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - const doc: any = yaml.safeLoad(fs.readFileSync(__dirname + '/../../../action.yml', 'utf8')); - Object.keys(doc.inputs).forEach(name => { - const envVar = `INPUT_${name.replace(/ /g, '_').toUpperCase()}`; - console.debug(`delete ${envVar}\t${process.env[envVar]}`); - delete process.env[envVar]; - }); -}); - -// Assert that process.stdout.write calls called only with the given arguments. -// cf. https://github.com/actions/toolkit/blob/8b0300129f08728419263b016de8630f1d426d5f/packages/core/__tests__/core.test.ts -function assertWriteCalls(calls: string[]): void { - expect(process.stdout.write).toHaveBeenCalledTimes(calls.length); - - for (let i = 0; i < calls.length; i++) { - expect(process.stdout.write).toHaveBeenNthCalledWith(i + 1, calls[i]); - } -} - -function getInputsLog(inps: Inputs): string { - return `\ -[INFO] Language: ${inps.Language} -`; -} - -describe('showInputs()', () => { - // eslint-disable-next-line jest/expect-expect - test('print all inputs', () => { - const inps: Inputs = getInputs(); - showInputs(inps); - - const test = getInputsLog(inps); - assertWriteCalls([`${test}${os.EOL}`]); - }); -}); - -describe('getInputs()', () => { - test('get default inputs', () => { - const inps: Inputs = getInputs(); - - expect(inps.GithubToken).toMatch('${{ github.token }}'); - expect(inps.Language).toMatch('en'); - }); - - test('get spec inputs', () => { - process.env['INPUT_GITHUB_TOKEN'] = 'xxx'; - process.env['INPUT_LANGUAGE'] = 'ja'; - - const inps: Inputs = getInputs(); - - expect(inps.GithubToken).toMatch('xxx'); - expect(inps.Language).toMatch('ja'); - }); -}); diff --git a/actions/suggest/src/get-inputs.ts b/actions/suggest/src/get-inputs.ts deleted file mode 100644 index eec8884..0000000 --- a/actions/suggest/src/get-inputs.ts +++ /dev/null @@ -1,17 +0,0 @@ -import * as core from '@actions/core'; -import {Inputs} from './interfaces'; - -export function showInputs(inps: Inputs): void { - core.info(`\ -[INFO] Language: ${inps.Language} -`); -} - -export function getInputs(): Inputs { - const inps: Inputs = { - GithubToken: core.getInput('github_token'), - Language: core.getInput('language') - }; - - return inps; -} diff --git a/actions/suggest/src/interfaces.ts b/actions/suggest/src/interfaces.ts deleted file mode 100644 index b3b7be4..0000000 --- a/actions/suggest/src/interfaces.ts +++ /dev/null @@ -1,9 +0,0 @@ -export interface Inputs { - readonly GithubToken: string; - readonly Language: string; -} - -export interface CmdResult { - exitcode: number; - output: string; -} diff --git a/actions/suggest/src/main.ts b/actions/suggest/src/main.ts deleted file mode 100644 index 6ef0206..0000000 --- a/actions/suggest/src/main.ts +++ /dev/null @@ -1,27 +0,0 @@ -import {context} from '@actions/github'; -import * as core from '@actions/core'; -// import * as exec from '@actions/exec'; -// import * as github from '@actions/github'; -import {Inputs} from './interfaces'; -import {showInputs, getInputs} from './get-inputs'; - -export async function run(): Promise { - try { - const inps: Inputs = getInputs(); - core.startGroup('Dump inputs'); - showInputs(inps); - core.endGroup(); - - if (core.isDebug()) { - core.startGroup('Debug: dump context'); - console.log(context); - core.endGroup(); - } - - core.info('[INFO] Action successfully completed'); - - return; - } catch (e) { - throw new Error(e.message); - } -} diff --git a/actions/train/README.md b/actions/train/README.md deleted file mode 100644 index bd59abb..0000000 --- a/actions/train/README.md +++ /dev/null @@ -1,9 +0,0 @@ - - -**Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)* - -- [Train Action](#train-action) - - - -## Train Action diff --git a/actions/train/action.yml b/actions/train/action.yml deleted file mode 100644 index 369182a..0000000 --- a/actions/train/action.yml +++ /dev/null @@ -1,37 +0,0 @@ -name: 'Model training sub-action of Suggest Related Links Action' -description: 'A GitHub Action to suggest related or similar issues, documents, and links. Based on the power of NLP and fastText. Model training sub-action' -author: 'peaceiris' -runs: - using: 'node12' - main: 'dist/index.js' -branding: - icon: 'link' - color: 'orange' -inputs: - github_token: - description: 'Set a generated GITHUB_TOKEN for posting a comment.' - default: ${{ github.token }} - required: false - language: - description: 'Set a target language.' - default: 'en' - required: false - model: - description: 'Set a model for suggesting.' - default: 'fasttext' - required: false - repository: - description: 'Set a repository name of issue source. (e.g. peaceiris/actions-gh-pages)' - default: ${{ github.repository }} - required: false - custom_training_data: - description: 'Set paths to JSON files including custom training data.' - default: '' - required: false - train_issues: - description: 'Set this to true to train issue data.' - default: true - required: false -# outputs: -# json_path: -# description: 'A path to a JSON file that contains results.' diff --git a/actions/train/src/index.ts b/actions/train/src/index.ts deleted file mode 100644 index 0133eaf..0000000 --- a/actions/train/src/index.ts +++ /dev/null @@ -1,10 +0,0 @@ -import * as core from '@actions/core'; -import * as main from './main'; - -(async (): Promise => { - try { - await main.run(); - } catch (e) { - core.setFailed(`Action failed with "${e.message}"`); - } -})(); diff --git a/package.json b/package.json index bada92a..7a0a6f7 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "actions-suggest-related-links", "version": "0.4.0", "description": "A GitHub Action to suggest related or similar issues, documents, and links. Based on the power of NLP and fastText.", - "main": "lib/index.js", + "main": "actions/dist/index.js", "engines": { "node": ">=12.18.3", "npm": ">=6.14.8" @@ -13,9 +13,7 @@ "lint": "eslint ./actions/**/*.ts", "lint:fix": "eslint --fix ./actions/**/*.ts", "test": "jest --coverage --verbose --detectOpenHandles", - "build": "npm run build:suggest && npm run build:train", - "build:suggest": "ncc build ./actions/suggest/src/index.ts -o ./actions/suggest/dist --minify", - "build:train": "ncc build ./actions/train/src/index.ts -o ./actions/train/dist --minify", + "build": "ncc build ./actions/src/index.ts -o ./actions/dist --minify", "tsc": "tsc", "fmt": "prettier --write **/*.ts", "fmt:check": "prettier --check **/*.ts", diff --git a/release.sh b/release.sh index ef5c87d..15b765f 100755 --- a/release.sh +++ b/release.sh @@ -50,14 +50,12 @@ fi npm ci npm run build -git add ./actions/suggest/dist/index.js -git add ./actions/train/dist/index.js +git add ./actions/dist/index.js git commit -m "chore(release): Add build assets" npm run release -- --release-as "${RELEASE_TYPE}" --preset eslint -git rm ./actions/suggest/dist/index.js -git rm ./actions/train/dist/index.js +git rm ./actions/dist/index.js git commit -m "chore(release): Remove build assets [skip ci]" if [ "${CURRENT_BRANCH}" != "${DEFAULT_BRANCH}" ]; then