Forráskód Böngészése

chore: github action 优化

mrabit 2 éve
szülő
commit
22dd667b55
5 módosított fájl, 28 hozzáadás és 24 törlés
  1. 11 17
      .github/workflows/workflow.yml
  2. 11 2
      api.js
  3. 3 3
      config.example.js
  4. 2 1
      index.js
  5. 1 1
      indexAction.js

+ 11 - 17
.github/workflows/workflow.yml

@@ -1,39 +1,33 @@
 name: ci
 
 on:
+  workflow_dispatch:
   push:
     branches:
       - master
   schedule:
-    - cron: '00 01-23 * * *' # 每个小时运行一次
+    - cron: '*/20 * * * *' # 每20分钟执行一次
 
 env: # 设置环境变量
   TZ: Asia/Shanghai # 时区(设置时区可使页面中的`最近更新时间`使用时区时间)
 
-jobs: 
+jobs:
   execute:
     runs-on: ubuntu-latest # 运行在虚拟机环境ubuntu-latest
-    environment: test
     steps:
-      - name: Checkout
-        uses: actions/checkout@v1 # 作用:检出仓库,获取源码。
-      - name: set-go-environment
+      - uses: actions/checkout@v2 # 作用:检出仓库,获取源码。
+      - name: Install Node 14
         uses: actions/setup-node@v3 # uses 和 run 不能同时在一个step使用
         with:
           node-version: 14
-      - name: build
-        run: |
-          npm i -g pm2
-          npm install
-          echo 'build success'
+      - name: Install packages
+        run: npm install
       - name: run
+        env:
+          MT_COOKIE: ${{ secrets.MT_COOKIE }}
+          MT_DEVICEID: ${{ secrets.MT_DEVICEID }}
+          BARK: ${{ secrets.BARK }}
         run: |
           cp config.example.js config.js
-          echo '${{secrets.MT_DEVICEID}}'
-          sed -i 's/$COOKIE/${{secrets.MT_COOKIE}}/g' config.js
-          sed -i 's/$DEVICEID/${{secrets.MT_DEVICEID}}/g' ./config.js
           chmod 777 indexAction.js
           node ./indexAction.js
-
-      
-

+ 11 - 2
api.js

@@ -6,9 +6,16 @@ require('./console')
 
 dayjs.extend(duration)
 
-let cookies = typeof cookie === 'object' ? cookie : [cookie]
+let cookies = (typeof cookie === 'object' ? cookie : cookie.split('\n')).filter(
+  v => v
+)
 let currentCookie = ''
 
+if (!cookies.length) {
+  console.log('未配置cookie, 程序终止')
+  process.exit(1)
+}
+
 const xmTravelAxios = axios.create()
 const barkAxios = axios.create()
 
@@ -20,7 +27,9 @@ xmTravelAxios.interceptors.request.use(req => {
   req.headers['MT-Request-ID'] = getGUID()
   req.headers[
     'User-Agent'
-  ] = `Mozilla/5.0 (iPhone; CPU iPhone OS 14_8 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 moutaiapp/1.2.1 device-id/${deviceId}`
+  ] = `Mozilla/5.0 (iPhone; CPU iPhone OS 14_8 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 moutaiapp/1.2.1 device-id/${
+    deviceId || 'moutaiapp'
+  }`
   req.headers['Referer'] =
     'https://h5.moutai519.com.cn/gux/game/main?appConfig=2_1_2'
   req.headers['Cookie'] = currentCookie

+ 3 - 3
config.example.js

@@ -1,6 +1,6 @@
 module.exports = {
   baseURL: 'https://h5.moutai519.com.cn/game/',
-  cookie: ['$COOKIE'], // 小茅运 H5 页面请求 cookie
-  deviceId: '$DEVICEID', // User-Agent 里的 deviceId 值
-  bark: '' // bark 推送地址
+  cookie: process.env.MT_COOKIE || [''], // 小茅运 H5 页面请求 cookie
+  deviceId: process.env.MT_DEVICEID || '', // User-Agent 里的 deviceId 值
+  bark: process.env.BARK || '' // bark 推送地址
 }

+ 2 - 1
index.js

@@ -1,4 +1,5 @@
 const schedule = require('node-schedule')
 const api = require('./api')
+
 api.init()
-schedule.scheduleJob('00 */30 * * * *', api.init) // 每半小时
+schedule.scheduleJob('00 */20 * * * *', api.init) // 每20分钟执行一次

+ 1 - 1
indexAction.js

@@ -1,3 +1,3 @@
 const api = require('./api')
-// console.log(index)
+
 api.init()