|
1 | 1 | name: Update Homebrew Formula
|
2 | 2 |
|
3 | 3 | on:
|
4 |
| - workflow_run: |
5 |
| - workflows: ["Build"] |
6 |
| - types: |
7 |
| - - completed |
8 | 4 | release:
|
9 | 5 | types:
|
10 | 6 | - published
|
11 | 7 |
|
12 | 8 | jobs:
|
13 | 9 | update-homebrew:
|
14 | 10 | runs-on: ubuntu-latest
|
15 |
| - if: github.event_name == 'release' || (github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'release') |
| 11 | + if: github.event_name == 'release' |
16 | 12 | steps:
|
17 | 13 | - name: Checkout
|
18 | 14 | uses: actions/checkout@v4
|
19 | 15 |
|
20 | 16 | - name: Get release info
|
21 | 17 | id: release
|
22 | 18 | 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 |
| 19 | + echo "tag_name=${{ github.event.release.tag_name }}" >> $GITHUB_OUTPUT |
| 20 | + echo "version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT |
| 21 | +
|
| 22 | + - name: Wait for release assets to be available |
| 23 | + run: | |
| 24 | + TAG_NAME="${{ steps.release.outputs.tag_name }}" |
| 25 | +
|
| 26 | + # Function to check if a file exists |
| 27 | + check_file() { |
| 28 | + local url="$1" |
| 29 | + local filename="$2" |
| 30 | + echo "Checking if $filename is available..." |
| 31 | + if curl --output /dev/null --silent --head --fail "$url"; then |
| 32 | + echo "✓ $filename is available" |
| 33 | + return 0 |
| 34 | + else |
| 35 | + echo "✗ $filename is not yet available" |
| 36 | + return 1 |
| 37 | + fi |
| 38 | + } |
| 39 | +
|
| 40 | + # List of files to check |
| 41 | + declare -a files=( |
| 42 | + "https://github.com/${{ github.repository }}/releases/download/$TAG_NAME/nginx-ui-macos-64.tar.gz" |
| 43 | + "https://github.com/${{ github.repository }}/releases/download/$TAG_NAME/nginx-ui-macos-arm64-v8a.tar.gz" |
| 44 | + "https://github.com/${{ github.repository }}/releases/download/$TAG_NAME/nginx-ui-linux-64.tar.gz" |
| 45 | + "https://github.com/${{ github.repository }}/releases/download/$TAG_NAME/nginx-ui-linux-arm64-v8a.tar.gz" |
| 46 | + ) |
| 47 | +
|
| 48 | + # Wait for all files to be available (max 10 minutes) |
| 49 | + max_attempts=60 |
| 50 | + attempt=1 |
| 51 | +
|
| 52 | + while [ $attempt -le $max_attempts ]; do |
| 53 | + echo "Attempt $attempt/$max_attempts - Checking release assets..." |
| 54 | + all_available=true |
| 55 | +
|
| 56 | + for url in "${files[@]}"; do |
| 57 | + filename=$(basename "$url") |
| 58 | + if ! check_file "$url" "$filename"; then |
| 59 | + all_available=false |
| 60 | + break |
| 61 | + fi |
| 62 | + done |
| 63 | +
|
| 64 | + if [ "$all_available" = true ]; then |
| 65 | + echo "All release assets are available!" |
| 66 | + break |
| 67 | + fi |
| 68 | +
|
| 69 | + if [ $attempt -eq $max_attempts ]; then |
| 70 | + echo "Timeout: Not all release assets are available after $max_attempts attempts" |
| 71 | + exit 1 |
| 72 | + fi |
| 73 | +
|
| 74 | + echo "Waiting 10 seconds before next check..." |
| 75 | + sleep 10 |
| 76 | + ((attempt++)) |
| 77 | + done |
34 | 78 |
|
35 | 79 | - name: Download release assets and calculate SHA256 checksums
|
36 | 80 | id: checksums
|
@@ -98,6 +142,45 @@ jobs:
|
98 | 142 |
|
99 | 143 | def install
|
100 | 144 | bin.install "nginx-ui"
|
| 145 | +
|
| 146 | + # Create configuration directory |
| 147 | + (etc/"nginx-ui").mkpath |
| 148 | +
|
| 149 | + # Create default configuration file if it doesn't exist |
| 150 | + config_file = etc/"nginx-ui/app.ini" |
| 151 | + unless config_file.exist? |
| 152 | + config_file.write <<~EOS |
| 153 | + [app] |
| 154 | + PageSize = 10 |
| 155 | +
|
| 156 | + [server] |
| 157 | + Host = 0.0.0.0 |
| 158 | + Port = 9000 |
| 159 | + RunMode = release |
| 160 | +
|
| 161 | + [cert] |
| 162 | + HTTPChallengePort = 9180 |
| 163 | +
|
| 164 | + [terminal] |
| 165 | + StartCmd = login |
| 166 | + EOS |
| 167 | + end |
| 168 | +
|
| 169 | + # Create data directory |
| 170 | + (var/"nginx-ui").mkpath |
| 171 | + end |
| 172 | +
|
| 173 | + def post_install |
| 174 | + # Ensure correct permissions |
| 175 | + (var/"nginx-ui").chmod 0755 |
| 176 | + end |
| 177 | +
|
| 178 | + service do |
| 179 | + run [opt_bin/"nginx-ui", "serve", "--config", etc/"nginx-ui/app.ini"] |
| 180 | + keep_alive true |
| 181 | + working_dir var/"nginx-ui" |
| 182 | + log_path var/"log/nginx-ui.log" |
| 183 | + error_log_path var/"log/nginx-ui.err.log" |
101 | 184 | end
|
102 | 185 |
|
103 | 186 | test do
|
|
0 commit comments