You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在GitHub Actions云端自动化运行electron-windows-store

问题

我希望通过GitHub Actions工作流,使用electron-windows-store将Electron应用自动化打包为Windows Store的.appx包,目前该流程为手动执行,想确认是否可完全云端自动化。

当前手动打包流程

  • 从electron-builder等工具获取.appx输出文件;
  • 在本地使用管理员权限的PowerShell会话运行以下命令:
electron-windows-store --input-directory C:\Path\To\YourApp\dist\win-unpacked `
                       --output-directory C:\Path\To\YourApp\Output `
                       --package-version 1.0.0.0 `
                       --package-name YourApp `
                       --package-display-name 'YourApp' `
                       --publisher-display-name 'YourPublisher' `
                       --identity-name YourPublisher.Identity `
                       -a C:\Path\To\YourApp\Resources\
  • 将签名后的.appx包上传至Windows Store。

我已在GitHub Actions中实现了macOS和Linux平台的签名与发布全自动化,但Windows流程需本地操作,不确定能否云端完成。以下是构想的GitHub Actions工作流草稿:

name: Build Windows Store App

on:
  push:
    branches:
      - main

jobs:
  build:
    runs-on: windows-latest

    steps:
      - name: Checkout code
        uses: actions/checkout@v3

      - name: Set up Node.js
        uses: actions/setup-node@v3
        with:
          node-version: 18

      - name: Install dependencies
        run: npm install

      - name: Run electron-windows-store
        run: electron-windows-store --input-directory ./dist/win-unpacked `
                                    --output-directory ./output `
                                    --package-version 1.0.0.0 `
                                    --package-name YourApp `
                                    --package-display-name 'YourApp' `
                                    --publisher-display-name 'YourPublisher' `
                                    --identity-name YourPublisher.Identity

我的应用已通过@electron/packager打包至win-unpacked目录,当前全程在本地管理员权限PowerShell中执行。请问能否在GitHub Actions的windows-latest运行器中,完全自动化electron-windows-store的打包、签名及生成.appx文件的流程,无需人工干预?

回答

完全可以在GitHub Actions的windows-latest运行器上实现全自动化流程,无需本地人工干预,但需要注意以下几个关键细节:

1. 管理员权限无需额外配置

GitHub Actions的Windows运行器默认以管理员权限启动PowerShell,直接执行electron-windows-store命令即可,不需要手动设置权限。

2. 配置Windows Store签名证书

要生成符合Windows Store要求的签名.appx包,需将**Windows Store发布证书(.pfx文件)**以Base64编码形式上传为GitHub Secrets,然后在工作流中导入证书:

- name: Import Windows Store Certificate
  run: |
    $certPath = "./store-cert.pfx"
    echo "${{ secrets.WINDOWS_STORE_PFX_BASE64 }}" | base64 --decode > $certPath
    Import-PfxCertificate -FilePath $certPath -CertStoreLocation Cert:\CurrentUser\My -Password (ConvertTo-SecureString "${{ secrets.CERT_PASSWORD }}" -AsPlainText -Force)

之后在electron-windows-store命令中通过--certificate-path和--certificate-password参数指定证书信息即可。

3. 补充依赖安装步骤

你的工作流草稿缺少electron-windows-store的安装步骤,需添加:

- name: Install electron-windows-store
  run: npm install -g electron-windows-store

另外,electron-windows-store依赖的Windows SDK已经预装在windows-latest镜像中,无需额外安装。

4. 动态设置版本号(可选)

不要硬编码--package-version,可以通过Git标签或环境变量动态生成版本号,比如:

- name: Get Version
  id: get_version
  run: echo "version=$(git describe --tags --abbrev=0 | sed 's/v//')" >> $GITHUB_OUTPUT

- name: Run electron-windows-store
  run: electron-windows-store --input-directory ./dist/win-unpacked `
                              --output-directory ./output `
                              --package-version ${{ steps.get_version.outputs.version }}.0 `
                              --package-name YourApp `
                              --package-display-name 'YourApp' `
                              --publisher-display-name 'YourPublisher' `
                              --identity-name YourPublisher.Identity `
                              --certificate-path ./store-cert.pfx `
                              --certificate-password "${{ secrets.CERT_PASSWORD }}"

5. 自动上传至Windows Store(可选)

可通过官方msstore-cli或第三方Action将生成的.appx包自动上传至Windows Store,只需将Windows Store的API凭据(客户端ID、密钥等)配置为GitHub Secrets即可。

完善后的工作流示例

name: Build & Publish Windows Store App

on:
  push:
    branches:
      - main

jobs:
  build-publish:
    runs-on: windows-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v3

      - name: Set up Node.js
        uses: actions/setup-node@v3
        with:
          node-version: 18

      - name: Install dependencies
        run: npm install

      - name: Package app with electron-packager
        run: npx electron-packager . YourApp --platform=win32 --arch=x64 --out=dist

      - name: Install electron-windows-store
        run: npm install -g electron-windows-store

      - name: Import Windows Store Certificate
        run: |
          $certPath = "./store-cert.pfx"
          echo "${{ secrets.WINDOWS_STORE_PFX_BASE64 }}" | base64 --decode > $certPath
          Import-PfxCertificate -FilePath $certPath -CertStoreLocation Cert:\CurrentUser\My -Password (ConvertTo-SecureString "${{ secrets.CERT_PASSWORD }}" -AsPlainText -Force)

      - name: Generate .appx package
        run: electron-windows-store --input-directory ./dist/YourApp-win32-x64 `
                                    --output-directory ./output `
                                    --package-version 1.0.0.0 `
                                    --package-name YourApp `
                                    --package-display-name 'YourApp' `
                                    --publisher-display-name 'YourPublisher' `
                                    --identity-name YourPublisher.Identity `
                                    -a ./Resources/

      - name: Upload to Windows Store
        uses: actions/upload-to-ms-store@v1
        with:
          client-id: ${{ secrets.MS_STORE_CLIENT_ID }}
          client-secret: ${{ secrets.MS_STORE_CLIENT_SECRET }}
          tenant-id: ${{ secrets.MS_STORE_TENANT_ID }}
          app-id: ${{ secrets.MS_STORE_APP_ID }}
          package-path: ./output/YourApp.appx

内容的提问来源于stack exchange,提问作者Martin

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 15:55:59