|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'v*' # Trigger on version tags like v1.0.0, v1.2.3, etc. |
| 7 | + workflow_dispatch: # Allow manual triggering |
| 8 | + |
| 9 | +jobs: |
| 10 | + build: |
| 11 | + name: Build Binaries |
| 12 | + runs-on: ubuntu-latest |
| 13 | + strategy: |
| 14 | + matrix: |
| 15 | + include: |
| 16 | + # Linux builds |
| 17 | + - goos: linux |
| 18 | + goarch: amd64 |
| 19 | + name: jail-linux-amd64 |
| 20 | + - goos: linux |
| 21 | + goarch: arm64 |
| 22 | + name: jail-linux-arm64 |
| 23 | + # macOS builds |
| 24 | + - goos: darwin |
| 25 | + goarch: amd64 |
| 26 | + name: jail-darwin-amd64 |
| 27 | + - goos: darwin |
| 28 | + goarch: arm64 |
| 29 | + name: jail-darwin-arm64 |
| 30 | + # Windows builds |
| 31 | + - goos: windows |
| 32 | + goarch: amd64 |
| 33 | + name: jail-windows-amd64.exe |
| 34 | + - goos: windows |
| 35 | + goarch: arm64 |
| 36 | + name: jail-windows-arm64.exe |
| 37 | + |
| 38 | + steps: |
| 39 | + - name: Check out code |
| 40 | + uses: actions/checkout@v4 |
| 41 | + |
| 42 | + - name: Set up Go |
| 43 | + uses: actions/setup-go@v5 |
| 44 | + with: |
| 45 | + go-version: '1.25' |
| 46 | + check-latest: true |
| 47 | + |
| 48 | + - name: Cache Go modules |
| 49 | + uses: actions/cache@v4 |
| 50 | + with: |
| 51 | + path: | |
| 52 | + ~/.cache/go-build |
| 53 | + ~/go/pkg/mod |
| 54 | + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} |
| 55 | + restore-keys: | |
| 56 | + ${{ runner.os }}-go- |
| 57 | +
|
| 58 | + - name: Download dependencies |
| 59 | + run: go mod download |
| 60 | + |
| 61 | + - name: Build binary |
| 62 | + env: |
| 63 | + GOOS: ${{ matrix.goos }} |
| 64 | + GOARCH: ${{ matrix.goarch }} |
| 65 | + CGO_ENABLED: 0 |
| 66 | + run: | |
| 67 | + go build -ldflags="-s -w -X main.version=${{ github.ref_name }}" -o ${{ matrix.name }} . |
| 68 | +
|
| 69 | + - name: Upload binary as artifact |
| 70 | + uses: actions/upload-artifact@v4 |
| 71 | + with: |
| 72 | + name: ${{ matrix.name }} |
| 73 | + path: ${{ matrix.name }} |
| 74 | + retention-days: 7 |
| 75 | + |
| 76 | + release: |
| 77 | + name: Create Release |
| 78 | + needs: build |
| 79 | + runs-on: ubuntu-latest |
| 80 | + if: startsWith(github.ref, 'refs/tags/') |
| 81 | + |
| 82 | + steps: |
| 83 | + - name: Check out code |
| 84 | + uses: actions/checkout@v4 |
| 85 | + |
| 86 | + - name: Download all artifacts |
| 87 | + uses: actions/download-artifact@v4 |
| 88 | + with: |
| 89 | + path: ./binaries |
| 90 | + |
| 91 | + - name: Prepare release assets |
| 92 | + run: | |
| 93 | + cd binaries |
| 94 | + # Create compressed archives for each binary |
| 95 | + for dir in */; do |
| 96 | + binary_name=$(basename "$dir") |
| 97 | + cd "$dir" |
| 98 | + if [[ "$binary_name" == *.exe ]]; then |
| 99 | + # Windows: create zip |
| 100 | + zip "../${binary_name%.exe}.zip" "$binary_name" |
| 101 | + else |
| 102 | + # Unix: create tar.gz |
| 103 | + tar -czf "../${binary_name}.tar.gz" "$binary_name" |
| 104 | + fi |
| 105 | + cd .. |
| 106 | + done |
| 107 | + # List all release assets |
| 108 | + ls -la *.tar.gz *.zip |
| 109 | +
|
| 110 | + - name: Generate release notes |
| 111 | + id: release_notes |
| 112 | + run: | |
| 113 | + echo "## 🚀 Release ${{ github.ref_name }}" > release_notes.md |
| 114 | + echo "" >> release_notes.md |
| 115 | + echo "### 📦 Downloads" >> release_notes.md |
| 116 | + echo "" >> release_notes.md |
| 117 | + echo "Choose the appropriate binary for your platform:" >> release_notes.md |
| 118 | + echo "" >> release_notes.md |
| 119 | + echo "- **Linux (x64)**: `jail-linux-amd64.tar.gz`" >> release_notes.md |
| 120 | + echo "- **Linux (ARM64)**: `jail-linux-arm64.tar.gz`" >> release_notes.md |
| 121 | + echo "- **macOS (Intel)**: `jail-darwin-amd64.tar.gz`" >> release_notes.md |
| 122 | + echo "- **macOS (Apple Silicon)**: `jail-darwin-arm64.tar.gz`" >> release_notes.md |
| 123 | + echo "- **Windows (x64)**: `jail-windows-amd64.zip`" >> release_notes.md |
| 124 | + echo "- **Windows (ARM64)**: `jail-windows-arm64.zip`" >> release_notes.md |
| 125 | + echo "" >> release_notes.md |
| 126 | + echo "### 🛠️ Installation" >> release_notes.md |
| 127 | + echo "" >> release_notes.md |
| 128 | + echo "1. Download the appropriate binary for your platform" >> release_notes.md |
| 129 | + echo "2. Extract the archive" >> release_notes.md |
| 130 | + echo "3. Make the binary executable (Unix): `chmod +x jail`" >> release_notes.md |
| 131 | + echo "4. Move to your PATH: `sudo mv jail /usr/local/bin/` (Unix)" >> release_notes.md |
| 132 | + echo "" >> release_notes.md |
| 133 | + echo "### ✅ Verification" >> release_notes.md |
| 134 | + echo "" >> release_notes.md |
| 135 | + echo "Verify installation: `jail --help`" >> release_notes.md |
| 136 | +
|
| 137 | + - name: Create GitHub Release |
| 138 | + uses: softprops/action-gh-release@v2 |
| 139 | + with: |
| 140 | + files: | |
| 141 | + binaries/*.tar.gz |
| 142 | + binaries/*.zip |
| 143 | + body_path: release_notes.md |
| 144 | + draft: false |
| 145 | + prerelease: ${{ contains(github.ref_name, '-') }} |
| 146 | + generate_release_notes: true |
| 147 | + env: |
| 148 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments