|
| 1 | +name: Build PR Binaries |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [opened, synchronize, reopened] |
| 6 | + branches: |
| 7 | + - master |
| 8 | + - main |
| 9 | + |
| 10 | +permissions: |
| 11 | + contents: read |
| 12 | + pull-requests: write |
| 13 | + |
| 14 | +jobs: |
| 15 | + build: |
| 16 | + runs-on: ubuntu-latest |
| 17 | + |
| 18 | + steps: |
| 19 | + - name: Check out code |
| 20 | + uses: actions/checkout@v4 |
| 21 | + |
| 22 | + - name: Set up Go |
| 23 | + uses: actions/setup-go@v4 |
| 24 | + with: |
| 25 | + go-version: '1.24' |
| 26 | + |
| 27 | + - name: Set up Node.js |
| 28 | + uses: actions/setup-node@v4 |
| 29 | + with: |
| 30 | + node-version: '18' |
| 31 | + |
| 32 | + - name: Build frontend |
| 33 | + run: | |
| 34 | + cd ui |
| 35 | + npm install |
| 36 | + npm run build |
| 37 | + cd .. |
| 38 | + rm -rf application/webserver/frontend/files/* |
| 39 | + mv ui/dist/* application/webserver/frontend/files/ |
| 40 | + mv application/webserver/frontend/files/fs/* application/webserver/frontend/files/ |
| 41 | +
|
| 42 | + - name: Get dependencies |
| 43 | + run: go get -v |
| 44 | + |
| 45 | + - name: Build binaries for multiple platforms |
| 46 | + run: | |
| 47 | + mkdir -p pr-binaries |
| 48 | + echo "Building Linux amd64..." |
| 49 | + env GOOS=linux GOARCH=amd64 go build -o pr-binaries/gatesentry-linux-amd64 |
| 50 | + echo "Building Linux arm64..." |
| 51 | + env GOOS=linux GOARCH=arm64 go build -o pr-binaries/gatesentry-linux-arm64 |
| 52 | + echo "Building macOS amd64..." |
| 53 | + env GOOS=darwin GOARCH=amd64 go build -o pr-binaries/gatesentry-macos-amd64 |
| 54 | + echo "Building macOS arm64 (Apple Silicon)..." |
| 55 | + env GOOS=darwin GOARCH=arm64 go build -o pr-binaries/gatesentry-macos-arm64 |
| 56 | + echo "Building Windows amd64..." |
| 57 | + env GOOS=windows GOARCH=amd64 go build -o pr-binaries/gatesentry-windows-amd64.exe |
| 58 | + |
| 59 | + # Make binaries executable |
| 60 | + chmod +x pr-binaries/gatesentry-* |
| 61 | + |
| 62 | + # Get file sizes |
| 63 | + ls -lh pr-binaries/ |
| 64 | +
|
| 65 | + - name: Upload binaries as artifacts |
| 66 | + uses: actions/upload-artifact@v4 |
| 67 | + with: |
| 68 | + name: gatesentry-pr-${{ github.event.pull_request.number }} |
| 69 | + path: pr-binaries/* |
| 70 | + retention-days: 30 |
| 71 | + |
| 72 | + - name: Generate download links and comment |
| 73 | + uses: actions/github-script@v7 |
| 74 | + with: |
| 75 | + script: | |
| 76 | + const fs = require('fs'); |
| 77 | + const path = require('path'); |
| 78 | + |
| 79 | + // Get file sizes |
| 80 | + const binariesDir = 'pr-binaries'; |
| 81 | + const files = fs.readdirSync(binariesDir); |
| 82 | + |
| 83 | + let fileList = ''; |
| 84 | + files.forEach(file => { |
| 85 | + const stats = fs.statSync(path.join(binariesDir, file)); |
| 86 | + const sizeMB = (stats.size / (1024 * 1024)).toFixed(2); |
| 87 | + fileList += `- \`${file}\` (${sizeMB} MB)\n`; |
| 88 | + }); |
| 89 | + |
| 90 | + const runId = context.runId; |
| 91 | + const repo = context.repo; |
| 92 | + const prNumber = context.payload.pull_request.number; |
| 93 | + const sha = context.payload.pull_request.head.sha.substring(0, 7); |
| 94 | + |
| 95 | + // Create comment body |
| 96 | + const commentBody = `## 🚀 PR Build Artifacts |
| 97 | + |
| 98 | + Test binaries have been built for this PR (commit ${sha}). |
| 99 | + |
| 100 | + ### Available Binaries: |
| 101 | + ${fileList} |
| 102 | + |
| 103 | + ### Download Instructions: |
| 104 | + |
| 105 | + 1. **Via GitHub Actions UI:** |
| 106 | + - Go to the [Actions tab](https://github.com/${repo.owner}/${repo.repo}/actions/runs/${runId}) |
| 107 | + - Scroll down to "Artifacts" section |
| 108 | + - Download \`gatesentry-pr-${prNumber}\` |
| 109 | + |
| 110 | + 2. **Via GitHub CLI:** |
| 111 | + \`\`\`bash |
| 112 | + gh run download ${runId} -n gatesentry-pr-${prNumber} -R ${repo.owner}/${repo.repo} |
| 113 | + \`\`\` |
| 114 | + |
| 115 | + ### Quick Test (Linux/macOS): |
| 116 | + \`\`\`bash |
| 117 | + # Extract and make executable |
| 118 | + chmod +x gatesentry-* |
| 119 | + |
| 120 | + # Test with low memory settings (good for routers) |
| 121 | + export GS_MAX_SCAN_SIZE_MB=3 |
| 122 | + export GS_DEBUG_LOGGING=false |
| 123 | + ./gatesentry-linux-amd64 |
| 124 | + |
| 125 | + # Or test with custom settings |
| 126 | + export GS_MAX_SCAN_SIZE_MB=10 |
| 127 | + ./gatesentry-linux-amd64 |
| 128 | + \`\`\` |
| 129 | + |
| 130 | + ### Quick Test (Windows): |
| 131 | + \`\`\`powershell |
| 132 | + # Set environment variables |
| 133 | + $env:GS_MAX_SCAN_SIZE_MB=10 |
| 134 | + $env:GS_DEBUG_LOGGING="false" |
| 135 | + .\\gatesentry-windows-amd64.exe |
| 136 | + \`\`\` |
| 137 | + |
| 138 | + ### Configuration Options: |
| 139 | + - \`GS_MAX_SCAN_SIZE_MB\`: Set max content scan size (1-1000 MB, default: 10) |
| 140 | + - \`GS_DEBUG_LOGGING\`: Enable verbose logging (true/false, default: false) |
| 141 | + |
| 142 | + See [ROUTER_OPTIMIZATION.md](https://github.com/${repo.owner}/${repo.repo}/blob/${context.payload.pull_request.head.ref}/ROUTER_OPTIMIZATION.md) for detailed configuration guide. |
| 143 | + |
| 144 | + --- |
| 145 | + |
| 146 | + 📝 *Binaries are kept for 30 days and automatically deleted afterwards.*`; |
| 147 | + |
| 148 | + // Find existing comment |
| 149 | + const { data: comments } = await github.rest.issues.listComments({ |
| 150 | + owner: repo.owner, |
| 151 | + repo: repo.repo, |
| 152 | + issue_number: prNumber |
| 153 | + }); |
| 154 | + |
| 155 | + const botComment = comments.find(comment => |
| 156 | + comment.user.login === 'github-actions[bot]' && |
| 157 | + comment.body.includes('PR Build Artifacts') |
| 158 | + ); |
| 159 | + |
| 160 | + // Update or create comment |
| 161 | + if (botComment) { |
| 162 | + await github.rest.issues.updateComment({ |
| 163 | + owner: repo.owner, |
| 164 | + repo: repo.repo, |
| 165 | + comment_id: botComment.id, |
| 166 | + body: commentBody |
| 167 | + }); |
| 168 | + console.log('Updated existing comment'); |
| 169 | + } else { |
| 170 | + await github.rest.issues.createComment({ |
| 171 | + owner: repo.owner, |
| 172 | + repo: repo.repo, |
| 173 | + issue_number: prNumber, |
| 174 | + body: commentBody |
| 175 | + }); |
| 176 | + console.log('Created new comment'); |
| 177 | + } |
| 178 | +
|
| 179 | + - name: Build summary |
| 180 | + run: | |
| 181 | + echo "## Build Summary" >> $GITHUB_STEP_SUMMARY |
| 182 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 183 | + echo "✅ Successfully built binaries for PR #${{ github.event.pull_request.number }}" >> $GITHUB_STEP_SUMMARY |
| 184 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 185 | + echo "### Binaries:" >> $GITHUB_STEP_SUMMARY |
| 186 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 187 | + ls -lh pr-binaries/ | tail -n +2 | awk '{print "- " $9 " (" $5 ")"}' >> $GITHUB_STEP_SUMMARY |
| 188 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 189 | + echo "Artifacts are available for download from the Actions tab." >> $GITHUB_STEP_SUMMARY |
0 commit comments