Obsidian 插件的 Github Action 设置

来源 obsidian-tracker

代码

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
name: Release # action 的名字

on:
  push:
    tags:
      - "*" # 在 push tags 后触发 action
  
jobs:
  build:
    permissions: 
      contents: write # 给 action 写的权限
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
    - name: Use Node.js
      uses: actions/setup-node@v4
      with:
        node-version: '20.x'
    - name: Build
      run: | # 这两句是核心,安装包&构建程序
        yarn
        yarn run build
    - name: Release with Notes
      uses: softprops/action-gh-release@v1 # 使用了 gh-release 的包,快速生成文件
      with:
        files: |
          main.js
          manifest.json
          styles.css          
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

gh-relsease

如何发布

  • git pushremote,注意 package.jsonmanifest.json 中的版本。
  • 使用命令 git tag x.x.x 来标记 tag
  • git push origin x.x.x (仅 push 一个版本) 或 git push --tags (push 所有版本)

注意事项

如果出现 403 错误,可能是没有给 workflow 写入的权限。可以在 settings - Actions - General - workflow permissions 中进行修改,修改为 Read and write permissions。

构建的过程是这样的(以推送 0.0.1 版本为例):

  • 推送到云端后,生成了一个 0.0.1 的分支。
  • 接下来 actions 会根据这个 0.0.1 的分支构建。
  • 如果说你更改了 main 的 workflow,这个 0.0.1 的分支仍然会按照之前的方式进行构建。

因此如果修改了 workflow,记得删除相应的分支再重新 push tags(20多次 commit 修改 release.yml 的痛)。

删除分支的方式:git tag -d x.x.x

0%