electron-build.yml 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. name: Build Electron App
  2. on:
  3. push:
  4. tags:
  5. - '*' # Triggers on version tags like v1.0.0
  6. workflow_dispatch: # Allows manual triggering
  7. jobs:
  8. build:
  9. strategy:
  10. matrix:
  11. # os: [macos-latest, windows-latest]
  12. os: [windows-latest]
  13. runs-on: ${{ matrix.os }}
  14. defaults:
  15. run:
  16. shell: bash
  17. steps:
  18. - name: Checkout code
  19. uses: actions/checkout@v4
  20. with:
  21. fetch-depth: 0
  22. - name: Setup Bun
  23. uses: oven-sh/setup-bun@v2
  24. with:
  25. bun-version: latest
  26. - name: Setup Node.js
  27. uses: actions/setup-node@v4
  28. with:
  29. node-version: '20'
  30. - name: Setup Go
  31. uses: actions/setup-go@v5
  32. with:
  33. go-version: '>=1.25.1'
  34. - name: Build frontend
  35. env:
  36. CI: ""
  37. NODE_OPTIONS: "--max-old-space-size=4096"
  38. run: |
  39. cd web
  40. bun install
  41. DISABLE_ESLINT_PLUGIN='true' VITE_REACT_APP_VERSION=$(git describe --tags) bun run build
  42. cd ..
  43. # - name: Build Go binary (macos/Linux)
  44. # if: runner.os != 'Windows'
  45. # run: |
  46. # go mod download
  47. # go build -ldflags "-s -w -X 'one-api/common.Version=$(git describe --tags)' -extldflags '-static'" -o new-api
  48. - name: Build Go binary (Windows)
  49. if: runner.os == 'Windows'
  50. run: |
  51. go mod download
  52. go build -ldflags "-s -w -X 'one-api/common.Version=$(git describe --tags)'" -o new-api.exe
  53. - name: Update Electron version
  54. run: |
  55. cd electron
  56. VERSION=$(git describe --tags)
  57. VERSION=${VERSION#v} # Remove 'v' prefix if present
  58. # Convert to valid semver: take first 3 components and convert rest to prerelease format
  59. # e.g., 0.9.3-patch.1 -> 0.9.3-patch.1
  60. if [[ $VERSION =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)(.*)$ ]]; then
  61. MAJOR=${BASH_REMATCH[1]}
  62. MINOR=${BASH_REMATCH[2]}
  63. PATCH=${BASH_REMATCH[3]}
  64. REST=${BASH_REMATCH[4]}
  65. VERSION="$MAJOR.$MINOR.$PATCH"
  66. # If there's extra content, append it without adding -dev
  67. if [[ -n "$REST" ]]; then
  68. VERSION="$VERSION$REST"
  69. fi
  70. fi
  71. npm version $VERSION --no-git-tag-version --allow-same-version
  72. - name: Install Electron dependencies
  73. run: |
  74. cd electron
  75. npm install
  76. # - name: Build Electron app (macOS)
  77. # if: runner.os == 'macOS'
  78. # run: |
  79. # cd electron
  80. # npm run build:mac
  81. # env:
  82. # CSC_IDENTITY_AUTO_DISCOVERY: false # Skip code signing
  83. - name: Build Electron app (Windows)
  84. if: runner.os == 'Windows'
  85. run: |
  86. cd electron
  87. npm run build:win
  88. # - name: Upload artifacts (macOS)
  89. # if: runner.os == 'macOS'
  90. # uses: actions/upload-artifact@v4
  91. # with:
  92. # name: macos-build
  93. # path: |
  94. # electron/dist/*.dmg
  95. # electron/dist/*.zip
  96. - name: Upload artifacts (Windows)
  97. if: runner.os == 'Windows'
  98. uses: actions/upload-artifact@v4
  99. with:
  100. name: windows-build
  101. path: |
  102. electron/dist/*.exe
  103. release:
  104. needs: build
  105. runs-on: ubuntu-latest
  106. if: startsWith(github.ref, 'refs/tags/')
  107. permissions:
  108. contents: write
  109. steps:
  110. - name: Download all artifacts
  111. uses: actions/download-artifact@v4
  112. - name: Create Release
  113. uses: softprops/action-gh-release@v2
  114. with:
  115. files: |
  116. windows-build/*
  117. draft: false
  118. prerelease: false
  119. overwrite_files: true
  120. env:
  121. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}