GitHub Action自动打包Electron APP
最近消失了一个月,忙公司的一个比较好玩的项目,所以博客断更了一个月。为了证明我是真的在忙,截一个图:
这个项目,后期要上Electron,所以就研究了下自动打包,这次就分享下自动打包的,如果对Action不明白的,可以看我之前的文章,我就不在详细的说了。
# Workflow's name
name: Build Electron App For Win/Mac
# Workflow's trigger
on:
push:
tags:
- "v*.*.*"
# Workflow's jobs
jobs:
# job's id
release:
# job's name
name: build and release electron app
# the type of machine to run the job on
runs-on: ${{ matrix.os }}
# create a build matrix for jobs
strategy:
fail-fast: false
matrix:
os: [windows-2019, macos-10.15]
# create steps
steps:
# step1: check out repository
- name: Check out git repository
uses: actions/checkout@v2
# step2: install node env
- name: Install Node.js
uses: actions/setup-node@v2-beta
# step3: npm install
- name: npm install
run: |
npm install
# step4: build app for mac/win
- name: build windows app
if: matrix.os == 'windows-2019'
run: |
npm run electron:build-win
env:
GH_TOKEN: ${{ secrets.ACCESS_TOKEN }}
- name: build mac app
if: matrix.os == 'macos-10.15'
run: |
npm run electron:build
env:
GH_TOKEN: ${{ secrets.ACCESS_TOKEN }}
# step5: cleanup artifacts in dist_electron
- name: cleanup artifacts for windows
if: matrix.os == 'windows-2019'
run: |
npx rimraf "dist_electron/!(*.exe)"
- name: cleanup artifacts for macosZ
if: matrix.os == 'macos-10.15'
run: |
npx rimraf "dist_electron/!(*.dmg)"
# step6: upload artifacts
- name: upload artifacts
uses: actions/upload-artifact@v2
with:
name: ${{ matrix.os }}
path: dist_electron
# step7: create release
- name: release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
files: "dist_electron/**"
env:
GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }}
注意这里的secrets.ACCESS_TOKEN
,需要自己去设置,代码有注释,就不用再详细说了。触发方式是提交代码的时候,添加tag标签。
然后,Releases里面就会生成对应的版本:
注意:空间是有限制的。
HttpError: 401 Unauthorized
注意看
secrets.ACCESS_TOKEN
,这个需要去配置,可以看我之前的文章。我配置了为啥总是
Error #1 --------------------------------------------------------------------------------
HttpError: 401 Unauthorized
{
"message": "Bad credentials",
"documentation_url": "https://docs.github.com/rest"
}
Headers: {
"server": "GitHub.com",
"date": "Mon, 26 Oct 2020 06:42:10 GMT",
"content-type": "application/json; charset=utf-8",
"content-length": "80",
"connection": "close",
"status": "401 Unauthorized",
"x-github-media-type": "github.v3; format=json",
"x-ratelimit-limit": "60",
"x-ratelimit-remaining": "59",
"x-ratelimit-reset": "1603698130",
"x-ratelimit-used": "1",
"access-control-expose-headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type,
不明觉厉。只会用github action部署hexo?