From 9aed821057cedda6608c9b4a1d1d74bc64a477b0 Mon Sep 17 00:00:00 2001 From: a632079 Date: Mon, 7 Sep 2020 20:42:26 +0800 Subject: [PATCH 1/3] build: support github actions --- .github/node.js.yml | 52 +++++++++++++++++++++++++++++++++++++++++++++ package.json | 3 ++- 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 .github/node.js.yml diff --git a/.github/node.js.yml b/.github/node.js.yml new file mode 100644 index 0000000..f2829a0 --- /dev/null +++ b/.github/node.js.yml @@ -0,0 +1,52 @@ +name: Node.js CI + +on: + pull_request: + branches: [ master ] + push: + branches: [ master ] +jobs: + test: + name: Test + runs-on: ubuntu-latest + strategy: + matrix: + node-version: [12.x, 14.x] + steps: + - uses: actions/checkout@v2 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + - uses: actions/cache@v2 + with: + path: ~/.npm + key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-node- + - run: npm ci + name: Install dependencies + - name: Test + run: npm test + lint: + name: Lint + runs-on: ubuntu-latest + strategy: + matrix: + node-version: [14.x] + steps: + - uses: actions/checkout@v2 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + - uses: actions/cache@v2 + with: + path: ~/.npm + key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-node- + - run: npm ci + name: Install dependencies + - name: Lint + run: npm lint \ No newline at end of file diff --git a/package.json b/package.json index 2c70471..ac6d015 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,8 @@ "scripts": { "start": "node app.js", "test": "mocha -r intelli-espower-loader -t 20000 app.test.js --exit", - "lint-fix": "eslint --fix --ext .js app.js module/ util/ test/ " + "lint": "eslint **/*.{js,ts}", + "lint-fix": "eslint --fix **/*.{js,ts}" }, "keywords": [ "网易云音乐", From bc71f537ad54f9b1eaa3716dd24bb3b23b7b899a Mon Sep 17 00:00:00 2001 From: a632079 Date: Mon, 7 Sep 2020 20:55:04 +0800 Subject: [PATCH 2/3] test: use env variable variables in login.test.js --- .github/node.js.yml | 4 ++++ test/login.test.js | 7 ++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/.github/node.js.yml b/.github/node.js.yml index f2829a0..33ceadd 100644 --- a/.github/node.js.yml +++ b/.github/node.js.yml @@ -26,6 +26,10 @@ jobs: ${{ runner.os }}-node- - run: npm ci name: Install dependencies + - name: Set Test Env + run: | + export NCM_API_TEST_LOGIN_PHONE=${{ secrets.NCM_API_TEST_LOGIN_PHONE }} + export NCM_API_TEST_LOGIN_PASSWORD=${{ secrets.NCM_API_TEST_LOGIN_PASSWORD }} - name: Test run: npm test lint: diff --git a/test/login.test.js b/test/login.test.js index 0855afe..a9e5a42 100644 --- a/test/login.test.js +++ b/test/login.test.js @@ -3,12 +3,13 @@ const request = require('request') const host = global.host || 'http://localhost:3000' console.log('注意: 测试登录需在 test/login.test.js 中填写账号密码!!!'); - +const phone = '' +const password = '' describe('测试登录是否正常', () => { it('手机登录 code 应该等于200', done => { const qs = { - phone: phone, - password: password + phone: process.env.NCM_API_TEST_LOGIN_PHONE || phone || '', + password: process.env.NCM_API_TEST_LOGIN_PASSWORD || password || '' } request.get({url: `${host}/login/cellphone`, qs: qs}, (err, res, body) => { From 4e074b1061e53f1ab5484557c1246b76e1c57e9a Mon Sep 17 00:00:00 2001 From: a632079 Date: Mon, 7 Sep 2020 20:59:43 +0800 Subject: [PATCH 3/3] fix: correct ci file path --- .github/{ => workflows}/node.js.yml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/{ => workflows}/node.js.yml (100%) diff --git a/.github/node.js.yml b/.github/workflows/node.js.yml similarity index 100% rename from .github/node.js.yml rename to .github/workflows/node.js.yml