homebrew.yml 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. name: Update Homebrew Formula
  2. on:
  3. release:
  4. types:
  5. - published
  6. jobs:
  7. update-homebrew:
  8. runs-on: ubuntu-latest
  9. if: github.event_name == 'release'
  10. steps:
  11. - name: Checkout
  12. uses: actions/checkout@v4
  13. - name: Get release info
  14. id: release
  15. run: |
  16. echo "tag_name=${{ github.event.release.tag_name }}" >> $GITHUB_OUTPUT
  17. echo "version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
  18. - name: Wait for release assets to be available
  19. run: |
  20. TAG_NAME="${{ steps.release.outputs.tag_name }}"
  21. # Function to check if a file exists
  22. check_file() {
  23. local url="$1"
  24. local filename="$2"
  25. echo "Checking if $filename is available..."
  26. if curl --output /dev/null --silent --head --fail "$url"; then
  27. echo "✓ $filename is available"
  28. return 0
  29. else
  30. echo "✗ $filename is not yet available"
  31. return 1
  32. fi
  33. }
  34. # List of files to check
  35. declare -a files=(
  36. "https://github.com/${{ github.repository }}/releases/download/$TAG_NAME/nginx-ui-macos-64.tar.gz"
  37. "https://github.com/${{ github.repository }}/releases/download/$TAG_NAME/nginx-ui-macos-arm64-v8a.tar.gz"
  38. "https://github.com/${{ github.repository }}/releases/download/$TAG_NAME/nginx-ui-linux-64.tar.gz"
  39. "https://github.com/${{ github.repository }}/releases/download/$TAG_NAME/nginx-ui-linux-arm64-v8a.tar.gz"
  40. )
  41. # Wait for all files to be available (max 10 minutes)
  42. max_attempts=60
  43. attempt=1
  44. while [ $attempt -le $max_attempts ]; do
  45. echo "Attempt $attempt/$max_attempts - Checking release assets..."
  46. all_available=true
  47. for url in "${files[@]}"; do
  48. filename=$(basename "$url")
  49. if ! check_file "$url" "$filename"; then
  50. all_available=false
  51. break
  52. fi
  53. done
  54. if [ "$all_available" = true ]; then
  55. echo "All release assets are available!"
  56. break
  57. fi
  58. if [ $attempt -eq $max_attempts ]; then
  59. echo "Timeout: Not all release assets are available after $max_attempts attempts"
  60. exit 1
  61. fi
  62. echo "Waiting 10 seconds before next check..."
  63. sleep 10
  64. ((attempt++))
  65. done
  66. - name: Download release assets and calculate SHA256 checksums
  67. id: checksums
  68. run: |
  69. VERSION="${{ steps.release.outputs.version }}"
  70. TAG_NAME="${{ steps.release.outputs.tag_name }}"
  71. # Download binary files from releases and calculate SHA256
  72. mkdir -p downloads
  73. # macOS Intel
  74. wget -O downloads/nginx-ui-macos-64.tar.gz "https://github.com/${{ github.repository }}/releases/download/$TAG_NAME/nginx-ui-macos-64.tar.gz"
  75. MACOS_INTEL_SHA256=$(sha256sum downloads/nginx-ui-macos-64.tar.gz | cut -d' ' -f1)
  76. # macOS ARM
  77. wget -O downloads/nginx-ui-macos-arm64-v8a.tar.gz "https://github.com/${{ github.repository }}/releases/download/$TAG_NAME/nginx-ui-macos-arm64-v8a.tar.gz"
  78. MACOS_ARM_SHA256=$(sha256sum downloads/nginx-ui-macos-arm64-v8a.tar.gz | cut -d' ' -f1)
  79. # Linux Intel
  80. wget -O downloads/nginx-ui-linux-64.tar.gz "https://github.com/${{ github.repository }}/releases/download/$TAG_NAME/nginx-ui-linux-64.tar.gz"
  81. LINUX_INTEL_SHA256=$(sha256sum downloads/nginx-ui-linux-64.tar.gz | cut -d' ' -f1)
  82. # Linux ARM
  83. wget -O downloads/nginx-ui-linux-arm64-v8a.tar.gz "https://github.com/${{ github.repository }}/releases/download/$TAG_NAME/nginx-ui-linux-arm64-v8a.tar.gz"
  84. LINUX_ARM_SHA256=$(sha256sum downloads/nginx-ui-linux-arm64-v8a.tar.gz | cut -d' ' -f1)
  85. echo "macos_intel_sha256=$MACOS_INTEL_SHA256" >> $GITHUB_OUTPUT
  86. echo "macos_arm_sha256=$MACOS_ARM_SHA256" >> $GITHUB_OUTPUT
  87. echo "linux_intel_sha256=$LINUX_INTEL_SHA256" >> $GITHUB_OUTPUT
  88. echo "linux_arm_sha256=$LINUX_ARM_SHA256" >> $GITHUB_OUTPUT
  89. - name: Generate Homebrew Formula
  90. id: formula
  91. run: |
  92. VERSION="${{ steps.release.outputs.version }}"
  93. cat > nginx-ui.rb << 'EOF'
  94. class NginxUi < Formula
  95. desc "Yet another Nginx Web UI"
  96. homepage "https://github.com/0xJacky/nginx-ui"
  97. version "${{ steps.release.outputs.version }}"
  98. license "AGPL-3.0"
  99. on_macos do
  100. on_intel do
  101. url "https://github.com/0xJacky/nginx-ui/releases/download/v#{version}/nginx-ui-macos-64.tar.gz"
  102. sha256 "${{ steps.checksums.outputs.macos_intel_sha256 }}"
  103. end
  104. on_arm do
  105. url "https://github.com/0xJacky/nginx-ui/releases/download/v#{version}/nginx-ui-macos-arm64-v8a.tar.gz"
  106. sha256 "${{ steps.checksums.outputs.macos_arm_sha256 }}"
  107. end
  108. end
  109. on_linux do
  110. on_intel do
  111. url "https://github.com/0xJacky/nginx-ui/releases/download/v#{version}/nginx-ui-linux-64.tar.gz"
  112. sha256 "${{ steps.checksums.outputs.linux_intel_sha256 }}"
  113. end
  114. on_arm do
  115. url "https://github.com/0xJacky/nginx-ui/releases/download/v#{version}/nginx-ui-linux-arm64-v8a.tar.gz"
  116. sha256 "${{ steps.checksums.outputs.linux_arm_sha256 }}"
  117. end
  118. end
  119. def install
  120. bin.install "nginx-ui"
  121. # Create configuration directory
  122. (etc/"nginx-ui").mkpath
  123. # Create default configuration file if it doesn't exist
  124. config_file = etc/"nginx-ui/app.ini"
  125. unless config_file.exist?
  126. config_file.write <<~EOS
  127. [app]
  128. PageSize = 10
  129. [server]
  130. Host = 0.0.0.0
  131. Port = 9000
  132. RunMode = release
  133. [cert]
  134. HTTPChallengePort = 9180
  135. [terminal]
  136. StartCmd = login
  137. EOS
  138. end
  139. # Create data directory
  140. (var/"nginx-ui").mkpath
  141. end
  142. def post_install
  143. # Ensure correct permissions
  144. (var/"nginx-ui").chmod 0755
  145. end
  146. service do
  147. run [opt_bin/"nginx-ui", "serve", "--config", etc/"nginx-ui/app.ini"]
  148. keep_alive true
  149. working_dir var/"nginx-ui"
  150. log_path var/"log/nginx-ui.log"
  151. error_log_path var/"log/nginx-ui.err.log"
  152. end
  153. test do
  154. assert_match version.to_s, shell_output("#{bin}/nginx-ui --version")
  155. end
  156. end
  157. EOF
  158. echo "Generated Homebrew Formula:"
  159. cat nginx-ui.rb
  160. - name: Checkout homebrew-tools repository
  161. uses: actions/checkout@v4
  162. with:
  163. repository: 0xJacky/homebrew-tools
  164. path: homebrew-tools
  165. token: ${{ secrets.HOMEBREW_GITHUB_TOKEN }}
  166. - name: Update Formula file
  167. run: |
  168. # Copy the generated formula to the correct location
  169. mkdir -p homebrew-tools/Formula/
  170. cp nginx-ui.rb homebrew-tools/Formula/nginx-ui.rb
  171. - name: Verify Formula
  172. run: |
  173. cd homebrew-tools
  174. # Basic syntax check
  175. ruby -c Formula/nginx-ui.rb
  176. echo "Formula syntax is valid"
  177. - name: Create Pull Request to homebrew-tools
  178. uses: peter-evans/create-pull-request@v7
  179. with:
  180. token: ${{ secrets.HOMEBREW_GITHUB_TOKEN }}
  181. path: homebrew-tools
  182. branch: update-nginx-ui-${{ steps.release.outputs.version }}
  183. delete-branch: true
  184. title: 'nginx-ui ${{ steps.release.outputs.version }}'
  185. body: |
  186. Update nginx-ui to version ${{ steps.release.outputs.version }}
  187. **Release Notes:**
  188. - Version: ${{ steps.release.outputs.version }}
  189. - Release URL: https://github.com/${{ github.repository }}/releases/tag/${{ steps.release.outputs.tag_name }}
  190. **Checksums (SHA256):**
  191. - macOS Intel: ${{ steps.checksums.outputs.macos_intel_sha256 }}
  192. - macOS ARM: ${{ steps.checksums.outputs.macos_arm_sha256 }}
  193. - Linux Intel: ${{ steps.checksums.outputs.linux_intel_sha256 }}
  194. - Linux ARM: ${{ steps.checksums.outputs.linux_arm_sha256 }}
  195. ---
  196. This PR was automatically generated by GitHub Actions.
  197. commit-message: 'nginx-ui ${{ steps.release.outputs.version }}'
  198. committer: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  199. author: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  200. add-paths: |
  201. Formula/nginx-ui.rb