记录一个Github仓库发布的workflow模板:
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 name: Release on: release: types: [published ] jobs: build-and-release: runs-on: ubuntu-latest strategy: matrix: os: [ubuntu-latest , macos-latest , windows-latest ] arch: [x64 , arm64 ] steps: - name: Checkout Code uses: actions/checkout@v3 - name: Setup Node.js uses: actions/setup-node@v3 with: node-version: '16' - name: Install Dependencies run: | npm install - name: Build for ${{ matrix.os }} on ${{ matrix.arch }} run: | npm run build -- --arch=${{ matrix.arch }} - name: Create Archive run: | mkdir -p release tar -czvf release/myapp-${{ matrix.os }}-${{ matrix.arch }}.tar.gz dist/ - name: Upload Artifact uses: actions/upload-artifact@v3 with: name: myapp-${{ matrix.os }}-${{ matrix.arch }} path: release/myapp-${{ matrix.os }}-${{ matrix.arch }}.tar.gz create-release: needs: build-and-release runs-on: ubuntu-latest steps: - name: Checkout Code uses: actions/checkout@v3 - name: Upload Release Assets uses: actions/upload-release-asset@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: upload_url: ${{ github.event.release.upload_url }} asset_path: release/myapp-*.tar.gz asset_name: myapp-${{ matrix.os }}-${{ matrix.arch }}.tar.gz asset_content_type: application/gzip
这里要注意的是第63行的upload_url: ${{ github.event.release.upload_url }}
,它表示只有当你在仓库中按照以下图片步骤进行,才会触发,如果直接在ci中强制运行这个文件,这里会报错:You have to provide a GITHUB_TOKEN or GH_PAT 等。