|
| 1 | +--- |
| 2 | +name: Build and Release |
| 3 | + |
| 4 | +on: |
| 5 | + push: |
| 6 | + tags: |
| 7 | + - "v*" |
| 8 | + |
| 9 | +jobs: |
| 10 | + build: |
| 11 | + name: Build binaries |
| 12 | + runs-on: ubuntu-latest |
| 13 | + strategy: |
| 14 | + matrix: |
| 15 | + os: [linux, darwin, windows] |
| 16 | + arch: [amd64, arm64] |
| 17 | + exclude: |
| 18 | + # Windows on ARM64 is not commonly used for this type of application |
| 19 | + - os: windows |
| 20 | + arch: arm64 |
| 21 | + |
| 22 | + steps: |
| 23 | + - name: Checkout code |
| 24 | + uses: actions/checkout@v4 |
| 25 | + |
| 26 | + - name: Set up Go |
| 27 | + uses: actions/setup-go@v5 |
| 28 | + with: |
| 29 | + go-version: '1.25.x' |
| 30 | + |
| 31 | + - name: Cache Go modules |
| 32 | + - name: Cache Go modules |
| 33 | + uses: actions/cache@v4 |
| 34 | + with: |
| 35 | + path: ~/go/pkg/mod |
| 36 | + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} |
| 37 | + restore-keys: | |
| 38 | + ${{ runner.os }}-go- |
| 39 | +
|
| 40 | + - name: Install dependencies |
| 41 | + run: go mod download |
| 42 | + |
| 43 | + - name: Verify dependencies |
| 44 | + run: go mod verify |
| 45 | + |
| 46 | + - name: Extract version from tag |
| 47 | + id: version |
| 48 | + run: | |
| 49 | + VERSION=${GITHUB_REF#refs/tags/v} |
| 50 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 51 | + echo "$VERSION" > appVersion.txt |
| 52 | + echo "Version set to: $VERSION" |
| 53 | +
|
| 54 | + - name: Create build directory |
| 55 | + run: mkdir -p build |
| 56 | + |
| 57 | + - name: Set build environment |
| 58 | + run: | |
| 59 | + echo "GOOS=${{ matrix.os }}" >> $GITHUB_ENV |
| 60 | + echo "GOARCH=${{ matrix.arch }}" >> $GITHUB_ENV |
| 61 | + if [ "${{ matrix.os }}" = "windows" ]; then |
| 62 | + echo "BINARY_EXT=.exe" >> $GITHUB_ENV |
| 63 | + else |
| 64 | + echo "BINARY_EXT=" >> $GITHUB_ENV |
| 65 | + fi |
| 66 | +
|
| 67 | + - name: Build all binaries |
| 68 | + run: | |
| 69 | + VERSION=$(cat appVersion.txt) |
| 70 | +
|
| 71 | + # List of all applications to build |
| 72 | + apps=( |
| 73 | + "web:webserver" |
| 74 | + "nntp-fetcher:pugleaf-fetcher" |
| 75 | + "nntp-server:pugleaf-nntp-server" |
| 76 | + "expire-news:expire-news" |
| 77 | + "merge-active:merge-active" |
| 78 | + "merge-descriptions:merge-descriptions" |
| 79 | + "test-MsgIdItemCache:test-MsgIdItemCache" |
| 80 | + "history-rebuild:history-rebuild" |
| 81 | + "fix-references:fix-references" |
| 82 | + "fix-thread-activity:fix-thread-activity" |
| 83 | + "rslight-importer:rslight-importer" |
| 84 | + "nntp-analyze:nntp-analyze" |
| 85 | + "recover-db:recover-db" |
| 86 | + ) |
| 87 | +
|
| 88 | + for app in "${apps[@]}"; do |
| 89 | + IFS=':' read -r cmd_dir binary_name <<< "$app" |
| 90 | + echo "Building $cmd_dir -> $binary_name" |
| 91 | +
|
| 92 | + if [ "$cmd_dir" = "nntp-fetcher" ]; then |
| 93 | + # Special build for fetcher with green tea GC |
| 94 | + GOEXPERIMENT=greenteagc go build \ |
| 95 | + -o "build/${binary_name}${BINARY_EXT}" \ |
| 96 | + -ldflags "-X main.appVersion=$VERSION" \ |
| 97 | + "./cmd/$cmd_dir" |
| 98 | + else |
| 99 | + # Standard build (removing -race for cross-compilation) |
| 100 | + go build -o "build/${binary_name}${BINARY_EXT}" \ |
| 101 | + -ldflags "-X main.appVersion=$VERSION" \ |
| 102 | + "./cmd/$cmd_dir" |
| 103 | + fi |
| 104 | +
|
| 105 | + if [ $? -ne 0 ]; then |
| 106 | + echo "Failed to build $cmd_dir" |
| 107 | + exit 1 |
| 108 | + fi |
| 109 | + done |
| 110 | +
|
| 111 | + - name: Create release archive |
| 112 | + run: | |
| 113 | + VERSION="${{ steps.version.outputs.version }}" |
| 114 | + OS="${{ matrix.os }}" |
| 115 | + ARCH="${{ matrix.arch }}" |
| 116 | + ARCHIVE_NAME="go-pugleaf-v${VERSION}-${OS}-${ARCH}" |
| 117 | + if [ "${{ matrix.os }}" = "windows" ]; then |
| 118 | + zip -r "${ARCHIVE_NAME}.zip" build/ README.md LICENSE |
| 119 | + echo "ARCHIVE_FILE=${ARCHIVE_NAME}.zip" >> $GITHUB_ENV |
| 120 | + else |
| 121 | + tar -czf "${ARCHIVE_NAME}.tar.gz" build/ README.md LICENSE |
| 122 | + echo "ARCHIVE_FILE=${ARCHIVE_NAME}.tar.gz" >> $GITHUB_ENV |
| 123 | + fi |
| 124 | +
|
| 125 | + - name: Upload build artifacts |
| 126 | + uses: actions/upload-artifact@v4 |
| 127 | + with: |
| 128 | + name: go-pugleaf-${{ matrix.os }}-${{ matrix.arch }} |
| 129 | + path: ${{ env.ARCHIVE_FILE }} |
| 130 | + |
| 131 | + release: |
| 132 | + name: Create release |
| 133 | + needs: build |
| 134 | + runs-on: ubuntu-latest |
| 135 | + permissions: |
| 136 | + contents: write |
| 137 | + |
| 138 | + steps: |
| 139 | + - name: Checkout code |
| 140 | + uses: actions/checkout@v4 |
| 141 | + |
| 142 | + - name: Extract version from tag |
| 143 | + id: version |
| 144 | + run: | |
| 145 | + VERSION=${GITHUB_REF#refs/tags/v} |
| 146 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 147 | +
|
| 148 | + - name: Download all artifacts |
| 149 | + uses: actions/download-artifact@v4 |
| 150 | + with: |
| 151 | + path: artifacts |
| 152 | + |
| 153 | + - name: Create release |
| 154 | + uses: softprops/action-gh-release@v2 |
| 155 | + with: |
| 156 | + tag_name: ${{ github.ref_name }} |
| 157 | + name: Release v${{ steps.version.outputs.version }} |
| 158 | + body: | |
| 159 | + ## Go-Pugleaf v${{ steps.version.outputs.version }} |
| 160 | +
|
| 161 | + Automated release build of go-pugleaf NNTP server and web gateway. |
| 162 | +
|
| 163 | + ### Included Binaries: |
| 164 | + - `webserver` - Main web interface |
| 165 | + - `pugleaf-fetcher` - Article fetcher from NNTP providers |
| 166 | + - `pugleaf-nntp-server` - NNTP server implementation |
| 167 | + - `expire-news` - Article expiration tool |
| 168 | + - `merge-active` - Active file merger |
| 169 | + - `merge-descriptions` - Description file merger |
| 170 | + - `test-MsgIdItemCache` - Cache testing tool |
| 171 | + - `history-rebuild` - History rebuild utility |
| 172 | + - `fix-references` - Reference fixing tool |
| 173 | + - `fix-thread-activity` - Thread activity fixer |
| 174 | + - `rslight-importer` - RSLight data importer |
| 175 | + - `nntp-analyze` - NNTP analysis tool |
| 176 | + - `recover-db` - Database recovery tool |
| 177 | +
|
| 178 | + ### Platform Support: |
| 179 | + - Linux (amd64, arm64) |
| 180 | + - macOS (amd64, arm64) |
| 181 | + - Windows (amd64) |
| 182 | +
|
| 183 | + Extract the archive for your platform and run the binaries. |
| 184 | + See README.md for usage instructions. |
| 185 | + files: artifacts/*/* |
| 186 | + draft: false |
| 187 | + prerelease: false |
0 commit comments