This commit is contained in:
Opportunity
2020-07-07 21:53:34 +08:00
Unverified
parent 70a1af86e5
commit bff8013f3d
18 changed files with 200 additions and 181 deletions
+29 -37
View File
@@ -1,42 +1,34 @@
root: true root: true
parser: "@typescript-eslint/parser" parser: '@typescript-eslint/parser'
parserOptions: parserOptions:
project: tsconfig.json project: tsconfig.json
plugins: plugins:
- "@typescript-eslint" - '@typescript-eslint'
- prettier - prettier
extends: extends:
- eslint:recommended - eslint:recommended
- plugin:@typescript-eslint/eslint-recommended - plugin:@typescript-eslint/eslint-recommended
- plugin:@typescript-eslint/recommended - plugin:@typescript-eslint/recommended
- plugin:@typescript-eslint/recommended-requiring-type-checking - plugin:@typescript-eslint/recommended-requiring-type-checking
- prettier/@typescript-eslint - prettier/@typescript-eslint
- plugin:prettier/recommended - plugin:prettier/recommended
rules: rules:
"prettier/prettier": 'prettier/prettier': [1]
- 1 '@typescript-eslint/array-type': [1, { default: array-simple }]
- singleQuote: true '@typescript-eslint/explicit-function-return-type': [2, { allowExpressions: true }]
trailingComma: all '@typescript-eslint/no-extra-non-null-assertion': [2]
tabWidth: 4 '@typescript-eslint/no-extraneous-class': [1, { allowWithDecorator: true, allowStaticOnly: true }]
endOfLine: lf '@typescript-eslint/no-floating-promises': [1]
printWidth: 160 '@typescript-eslint/no-parameter-properties':
- usePrettierrc: false - 1
"@typescript-eslint/array-type": [1, { default: array-simple }] - allows:
"@typescript-eslint/explicit-function-return-type": - protected readonly
[2, { allowExpressions: true }] - private readonly
"@typescript-eslint/no-extra-non-null-assertion": [2] - public readonly
"@typescript-eslint/no-extraneous-class": [1, { allowWithDecorator: true, allowStaticOnly: true }] - readonly
"@typescript-eslint/no-floating-promises": [1] '@typescript-eslint/no-throw-literal': [2]
"@typescript-eslint/no-parameter-properties": 'no-unused-vars': [0]
- 1 '@typescript-eslint/prefer-for-of': [1]
- allows: '@typescript-eslint/prefer-function-type': [1]
- protected readonly '@typescript-eslint/prefer-nullish-coalescing': [1]
- private readonly '@typescript-eslint/prefer-optional-chain': [1]
- 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]
+22 -22
View File
@@ -1,28 +1,28 @@
name: checkin name: checkin
on: on:
- push - push
- pull_request - pull_request
jobs: jobs:
checkin: checkin:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v1 - uses: actions/checkout@v1
- name: install - name: install
run: yarn install run: yarn install
- name: build - name: build
run: yarn build run: yarn build
- name: test - name: test
run: yarn test run: yarn test
- name: release - name: release
run: yarn release run: yarn release
- name: "check for uncommitted changes" - name: 'check for uncommitted changes'
# Ensure no changes # Ensure no changes
run: | run: |
git add . git add .
if ! git diff --cached --color=always --exit-code -- . ':!node_modules'; then 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." echo "::error::Found changed files after build. Please run 'yarn release' and check in all changes."
exit 1 exit 1
fi fi
+17 -17
View File
@@ -1,24 +1,24 @@
name: test name: test
on: on:
- push - push
jobs: jobs:
build: build:
strategy: strategy:
matrix: matrix:
os: [ubuntu-latest, windows-latest, macOS-latest] os: [ubuntu-latest, windows-latest, macOS-latest]
version: [latest, branch@master] version: [latest, branch@master]
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
steps: steps:
- uses: actions/checkout@v1 - uses: actions/checkout@v1
- uses: xmake-io/github-action-setup-xmake@master - uses: xmake-io/github-action-setup-xmake@master
with: with:
xmake-version: ${{ matrix.version }} xmake-version: ${{ matrix.version }}
- name: Run tests - name: Run tests
run: | run: |
xmake create -P test xmake create -P test
xmake build -P test xmake build -P test
xmake run -P test xmake run -P test
+5
View File
@@ -0,0 +1,5 @@
singleQuote: true
trailingComma: all
tabWidth: 4
endOfLine: lf
printWidth: 120
+17 -23
View File
@@ -1,25 +1,19 @@
{ {
"npm.packageManager": "yarn", "npm.packageManager": "yarn",
"eslint.validate": [ "eslint.validate": ["javascript", "javascriptreact", "typescript", "typescriptreact", "vue"],
"javascript", "eslint.enable": true,
"javascriptreact", "files.autoSave": "off",
"typescript", "eslint.format.enable": true,
"typescriptreact", "editor.tabSize": 4,
"vue" "editor.formatOnSave": false,
], "editor.codeActionsOnSave": {
"eslint.enable": true, "source.fixAll.eslint": true
"files.autoSave": "off", },
"eslint.format.enable": true, "[typescript]": {
"editor.tabSize": 4, "editor.defaultFormatter": "dbaeumer.vscode-eslint"
"editor.formatOnSave": false, },
"editor.codeActionsOnSave": { "[javascript]": {
"source.fixAll.eslint": true "editor.defaultFormatter": "dbaeumer.vscode-eslint"
}, },
"[typescript]": { "git.ignoreLimitWarning": true
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
},
"[javascript]": {
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
},
"git.ignoreLimitWarning": true
} }
+5 -4
View File
@@ -1,4 +1,5 @@
# GitHub Action - Setup xmake # 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) [![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) [![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 ```yml
uses: xmake-io/github-action-setup-xmake@v1 uses: xmake-io/github-action-setup-xmake@v1
with: with:
xmake-version: latest xmake-version: latest
``` ```
Use specified version: Use specified version:
@@ -23,7 +24,7 @@ Use specified version:
```yml ```yml
uses: xmake-io/github-action-setup-xmake@v1 uses: xmake-io/github-action-setup-xmake@v1
with: with:
xmake-version: '2.3.1' xmake-version: '2.3.1'
``` ```
Use specified branch: Use specified branch:
@@ -31,7 +32,7 @@ Use specified branch:
```yml ```yml
uses: xmake-io/github-action-setup-xmake@v1 uses: xmake-io/github-action-setup-xmake@v1
with: with:
xmake-version: branch@master xmake-version: branch@master
``` ```
Use semver: Use semver:
@@ -39,5 +40,5 @@ Use semver:
```yml ```yml
uses: xmake-io/github-action-setup-xmake@v1 uses: xmake-io/github-action-setup-xmake@v1
with: with:
xmake-version: '>=2.2.6 <=2.3.1' xmake-version: '>=2.2.6 <=2.3.1'
``` ```
+8 -9
View File
@@ -2,16 +2,15 @@ name: setup xmake
description: Set up a xmake environment and add it to the PATH description: Set up a xmake environment and add it to the PATH
author: OpportunityLiu author: OpportunityLiu
branding: branding:
icon: play icon: play
color: green color: green
inputs: inputs:
xmake-version: xmake-version:
required: true required: true
default: latest default: latest
description: The version to use. Should be a semver range or 'latest'. Or use [{repository}#]branch@{branch_name} to select a branch. description: The version to use. Should be a semver range or 'latest'. Or use [{repository}#]branch@{branch_name} to select a branch.
runs: runs:
using: 'node12' using: 'node12'
main: 'dist/index.js' main: 'dist/index.js'
+2 -1
View File
@@ -137,7 +137,8 @@ async function selectVersion(version) {
if (!ret) { if (!ret) {
throw new Error(`Invalid input xmake-version ${core.getInput('xmake-version')}`); 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; return ret;
} }
exports.selectVersion = selectVersion; exports.selectVersion = selectVersion;
+5 -1
View File
@@ -45,7 +45,11 @@ async function winInstall(version) {
const url = getInstallerUrl(version); const url = getInstallerUrl(version);
core.info(`downloading from ${url}`); core.info(`downloading from ${url}`);
const file = await toolCache.downloadTool(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); await io.mv(file, exe);
core.info(`downloaded to ${exe}`); core.info(`downloaded to ${exe}`);
return exe; return exe;
+2 -2
View File
@@ -1,4 +1,4 @@
module.exports = { module.exports = {
preset: 'ts-jest', preset: 'ts-jest',
testEnvironment: 'node', testEnvironment: 'node',
}; };
+41 -41
View File
@@ -1,43 +1,43 @@
{ {
"name": "github-action-setup-xmake", "name": "github-action-setup-xmake",
"version": "1.0.3", "version": "1.0.3",
"description": "Set up your GitHub Actions workflow with a specific version of xmake", "description": "Set up your GitHub Actions workflow with a specific version of xmake",
"main": "dist/index.js", "main": "dist/index.js",
"author": "OpportunityLiu", "author": "OpportunityLiu",
"license": "GPL-3.0-or-later", "license": "GPL-3.0-or-later",
"repository": "https://github.com/xmake-io/github-action-setup-xmake.git", "repository": "https://github.com/xmake-io/github-action-setup-xmake.git",
"homepage": "https://github.com/xmake-io/github-action-setup-xmake", "homepage": "https://github.com/xmake-io/github-action-setup-xmake",
"scripts": { "scripts": {
"init": "yarn install && yarn clean", "init": "yarn install && yarn clean",
"watch": "tsc --watch", "watch": "tsc --watch",
"build": "tsc --build ./tsconfig.build.json", "build": "tsc --build ./tsconfig.build.json",
"rebuild": "yarn clean && yarn build", "rebuild": "yarn clean && yarn build",
"clean": "rimraf dist", "clean": "rimraf dist",
"lint": "eslint --fix src/**/*.ts", "lint": "eslint --fix src/**/*.ts",
"test": "jest", "test": "jest",
"release": "yarn rebuild && yarn lint && yarn install --production --no-bin-links" "release": "yarn rebuild && yarn lint && yarn install --production --no-bin-links"
}, },
"dependencies": { "dependencies": {
"@actions/core": "^1.2.4", "@actions/core": "^1.2.4",
"@actions/exec": "^1.0.4", "@actions/exec": "^1.0.4",
"@actions/io": "^1.0.1", "@actions/io": "^1.0.1",
"@actions/tool-cache": "^1.5.5", "@actions/tool-cache": "^1.5.5",
"semver": "^7.3.2" "semver": "^7.3.2"
}, },
"devDependencies": { "devDependencies": {
"@types/jest": "^26.0.3", "@types/jest": "^26.0.3",
"@types/node": "^14.0.14", "@types/node": "^14.0.14",
"@types/semver": "^7.3.1", "@types/semver": "^7.3.1",
"@typescript-eslint/eslint-plugin": "^3.4.0", "@typescript-eslint/eslint-plugin": "^3.4.0",
"@typescript-eslint/parser": "^3.4.0", "@typescript-eslint/parser": "^3.4.0",
"eslint": "^7.3.1", "eslint": "^7.3.1",
"eslint-config-prettier": "^6.11.0", "eslint-config-prettier": "^6.11.0",
"eslint-plugin-prettier": "^3.1.4", "eslint-plugin-prettier": "^3.1.4",
"jest": "^26.1.0", "jest": "^26.1.0",
"prettier": "^2.0.5", "prettier": "^2.0.5",
"rimraf": "^3.0.2", "rimraf": "^3.0.2",
"ts-jest": "^26.1.1", "ts-jest": "^26.1.1",
"type-fest": "^0.16.0", "type-fest": "^0.16.0",
"typescript": "^3.9.5" "typescript": "^3.9.5"
} }
} }
+5 -1
View File
@@ -49,7 +49,11 @@ export async function create(repo: Repo, ref: Sha): Promise<string> {
await io.mkdirP(opt.cwd); await io.mkdirP(opt.cwd);
await exec('git', ['init'], opt); await exec('git', ['init'], opt);
await exec('git', ['remote', 'add', 'origin', repoUrl(repo)], 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', ['checkout', ref], opt);
await exec('git', ['submodule', 'update', '--init', '--recursive'], opt); await exec('git', ['submodule', 'update', '--init', '--recursive'], opt);
return opt.cwd; return opt.cwd;
+3 -1
View File
@@ -12,7 +12,9 @@ export async function unixInstall(version: Version): Promise<void> {
const ver = version.version; const ver = version.version;
let toolDir = toolCache.find('xmake', ver); let toolDir = toolCache.find('xmake', ver);
if (!toolDir) { 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 () => { toolDir = await core.group(`install xmake ${String(version)}`, async () => {
await exec('make', ['build'], { cwd: sourceDir }); await exec('make', ['build'], { cwd: sourceDir });
const binDir = path.join(os.tmpdir(), `xmake-${version.sha}`); const binDir = path.join(os.tmpdir(), `xmake-${version.sha}`);
+6 -2
View File
@@ -284,7 +284,9 @@ describe('selectVersion', () => {
it('should throw for no matched', async () => { 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('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('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 () => { it('should return correct version for given', async () => {
await expect(selectVersion('v1.0.1')).resolves.toEqual({ await expect(selectVersion('v1.0.1')).resolves.toEqual({
@@ -330,7 +332,9 @@ describe('selectVersion', () => {
}); });
it('should throw invalid pr', async () => { 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 () => { it('should return branch of sha', async () => {
+14 -3
View File
@@ -15,7 +15,13 @@ async function getVersions(repo: Repo): Promise<RefDic> {
} }
class VersionImpl implements Version { 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; this.#string = toString;
} }
readonly #string: string; readonly #string: string;
@@ -80,7 +86,9 @@ async function selectSha(repo: Repo, sha: string): Promise<Version> {
return selectPr(repo, Number.parseInt(pr)); 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<Version> { export async function selectVersion(version?: string): Promise<Version> {
@@ -123,6 +131,9 @@ export async function selectVersion(version?: string): Promise<Version> {
if (!ret) { if (!ret) {
throw new Error(`Invalid input xmake-version ${core.getInput('xmake-version')}`); 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; return ret;
} }
+5 -1
View File
@@ -45,7 +45,11 @@ export async function winInstall(version: Version): Promise<void> {
const url = getInstallerUrl(version); const url = getInstallerUrl(version);
core.info(`downloading from ${url}`); core.info(`downloading from ${url}`);
const file = await toolCache.downloadTool(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); await io.mv(file, exe);
core.info(`downloaded to ${exe}`); core.info(`downloaded to ${exe}`);
return exe; return exe;
+1 -3
View File
@@ -1,6 +1,4 @@
{ {
"extends": "./tsconfig.json", "extends": "./tsconfig.json",
"exclude": [ "exclude": ["**/*.spec.ts"]
"**/*.spec.ts"
]
} }
+10 -10
View File
@@ -1,12 +1,12 @@
{ {
"include": ["src/**/*"], "include": ["src/**/*"],
"compileOnSave": true, "compileOnSave": true,
"compilerOptions": { "compilerOptions": {
"strict": true, "strict": true,
"moduleResolution": "node", "moduleResolution": "node",
"module": "commonjs", "module": "commonjs",
"target": "es2018", "target": "es2018",
"outDir": "dist", "outDir": "dist",
"types": ["node", "jest"] "types": ["node", "jest"]
} }
} }