drawio-desktop AppVeyor:Windows环境的持续集成

drawio-desktop AppVeyor:Windows环境的持续集成

【免费下载链接】drawio-desktop Official electron build of draw.io 【免费下载链接】drawio-desktop 项目地址: https://gitcode.com/GitHub_Trending/dr/drawio-desktop

引言

你是否曾经为跨平台Electron应用的Windows构建而头疼?手动构建、签名、发布流程繁琐且容易出错。drawio-desktop项目通过AppVeyor实现了Windows环境的自动化持续集成(Continuous Integration,CI),让构建过程变得简单高效。本文将深入解析drawio-desktop的AppVeyor配置,帮助你掌握Windows环境CI的最佳实践。

通过本文,你将学到:

  • AppVeyor配置文件的详细解析
  • Electron应用Windows构建的完整流程
  • 代码签名和自动发布的实现方法
  • 多架构构建的最佳实践
  • 环境变量和敏感信息的安全管理

AppVeyor配置详解

drawio-desktop的appveyor.yml文件定义了完整的Windows构建流程:

version: 1.0.{build}

platform:
  - x64

cache:

init:
  - git config --global core.autocrlf input

clone_script:
  - cmd: git clone --depth=1 -q --branch=%APPVEYOR_REPO_BRANCH% https://github.com/%APPVEYOR_REPO_NAME%.git %APPVEYOR_BUILD_FOLDER%
  - cmd: cd %APPVEYOR_BUILD_FOLDER%
  - cmd: git checkout -qf %APPVEYOR_REPO_COMMIT%
  - ps: (gc .\.gitmodules) -replace 'git@github.com:','https://github.com/' | Out-File -encoding ASCII .gitmodules
  - cmd: git submodule update --init --recursive

install:
  - ps: Install-Product node 10 x64
  - npm install -g yarn
  - yarn install
  - cd drawio/src/main/webapp
  - yarn install
  - cd ../..

before_build:

build_script:
  - yarn run sync
  - yarn run release-win
  - yarn run sync disableUpdate
  - yarn run release-appx

test: off

配置解析

mermaid

构建流程深度解析

1. 环境初始化阶段

# Git配置:统一换行符处理
git config --global core.autocrlf input

# 代码克隆:使用浅克隆提高效率
git clone --depth=1 -q --branch=%APPVEYOR_REPO_BRANCH% \
https://github.com/%APPVEYOR_REPO_NAME%.git %APPVEYOR_BUILD_FOLDER%

# 子模块处理:确保依赖完整
git submodule update --init --recursive

2. 依赖安装阶段

# Node.js环境安装
Install-Product node 10 x64

# Yarn包管理器安装
npm install -g yarn

# 主项目依赖安装
yarn install

# 子项目依赖安装(drawio webapp)
cd drawio/src/main/webapp
yarn install
cd ../..

3. 构建执行阶段

# 版本同步:从子模块获取版本信息
yarn run sync

# Windows应用构建
yarn run release-win

# 禁用更新功能
yarn run sync disableUpdate

# AppX包构建(Windows应用商店)
yarn run release-appx

多目标构建配置

drawio-desktop支持多种Windows安装包格式,通过不同的electron-builder配置文件实现:

NSIS安装程序配置(electron-builder-win.json)

{
  "win": {
    "target": [
      {
        "target": "nsis",
        "arch": ["x64"]
      },
      {
        "target": "msi",
        "arch": ["x64"]
      }
    ]
  },
  "nsis": {
    "artifactName": "${productName}-${version}-windows-installer.${ext}",
    "oneClick": false,
    "perMachine": true,
    "allowToChangeInstallationDirectory": true
  }
}

AppX应用包配置(electron-builder-appx.json)

{
  "win": {
    "target": [
      {
        "target": "appx",
        "arch": ["x64"]
      }
    ]
  },
  "appx": {
    "displayName": "draw.io Diagrams",
    "publisherDisplayName": "JGraph Ltd",
    "identityName": "draw.io.draw.ioDiagrams"
  }
}

版本管理策略

drawio-desktop采用独特的版本同步机制,通过sync.cjs脚本实现:

