From bff8013f3dc3163de9b7765f420d610f85923fce Mon Sep 17 00:00:00 2001 From: Opportunity Date: Tue, 7 Jul 2020 21:53:34 +0800 Subject: [PATCH] format --- .eslintrc.yml | 66 +++++++++++++--------------- .github/workflows/checkin.yml | 44 +++++++++---------- .github/workflows/test.yml | 34 +++++++-------- .prettierrc.yml | 5 +++ .vscode/settings.json | 42 ++++++++---------- README.md | 9 ++-- action.yml | 17 ++++---- dist/versions.js | 3 +- dist/win-install.js | 6 ++- jest.config.js | 6 +-- package.json | 82 +++++++++++++++++------------------ src/git.ts | 6 ++- src/unix-install.ts | 4 +- src/version.spec.ts | 8 +++- src/versions.ts | 17 ++++++-- src/win-install.ts | 6 ++- tsconfig.build.json | 6 +-- tsconfig.json | 20 ++++----- 18 files changed, 200 insertions(+), 181 deletions(-) create mode 100644 .prettierrc.yml diff --git a/.eslintrc.yml b/.eslintrc.yml index 86c7296..6537d4b 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -1,42 +1,34 @@ root: true -parser: "@typescript-eslint/parser" +parser: '@typescript-eslint/parser' parserOptions: - project: tsconfig.json + project: tsconfig.json plugins: - - "@typescript-eslint" - - prettier + - '@typescript-eslint' + - prettier extends: - - eslint:recommended - - plugin:@typescript-eslint/eslint-recommended - - plugin:@typescript-eslint/recommended - - plugin:@typescript-eslint/recommended-requiring-type-checking - - prettier/@typescript-eslint - - plugin:prettier/recommended + - eslint:recommended + - plugin:@typescript-eslint/eslint-recommended + - plugin:@typescript-eslint/recommended + - plugin:@typescript-eslint/recommended-requiring-type-checking + - prettier/@typescript-eslint + - plugin:prettier/recommended rules: - "prettier/prettier": - - 1 - - singleQuote: true - trailingComma: all - tabWidth: 4 - endOfLine: lf - printWidth: 160 - - usePrettierrc: false - "@typescript-eslint/array-type": [1, { default: array-simple }] - "@typescript-eslint/explicit-function-return-type": - [2, { allowExpressions: true }] - "@typescript-eslint/no-extra-non-null-assertion": [2] - "@typescript-eslint/no-extraneous-class": [1, { allowWithDecorator: true, allowStaticOnly: true }] - "@typescript-eslint/no-floating-promises": [1] - "@typescript-eslint/no-parameter-properties": - - 1 - - allows: - - protected readonly - - private readonly - - public readonly - - readonly - "@typescript-eslint/no-throw-literal": [2] - "no-unused-vars": [0] - "@typescript-eslint/prefer-for-of": [1] - "@typescript-eslint/prefer-function-type": [1] - "@typescript-eslint/prefer-nullish-coalescing": [1] - "@typescript-eslint/prefer-optional-chain": [1] \ No newline at end of file + 'prettier/prettier': [1] + '@typescript-eslint/array-type': [1, { default: array-simple }] + '@typescript-eslint/explicit-function-return-type': [2, { allowExpressions: true }] + '@typescript-eslint/no-extra-non-null-assertion': [2] + '@typescript-eslint/no-extraneous-class': [1, { allowWithDecorator: true, allowStaticOnly: true }] + '@typescript-eslint/no-floating-promises': [1] + '@typescript-eslint/no-parameter-properties': + - 1 + - allows: + - protected readonly + - private readonly + - public readonly + - readonly + '@typescript-eslint/no-throw-literal': [2] + 'no-unused-vars': [0] + '@typescript-eslint/prefer-for-of': [1] + '@typescript-eslint/prefer-function-type': [1] + '@typescript-eslint/prefer-nullish-coalescing': [1] + '@typescript-eslint/prefer-optional-chain': [1] diff --git a/.github/workflows/checkin.yml b/.github/workflows/checkin.yml index e87d95e..8e5c5f3 100644 --- a/.github/workflows/checkin.yml +++ b/.github/workflows/checkin.yml @@ -1,28 +1,28 @@ name: checkin on: - - push - - pull_request + - push + - pull_request jobs: - checkin: - runs-on: ubuntu-latest + checkin: + runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v1 - - name: install - run: yarn install - - name: build - run: yarn build - - name: test - run: yarn test - - name: release - run: yarn release - - name: "check for uncommitted changes" - # Ensure no changes - run: | - git add . - if ! git diff --cached --color=always --exit-code -- . ':!node_modules'; then - echo "::error::Found changed files after build. Please run 'yarn release' and check in all changes." - exit 1 - fi \ No newline at end of file + steps: + - uses: actions/checkout@v1 + - name: install + run: yarn install + - name: build + run: yarn build + - name: test + run: yarn test + - name: release + run: yarn release + - name: 'check for uncommitted changes' + # Ensure no changes + run: | + git add . + if ! git diff --cached --color=always --exit-code -- . ':!node_modules'; then + echo "::error::Found changed files after build. Please run 'yarn release' and check in all changes." + exit 1 + fi diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b7085ae..3cc2ba7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,24 +1,24 @@ name: test on: - - push + - push jobs: - build: - strategy: - matrix: - os: [ubuntu-latest, windows-latest, macOS-latest] - version: [latest, branch@master] + build: + strategy: + matrix: + os: [ubuntu-latest, windows-latest, macOS-latest] + version: [latest, branch@master] - runs-on: ${{ matrix.os }} + runs-on: ${{ matrix.os }} - steps: - - uses: actions/checkout@v1 - - uses: xmake-io/github-action-setup-xmake@master - with: - xmake-version: ${{ matrix.version }} - - name: Run tests - run: | - xmake create -P test - xmake build -P test - xmake run -P test + steps: + - uses: actions/checkout@v1 + - uses: xmake-io/github-action-setup-xmake@master + with: + xmake-version: ${{ matrix.version }} + - name: Run tests + run: | + xmake create -P test + xmake build -P test + xmake run -P test diff --git a/.prettierrc.yml b/.prettierrc.yml new file mode 100644 index 0000000..8760205 --- /dev/null +++ b/.prettierrc.yml @@ -0,0 +1,5 @@ +singleQuote: true +trailingComma: all +tabWidth: 4 +endOfLine: lf +printWidth: 120 diff --git a/.vscode/settings.json b/.vscode/settings.json index 7d91096..72d4575 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,25 +1,19 @@ { - "npm.packageManager": "yarn", - "eslint.validate": [ - "javascript", - "javascriptreact", - "typescript", - "typescriptreact", - "vue" - ], - "eslint.enable": true, - "files.autoSave": "off", - "eslint.format.enable": true, - "editor.tabSize": 4, - "editor.formatOnSave": false, - "editor.codeActionsOnSave": { - "source.fixAll.eslint": true - }, - "[typescript]": { - "editor.defaultFormatter": "dbaeumer.vscode-eslint" - }, - "[javascript]": { - "editor.defaultFormatter": "dbaeumer.vscode-eslint" - }, - "git.ignoreLimitWarning": true -} \ No newline at end of file + "npm.packageManager": "yarn", + "eslint.validate": ["javascript", "javascriptreact", "typescript", "typescriptreact", "vue"], + "eslint.enable": true, + "files.autoSave": "off", + "eslint.format.enable": true, + "editor.tabSize": 4, + "editor.formatOnSave": false, + "editor.codeActionsOnSave": { + "source.fixAll.eslint": true + }, + "[typescript]": { + "editor.defaultFormatter": "dbaeumer.vscode-eslint" + }, + "[javascript]": { + "editor.defaultFormatter": "dbaeumer.vscode-eslint" + }, + "git.ignoreLimitWarning": true +} diff --git a/README.md b/README.md index ddb5195..00a7c20 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ # GitHub Action - Setup xmake + [![Build status](https://github.com/xmake-io/github-action-setup-xmake/workflows/test/badge.svg)](https://github.com/xmake-io/github-action-setup-xmake/actions) [![GitHub release (latest by date)](https://img.shields.io/github/v/release/xmake-io/github-action-setup-xmake)](https://github.com/marketplace/actions/setup-xmake) @@ -15,7 +16,7 @@ Use latest version: ```yml uses: xmake-io/github-action-setup-xmake@v1 with: - xmake-version: latest + xmake-version: latest ``` Use specified version: @@ -23,7 +24,7 @@ Use specified version: ```yml uses: xmake-io/github-action-setup-xmake@v1 with: - xmake-version: '2.3.1' + xmake-version: '2.3.1' ``` Use specified branch: @@ -31,7 +32,7 @@ Use specified branch: ```yml uses: xmake-io/github-action-setup-xmake@v1 with: - xmake-version: branch@master + xmake-version: branch@master ``` Use semver: @@ -39,5 +40,5 @@ Use semver: ```yml uses: xmake-io/github-action-setup-xmake@v1 with: - xmake-version: '>=2.2.6 <=2.3.1' + xmake-version: '>=2.2.6 <=2.3.1' ``` diff --git a/action.yml b/action.yml index 19fa9a0..5b41687 100644 --- a/action.yml +++ b/action.yml @@ -2,16 +2,15 @@ name: setup xmake description: Set up a xmake environment and add it to the PATH author: OpportunityLiu branding: - icon: play - color: green + icon: play + color: green inputs: - xmake-version: - required: true - default: latest - description: The version to use. Should be a semver range or 'latest'. Or use [{repository}#]branch@{branch_name} to select a branch. + xmake-version: + required: true + default: latest + description: The version to use. Should be a semver range or 'latest'. Or use [{repository}#]branch@{branch_name} to select a branch. runs: - using: 'node12' - main: 'dist/index.js' - \ No newline at end of file + using: 'node12' + main: 'dist/index.js' diff --git a/dist/versions.js b/dist/versions.js index 8a567f9..f043df2 100644 --- a/dist/versions.js +++ b/dist/versions.js @@ -137,7 +137,8 @@ async function selectVersion(version) { if (!ret) { throw new Error(`Invalid input xmake-version ${core.getInput('xmake-version')}`); } - core.info(`Selected xmake ${String(ret)} (commit: ${ret.sha.substr(0, 8)})` + (repo !== DEFAULT_REPO ? ` of ${repo}` : '')); + core.info(`Selected xmake ${String(ret)} (commit: ${ret.sha.substr(0, 8)})` + + (repo !== DEFAULT_REPO ? ` of ${repo}` : '')); return ret; } exports.selectVersion = selectVersion; diff --git a/dist/win-install.js b/dist/win-install.js index 145c5c7..0b9148a 100644 --- a/dist/win-install.js +++ b/dist/win-install.js @@ -45,7 +45,11 @@ async function winInstall(version) { const url = getInstallerUrl(version); core.info(`downloading from ${url}`); const file = await toolCache.downloadTool(url); - const exe = path.format({ ...path.parse(file), ext: '.exe', base: undefined }); + const exe = path.format({ + ...path.parse(file), + ext: '.exe', + base: undefined, + }); await io.mv(file, exe); core.info(`downloaded to ${exe}`); return exe; diff --git a/jest.config.js b/jest.config.js index 91a2d2c..6d6062b 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,4 +1,4 @@ module.exports = { - preset: 'ts-jest', - testEnvironment: 'node', -}; \ No newline at end of file + preset: 'ts-jest', + testEnvironment: 'node', +}; diff --git a/package.json b/package.json index d710270..64f7168 100644 --- a/package.json +++ b/package.json @@ -1,43 +1,43 @@ { - "name": "github-action-setup-xmake", - "version": "1.0.3", - "description": "Set up your GitHub Actions workflow with a specific version of xmake", - "main": "dist/index.js", - "author": "OpportunityLiu", - "license": "GPL-3.0-or-later", - "repository": "https://github.com/xmake-io/github-action-setup-xmake.git", - "homepage": "https://github.com/xmake-io/github-action-setup-xmake", - "scripts": { - "init": "yarn install && yarn clean", - "watch": "tsc --watch", - "build": "tsc --build ./tsconfig.build.json", - "rebuild": "yarn clean && yarn build", - "clean": "rimraf dist", - "lint": "eslint --fix src/**/*.ts", - "test": "jest", - "release": "yarn rebuild && yarn lint && yarn install --production --no-bin-links" - }, - "dependencies": { - "@actions/core": "^1.2.4", - "@actions/exec": "^1.0.4", - "@actions/io": "^1.0.1", - "@actions/tool-cache": "^1.5.5", - "semver": "^7.3.2" - }, - "devDependencies": { - "@types/jest": "^26.0.3", - "@types/node": "^14.0.14", - "@types/semver": "^7.3.1", - "@typescript-eslint/eslint-plugin": "^3.4.0", - "@typescript-eslint/parser": "^3.4.0", - "eslint": "^7.3.1", - "eslint-config-prettier": "^6.11.0", - "eslint-plugin-prettier": "^3.1.4", - "jest": "^26.1.0", - "prettier": "^2.0.5", - "rimraf": "^3.0.2", - "ts-jest": "^26.1.1", - "type-fest": "^0.16.0", - "typescript": "^3.9.5" - } + "name": "github-action-setup-xmake", + "version": "1.0.3", + "description": "Set up your GitHub Actions workflow with a specific version of xmake", + "main": "dist/index.js", + "author": "OpportunityLiu", + "license": "GPL-3.0-or-later", + "repository": "https://github.com/xmake-io/github-action-setup-xmake.git", + "homepage": "https://github.com/xmake-io/github-action-setup-xmake", + "scripts": { + "init": "yarn install && yarn clean", + "watch": "tsc --watch", + "build": "tsc --build ./tsconfig.build.json", + "rebuild": "yarn clean && yarn build", + "clean": "rimraf dist", + "lint": "eslint --fix src/**/*.ts", + "test": "jest", + "release": "yarn rebuild && yarn lint && yarn install --production --no-bin-links" + }, + "dependencies": { + "@actions/core": "^1.2.4", + "@actions/exec": "^1.0.4", + "@actions/io": "^1.0.1", + "@actions/tool-cache": "^1.5.5", + "semver": "^7.3.2" + }, + "devDependencies": { + "@types/jest": "^26.0.3", + "@types/node": "^14.0.14", + "@types/semver": "^7.3.1", + "@typescript-eslint/eslint-plugin": "^3.4.0", + "@typescript-eslint/parser": "^3.4.0", + "eslint": "^7.3.1", + "eslint-config-prettier": "^6.11.0", + "eslint-plugin-prettier": "^3.1.4", + "jest": "^26.1.0", + "prettier": "^2.0.5", + "rimraf": "^3.0.2", + "ts-jest": "^26.1.1", + "type-fest": "^0.16.0", + "typescript": "^3.9.5" + } } diff --git a/src/git.ts b/src/git.ts index af25943..d4fc116 100644 --- a/src/git.ts +++ b/src/git.ts @@ -49,7 +49,11 @@ export async function create(repo: Repo, ref: Sha): Promise { await io.mkdirP(opt.cwd); await exec('git', ['init'], opt); await exec('git', ['remote', 'add', 'origin', repoUrl(repo)], opt); - await exec('git', ['fetch', 'origin', '+refs/pull/*:refs/remotes/origin/pull/*', '+refs/heads/*:refs/remotes/origin/*'], opt); + await exec( + 'git', + ['fetch', 'origin', '+refs/pull/*:refs/remotes/origin/pull/*', '+refs/heads/*:refs/remotes/origin/*'], + opt, + ); await exec('git', ['checkout', ref], opt); await exec('git', ['submodule', 'update', '--init', '--recursive'], opt); return opt.cwd; diff --git a/src/unix-install.ts b/src/unix-install.ts index 0fb9d18..021c112 100644 --- a/src/unix-install.ts +++ b/src/unix-install.ts @@ -12,7 +12,9 @@ export async function unixInstall(version: Version): Promise { const ver = version.version; let toolDir = toolCache.find('xmake', ver); if (!toolDir) { - const sourceDir = await core.group(`download xmake ${String(version)}`, () => git.create(version.repo, version.sha)); + const sourceDir = await core.group(`download xmake ${String(version)}`, () => + git.create(version.repo, version.sha), + ); toolDir = await core.group(`install xmake ${String(version)}`, async () => { await exec('make', ['build'], { cwd: sourceDir }); const binDir = path.join(os.tmpdir(), `xmake-${version.sha}`); diff --git a/src/version.spec.ts b/src/version.spec.ts index f2266bf..2604bb2 100644 --- a/src/version.spec.ts +++ b/src/version.spec.ts @@ -284,7 +284,9 @@ describe('selectVersion', () => { it('should throw for no matched', async () => { await expect(selectVersion('0.2.3')).rejects.toThrowError('No matched releases of xmake-version 0.2.3'); await expect(selectVersion('v0.2.3')).rejects.toThrowError('No matched releases of xmake-version 0.2.3'); - await expect(selectVersion('<0.2.3 > 0.1')).rejects.toThrowError('No matched releases of xmake-version <0.2.3 >=0.2.0'); + await expect(selectVersion('<0.2.3 > 0.1')).rejects.toThrowError( + 'No matched releases of xmake-version <0.2.3 >=0.2.0', + ); }); it('should return correct version for given', async () => { await expect(selectVersion('v1.0.1')).resolves.toEqual({ @@ -330,7 +332,9 @@ describe('selectVersion', () => { }); it('should throw invalid pr', async () => { - await expect(selectVersion('pr@xxx')).rejects.toThrowError('Invalid pull requrest xxx, should be a positive integer'); + await expect(selectVersion('pr@xxx')).rejects.toThrowError( + 'Invalid pull requrest xxx, should be a positive integer', + ); }); it('should return branch of sha', async () => { diff --git a/src/versions.ts b/src/versions.ts index a767ccf..57aae99 100644 --- a/src/versions.ts +++ b/src/versions.ts @@ -15,7 +15,13 @@ async function getVersions(repo: Repo): Promise { } class VersionImpl implements Version { - constructor(readonly repo: Repo, readonly version: string, readonly sha: Sha, readonly type: Version['type'], toString: string) { + constructor( + readonly repo: Repo, + readonly version: string, + readonly sha: Sha, + readonly type: Version['type'], + toString: string, + ) { this.#string = toString; } readonly #string: string; @@ -80,7 +86,9 @@ async function selectSha(repo: Repo, sha: string): Promise { return selectPr(repo, Number.parseInt(pr)); } } - return Promise.resolve(new VersionImpl(repo, `sha#${shaValue}`, shaValue, 'sha', `commit ${shaValue.substr(0, 8)}`)); + return Promise.resolve( + new VersionImpl(repo, `sha#${shaValue}`, shaValue, 'sha', `commit ${shaValue.substr(0, 8)}`), + ); } export async function selectVersion(version?: string): Promise { @@ -123,6 +131,9 @@ export async function selectVersion(version?: string): Promise { if (!ret) { throw new Error(`Invalid input xmake-version ${core.getInput('xmake-version')}`); } - core.info(`Selected xmake ${String(ret)} (commit: ${ret.sha.substr(0, 8)})` + (repo !== DEFAULT_REPO ? ` of ${repo}` : '')); + core.info( + `Selected xmake ${String(ret)} (commit: ${ret.sha.substr(0, 8)})` + + (repo !== DEFAULT_REPO ? ` of ${repo}` : ''), + ); return ret; } diff --git a/src/win-install.ts b/src/win-install.ts index c03e77f..e39db02 100644 --- a/src/win-install.ts +++ b/src/win-install.ts @@ -45,7 +45,11 @@ export async function winInstall(version: Version): Promise { const url = getInstallerUrl(version); core.info(`downloading from ${url}`); const file = await toolCache.downloadTool(url); - const exe = path.format({ ...path.parse(file), ext: '.exe', base: undefined }); + const exe = path.format({ + ...path.parse(file), + ext: '.exe', + base: undefined, + }); await io.mv(file, exe); core.info(`downloaded to ${exe}`); return exe; diff --git a/tsconfig.build.json b/tsconfig.build.json index 8f8618c..1b72219 100644 --- a/tsconfig.build.json +++ b/tsconfig.build.json @@ -1,6 +1,4 @@ { "extends": "./tsconfig.json", - "exclude": [ - "**/*.spec.ts" - ] -} \ No newline at end of file + "exclude": ["**/*.spec.ts"] +} diff --git a/tsconfig.json b/tsconfig.json index f46493a..37f97cb 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,12 +1,12 @@ { - "include": ["src/**/*"], - "compileOnSave": true, - "compilerOptions": { - "strict": true, - "moduleResolution": "node", - "module": "commonjs", - "target": "es2018", - "outDir": "dist", - "types": ["node", "jest"] - } + "include": ["src/**/*"], + "compileOnSave": true, + "compilerOptions": { + "strict": true, + "moduleResolution": "node", + "module": "commonjs", + "target": "es2018", + "outDir": "dist", + "types": ["node", "jest"] + } }