|
| 1 | +name: Update Homebrew Formula |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_run: |
| 5 | + workflows: ["Build"] |
| 6 | + types: |
| 7 | + - completed |
| 8 | + release: |
| 9 | + types: |
| 10 | + - published |
| 11 | + |
| 12 | +jobs: |
| 13 | + update-homebrew: |
| 14 | + runs-on: ubuntu-latest |
| 15 | + if: github.event_name == 'release' || (github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'release') |
| 16 | + steps: |
| 17 | + - name: Checkout |
| 18 | + uses: actions/checkout@v4 |
| 19 | + |
| 20 | + - name: Get release info |
| 21 | + id: release |
| 22 | + run: | |
| 23 | + if [[ "${{ github.event_name }}" == "release" ]]; then |
| 24 | + echo "tag_name=${{ github.event.release.tag_name }}" >> $GITHUB_OUTPUT |
| 25 | + echo "version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT |
| 26 | + else |
| 27 | + # Get latest release info |
| 28 | + LATEST_RELEASE=$(curl -s "https://api.github.com/repos/${{ github.repository }}/releases/latest") |
| 29 | + TAG_NAME=$(echo "$LATEST_RELEASE" | jq -r '.tag_name') |
| 30 | + VERSION=${TAG_NAME#v} |
| 31 | + echo "tag_name=$TAG_NAME" >> $GITHUB_OUTPUT |
| 32 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 33 | + fi |
| 34 | +
|
| 35 | + - name: Download release assets and calculate SHA256 checksums |
| 36 | + id: checksums |
| 37 | + run: | |
| 38 | + VERSION="${{ steps.release.outputs.version }}" |
| 39 | + TAG_NAME="${{ steps.release.outputs.tag_name }}" |
| 40 | +
|
| 41 | + # Download binary files from releases and calculate SHA256 |
| 42 | + mkdir -p downloads |
| 43 | +
|
| 44 | + # macOS Intel |
| 45 | + wget -O downloads/nginx-ui-macos-64.tar.gz "https://github.com/${{ github.repository }}/releases/download/$TAG_NAME/nginx-ui-macos-64.tar.gz" |
| 46 | + MACOS_INTEL_SHA256=$(sha256sum downloads/nginx-ui-macos-64.tar.gz | cut -d' ' -f1) |
| 47 | +
|
| 48 | + # macOS ARM |
| 49 | + 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" |
| 50 | + MACOS_ARM_SHA256=$(sha256sum downloads/nginx-ui-macos-arm64-v8a.tar.gz | cut -d' ' -f1) |
| 51 | +
|
| 52 | + # Linux Intel |
| 53 | + wget -O downloads/nginx-ui-linux-64.tar.gz "https://github.com/${{ github.repository }}/releases/download/$TAG_NAME/nginx-ui-linux-64.tar.gz" |
| 54 | + LINUX_INTEL_SHA256=$(sha256sum downloads/nginx-ui-linux-64.tar.gz | cut -d' ' -f1) |
| 55 | +
|
| 56 | + # Linux ARM |
| 57 | + 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" |
| 58 | + LINUX_ARM_SHA256=$(sha256sum downloads/nginx-ui-linux-arm64-v8a.tar.gz | cut -d' ' -f1) |
| 59 | +
|
| 60 | + echo "macos_intel_sha256=$MACOS_INTEL_SHA256" >> $GITHUB_OUTPUT |
| 61 | + echo "macos_arm_sha256=$MACOS_ARM_SHA256" >> $GITHUB_OUTPUT |
| 62 | + echo "linux_intel_sha256=$LINUX_INTEL_SHA256" >> $GITHUB_OUTPUT |
| 63 | + echo "linux_arm_sha256=$LINUX_ARM_SHA256" >> $GITHUB_OUTPUT |
| 64 | +
|
| 65 | + - name: Generate Homebrew Formula |
| 66 | + id: formula |
| 67 | + run: | |
| 68 | + VERSION="${{ steps.release.outputs.version }}" |
| 69 | +
|
| 70 | + cat > nginx-ui.rb << 'EOF' |
| 71 | + class NginxUi < Formula |
| 72 | + desc "Yet another Nginx Web UI" |
| 73 | + homepage "https://github.com/0xJacky/nginx-ui" |
| 74 | + version "${{ steps.release.outputs.version }}" |
| 75 | + license "AGPL-3.0" |
| 76 | +
|
| 77 | + on_macos do |
| 78 | + on_intel do |
| 79 | + url "https://github.com/0xJacky/nginx-ui/releases/download/v#{version}/nginx-ui-macos-64.tar.gz" |
| 80 | + sha256 "${{ steps.checksums.outputs.macos_intel_sha256 }}" |
| 81 | + end |
| 82 | + on_arm do |
| 83 | + url "https://github.com/0xJacky/nginx-ui/releases/download/v#{version}/nginx-ui-macos-arm64-v8a.tar.gz" |
| 84 | + sha256 "${{ steps.checksums.outputs.macos_arm_sha256 }}" |
| 85 | + end |
| 86 | + end |
| 87 | +
|
| 88 | + on_linux do |
| 89 | + on_intel do |
| 90 | + url "https://github.com/0xJacky/nginx-ui/releases/download/v#{version}/nginx-ui-linux-64.tar.gz" |
| 91 | + sha256 "${{ steps.checksums.outputs.linux_intel_sha256 }}" |
| 92 | + end |
| 93 | + on_arm do |
| 94 | + url "https://github.com/0xJacky/nginx-ui/releases/download/v#{version}/nginx-ui-linux-arm64-v8a.tar.gz" |
| 95 | + sha256 "${{ steps.checksums.outputs.linux_arm_sha256 }}" |
| 96 | + end |
| 97 | + end |
| 98 | +
|
| 99 | + def install |
| 100 | + bin.install "nginx-ui" |
| 101 | + end |
| 102 | +
|
| 103 | + test do |
| 104 | + assert_match version.to_s, shell_output("#{bin}/nginx-ui --version") |
| 105 | + end |
| 106 | + end |
| 107 | + EOF |
| 108 | +
|
| 109 | + echo "Generated Homebrew Formula:" |
| 110 | + cat nginx-ui.rb |
| 111 | +
|
| 112 | + - name: Checkout homebrew-tools repository |
| 113 | + uses: actions/checkout@v4 |
| 114 | + with: |
| 115 | + repository: 0xJacky/homebrew-tools |
| 116 | + path: homebrew-tools |
| 117 | + token: ${{ secrets.HOMEBREW_GITHUB_TOKEN }} |
| 118 | + |
| 119 | + - name: Update Formula file |
| 120 | + run: | |
| 121 | + # Copy the generated formula to the correct location |
| 122 | + mkdir -p homebrew-tools/Formula/ |
| 123 | + cp nginx-ui.rb homebrew-tools/Formula/nginx-ui.rb |
| 124 | +
|
| 125 | + - name: Verify Formula |
| 126 | + run: | |
| 127 | + cd homebrew-tools |
| 128 | + # Basic syntax check |
| 129 | + ruby -c Formula/nginx-ui.rb |
| 130 | + echo "Formula syntax is valid" |
| 131 | +
|
| 132 | + - name: Create Pull Request to homebrew-tools |
| 133 | + uses: peter-evans/create-pull-request@v5 |
| 134 | + with: |
| 135 | + token: ${{ secrets.HOMEBREW_GITHUB_TOKEN }} |
| 136 | + path: homebrew-tools |
| 137 | + branch: update-nginx-ui-${{ steps.release.outputs.version }} |
| 138 | + delete-branch: true |
| 139 | + title: 'nginx-ui ${{ steps.release.outputs.version }}' |
| 140 | + body: | |
| 141 | + Update nginx-ui to version ${{ steps.release.outputs.version }} |
| 142 | +
|
| 143 | + **Release Notes:** |
| 144 | + - Version: ${{ steps.release.outputs.version }} |
| 145 | + - Release URL: https://github.com/${{ github.repository }}/releases/tag/${{ steps.release.outputs.tag_name }} |
| 146 | +
|
| 147 | + **Checksums (SHA256):** |
| 148 | + - macOS Intel: ${{ steps.checksums.outputs.macos_intel_sha256 }} |
| 149 | + - macOS ARM: ${{ steps.checksums.outputs.macos_arm_sha256 }} |
| 150 | + - Linux Intel: ${{ steps.checksums.outputs.linux_intel_sha256 }} |
| 151 | + - Linux ARM: ${{ steps.checksums.outputs.linux_arm_sha256 }} |
| 152 | +
|
| 153 | + --- |
| 154 | +
|
| 155 | + This PR was automatically generated by GitHub Actions. |
| 156 | + commit-message: 'nginx-ui ${{ steps.release.outputs.version }}' |
| 157 | + committer: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> |
| 158 | + author: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> |
| 159 | + add-paths: | |
| 160 | + Formula/nginx-ui.rb |
0 commit comments