const fs = require('fs')
const path = require('path')

// 从drawio子模块读取版本信息
let ver = fs.readFileSync(path.join(__dirname, 'drawio', 'VERSION'), 'utf8')

// 更新主项目的package.json版本
let pj = require('./package.json')
pj.version = ver
fs.writeFileSync('./package.json', JSON.stringify(pj, null, 2), 'utf8')

// 控制更新功能
fs.writeFileSync('./src/main/disableUpdate.js', 
  'export function disableUpdate() { return ' + 
  (process.argv[2] == 'disableUpdate'? 'true' : 'false') + ';}', 'utf8')

代码签名与安全

Windows应用分发需要代码签名,drawio-desktop通过环境变量实现安全的签名配置:

环境变量用途示例值
CSC_LINK代码签名证书base64编码的.p12文件
CSC_KEY_PASSWORD证书密码加密密码
GH_TOKENGitHub发布令牌github_pat_xxx

签名证书类型对比

证书类型信任级别CI支持成本
EV代码签名证书最高不支持(需要物理USB)
标准代码签名证书中等支持中等
无签名最低-免费

构建产物管理

构建完成后,AppVeyor会自动创建发布包并上传到GitHub Releases:

mermaid

最佳实践总结

1. 环境配置最佳实践

# 使用特定的Node.js版本
install:
  - ps: Install-Product node 10 x64

# 全局安装构建工具
- npm install -g yarn

# 分层依赖安装
- yarn install
- cd submodule/path && yarn install

2. 构建优化策略

# 使用缓存加速构建
cache:
  - node_modules
  - '%USERPROFILE%\.electron'

# 并行构建配置
matrix:
  fast_finish: true

3. 安全敏感信息处理

# 通过环境变量传递敏感信息
$env:CSC_LINK = [Convert]::ToBase64String([IO.File]::ReadAllBytes("cert.p12"))
$env:CSC_KEY_PASSWORD = "your_password"
$env:GH_TOKEN = "github_token"

常见问题与解决方案

问题1:构建超时

解决方案:优化依赖安装,使用缓存机制

cache:
  - node_modules -> package.json
  - '%USERPROFILE%\.electron'

问题2:代码签名失败

解决方案:确保证书格式正确且环境变量设置正确

# 验证证书格式
certutil -decode encoded.txt cert.p12

问题3:子模块更新失败

解决方案:使用GitHub HTTPS协议替代SSH

clone_script:
  - ps: (gc .\.gitmodules) -replace 'git@github.com:','https://github.com/' | Out-File -encoding ASCII .gitmodules

性能优化建议

构建时间优化

优化策略效果实施方法
浅克隆减少克隆时间--depth=1
依赖缓存避免重复安装AppVeyor缓存
并行构建提高构建效率矩阵构建

包大小优化

{
  "files": [
    "**/*",
    "!**/WEB-INF{,/**}"  // 排除不必要的文件
  ],
  "asar": true,          // 使用ASAR打包
  "npmRebuild": false    // 避免重复构建原生模块
}

扩展功能实现

多架构支持

虽然当前配置只支持x64架构,但可以扩展支持ARM64:

{
  "win": {
    "target": [
      {
        "target": "nsis",
        "arch": ["x64", "arm64"]
      }
    ]
  }
}

自动化测试集成

test_script:
  - yarn test
  - yarn run test:e2e

after_test:
  - yarn run coverage

总结

drawio-desktop的AppVeyor配置展示了Windows环境Electron应用CI/CD的最佳实践。通过合理的配置分层、安全敏感信息处理、多目标构建支持,实现了高效可靠的自动化构建流程。

关键要点:

  • 使用环境变量管理敏感信息
  • 采用版本同步机制确保一致性
  • 支持多种安装包格式
  • 实现安全的代码签名流程
  • 优化构建性能和包大小

这套配置方案不仅适用于drawio-desktop,也可以作为其他Electron项目的参考模板,帮助开发者构建高质量的Windows桌面应用。

【免费下载链接】drawio-desktop Official electron build of draw.io 【免费下载链接】drawio-desktop 项目地址: https://gitcode.com/GitHub_Trending/dr/drawio-desktop

创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值