浏览代码

Merge pull request #82 from tofuliang/master

使用GitHub Action自动打包crx扩展,并利用GitHub进行自动更新
Alien-阿烈叔 5 年之前
父节点
当前提交
7c794bea27
共有 3 个文件被更改,包括 58 次插入3 次删除
  1. 32 0
      .github/workflows/build.yml
  2. 24 2
      gulpfile.js
  3. 2 1
      package.json

+ 32 - 0
.github/workflows/build.yml

@@ -0,0 +1,32 @@
+name: buildCrx
+on:
+  watch:
+    types: [started]
+jobs:
+  build:
+    runs-on: ubuntu-latest
+    steps:
+      - uses: actions/checkout@v2
+        with:
+          ref: stable #只打包stable分支
+      - name: Use Node.js
+        uses: actions/setup-node@v1
+        with:
+          node-version: '11.x'
+      - name: build
+        env:
+          PRIVATE_KEY: ${{ secrets.buildPem }}
+        run: |
+          npm install
+          npm install crx3
+          cat <<< $PRIVATE_KEY > ../build.pem
+          npm run crx
+      - name: Set git identity
+        run : |
+          git config --global user.email "[email protected]"
+          git config --global user.name "tofuliang"
+          rm -fr node_modules output package-lock.json
+          git add chrome/fehelper.crx chrome/update.xml
+          git checkout *
+          git commit -m "update crx"
+          git push

+ 24 - 2
gulpfile.js

@@ -22,7 +22,7 @@ let watchPath = require('gulp-watch-path');
 let gcallback = require('gulp-callback');
 let gcallback = require('gulp-callback');
 
 
 gulp.task('clean', () => {
 gulp.task('clean', () => {
-    return gulp.src('output', {read: false}).pipe(clean({force: true}));
+    return gulp.src(['output','chrome'], {read: false}).pipe(clean({force: true}));
 });
 });
 
 
 gulp.task('copy', () => {
 gulp.task('copy', () => {
@@ -155,6 +155,24 @@ gulp.task('zip', () => {
 
 
 });
 });
 
 
+// 打包成crx
+gulp.task('_crx',() => {
+    let pathOfMF = './output/apps/manifest.json';
+    let manifest = require(pathOfMF);
+    shell.exec('[ ! -d chrome ] && mkdir chrome');
+    shell.exec('cat output/fehelper.zip | npx crx3 -p ../build.pem -o chrome/fehelper.crx -x chrome/update.xml --appVersion '+manifest.version+' --crxURL https://raw.githubusercontent.com/'+manifest.author+'/FeHelper/master/fehelper.crx');
+
+    let size = fs.statSync('chrome/fehelper.crx').size;
+    size = pretty(size);
+
+    console.log('\n\nfehelper.crx 已打包完成!');
+    console.log('\n\n================================================================================');
+    console.log('    当前版本:', manifest.version, '\t文件大小:', size);
+    console.log('    提交到GitHub享受摆脱Chrome Webstore的自动更新吧');
+    console.log('================================================================================\n\n');
+
+});
+
 // 打包Firefox安装包
 // 打包Firefox安装包
 gulp.task('firefox', () => {
 gulp.task('firefox', () => {
     shell.exec('rm -rf output-firefox && cp -r output output-firefox && rm -rf output-firefox/fehelper.zip');
     shell.exec('rm -rf output-firefox && cp -r output output-firefox && rm -rf output-firefox/fehelper.zip');
@@ -202,6 +220,10 @@ gulp.task('default', ['clean'], () => {
     runSequence(['copy', 'css', 'js', 'html', 'json'], 'zip');
     runSequence(['copy', 'css', 'js', 'html', 'json'], 'zip');
 });
 });
 
 
+gulp.task('crx', ['clean'], () => {
+    runSequence(['copy', 'css', 'js', 'html', 'json'],'zip','_crx');
+});
+
 gulp.task('sync', () => {
 gulp.task('sync', () => {
     gulp.src('apps/**/*').pipe(gulp.dest('output/apps'));
     gulp.src('apps/**/*').pipe(gulp.dest('output/apps'));
 });
 });
@@ -214,4 +236,4 @@ gulp.task('watch', () => {
             console.log(new Date().toLocaleString(), '> 文件发生变化,已编译:', wp.srcPath);
             console.log(new Date().toLocaleString(), '> 文件发生变化,已编译:', wp.srcPath);
         }));
         }));
     });
     });
-});
+});

+ 2 - 1
package.json

@@ -23,7 +23,8 @@
   },
   },
   "scripts": {
   "scripts": {
     "watch": "gulp watch",
     "watch": "gulp watch",
-    "build": "gulp"
+    "build": "gulp",
+    "crx": "gulp crx"
   },
   },
   "repository": {
   "repository": {
     "type": "git",
     "type": "git",