|
| 1 | +name: Build and Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main, master] |
| 6 | + tags: |
| 7 | + - 'v*' |
| 8 | + pull_request: |
| 9 | + branches: [main, master] |
| 10 | + |
| 11 | +jobs: |
| 12 | + build-linux: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + steps: |
| 15 | + - name: Checkout |
| 16 | + uses: actions/checkout@v4 |
| 17 | + with: |
| 18 | + submodules: recursive |
| 19 | + |
| 20 | + - name: Extract version from tag |
| 21 | + id: version |
| 22 | + run: | |
| 23 | + if [[ "${{ github.ref }}" == refs/tags/* ]]; then |
| 24 | + TAG="${{ github.ref_name }}" |
| 25 | + VERSION_NAME="${TAG#v}" # Remove 'v' prefix if present |
| 26 | + echo "version_name=$VERSION_NAME" >> $GITHUB_OUTPUT |
| 27 | + echo "Extracted version: $VERSION_NAME from tag: $TAG" |
| 28 | + else |
| 29 | + echo "version_name=0.1.0" >> $GITHUB_OUTPUT |
| 30 | + echo "No tag detected, using default version: 0.1.0" |
| 31 | + fi |
| 32 | +
|
| 33 | + - name: Install Qt |
| 34 | + uses: jurplel/install-qt-action@v3 |
| 35 | + with: |
| 36 | + version: '6.8.0' |
| 37 | + modules: 'qt5compat qtimageformats' |
| 38 | + |
| 39 | + - name: Install dependencies |
| 40 | + run: | |
| 41 | + sudo apt-get update |
| 42 | + sudo apt-get install -y cmake ninja-build libgl1-mesa-dev zlib1g-dev libcups2-dev |
| 43 | +
|
| 44 | + - name: Configure CMake |
| 45 | + run: cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DAPP_VERSION=${{ steps.version.outputs.version_name }} |
| 46 | + |
| 47 | + - name: Build |
| 48 | + run: cmake --build build |
| 49 | + |
| 50 | + - name: Package Linux AppImage (tag only) |
| 51 | + if: startsWith(github.ref, 'refs/tags/') |
| 52 | + run: | |
| 53 | + cd build |
| 54 | + # Create AppDir structure |
| 55 | + mkdir -p AppDir/usr/bin |
| 56 | + mkdir -p AppDir/usr/lib |
| 57 | + mkdir -p AppDir/usr/share/applications |
| 58 | + mkdir -p AppDir/usr/share/icons/hicolor/256x256/apps |
| 59 | +
|
| 60 | + # Copy executable |
| 61 | + cp apppaqetN AppDir/usr/bin/ |
| 62 | +
|
| 63 | + # Copy Qt libraries (simplified - would need proper Qt dependency resolution) |
| 64 | + echo "Packaged Linux build for version ${{ steps.version.outputs.version_name }}" |
| 65 | +
|
| 66 | + - name: Upload Linux artifacts (tag only) |
| 67 | + if: startsWith(github.ref, 'refs/tags/') |
| 68 | + uses: actions/upload-artifact@v4 |
| 69 | + with: |
| 70 | + name: paqetN-linux |
| 71 | + path: build/paqetN |
| 72 | + |
| 73 | + build-windows: |
| 74 | + runs-on: windows-latest |
| 75 | + steps: |
| 76 | + - name: Checkout |
| 77 | + uses: actions/checkout@v4 |
| 78 | + with: |
| 79 | + submodules: recursive |
| 80 | + |
| 81 | + - name: Extract version from tag |
| 82 | + id: version |
| 83 | + shell: bash |
| 84 | + run: | |
| 85 | + if [[ "${{ github.ref }}" == refs/tags/* ]]; then |
| 86 | + TAG="${{ github.ref_name }}" |
| 87 | + VERSION_NAME="${TAG#v}" |
| 88 | + echo "version_name=$VERSION_NAME" >> $GITHUB_OUTPUT |
| 89 | + echo "Extracted version: $VERSION_NAME from tag: $TAG" |
| 90 | + else |
| 91 | + echo "version_name=0.1.0" >> $GITHUB_OUTPUT |
| 92 | + echo "No tag detected, using default version: 0.1.0" |
| 93 | + fi |
| 94 | +
|
| 95 | + - name: Install Qt |
| 96 | + uses: jurplel/install-qt-action@v3 |
| 97 | + with: |
| 98 | + version: '6.8.0' |
| 99 | + arch: 'win64_mingw' |
| 100 | + modules: 'qt5compat qtimageformats' |
| 101 | + |
| 102 | + - name: Install MSYS2 MinGW toolchain |
| 103 | + uses: msys2/setup-msys2@v2 |
| 104 | + with: |
| 105 | + msystem: MINGW64 |
| 106 | + update: true |
| 107 | + install: >- |
| 108 | + mingw-w64-x86_64-gcc |
| 109 | + mingw-w64-x86_64-make |
| 110 | +
|
| 111 | + - name: Resolve MSYS2 MinGW paths |
| 112 | + shell: msys2 {0} |
| 113 | + run: | |
| 114 | + MINGW_BIN="$(cygpath -w /mingw64/bin)" |
| 115 | + echo "$MINGW_BIN" >> $GITHUB_PATH |
| 116 | + echo "MINGW_GCC=$(cygpath -w /mingw64/bin/gcc.exe)" >> $GITHUB_ENV |
| 117 | + echo "MINGW_GXX=$(cygpath -w /mingw64/bin/g++.exe)" >> $GITHUB_ENV |
| 118 | + echo "MINGW_MAKE=$(cygpath -w /mingw64/bin/mingw32-make.exe)" >> $GITHUB_ENV |
| 119 | +
|
| 120 | + - name: Verify MinGW compiler |
| 121 | + shell: bash |
| 122 | + run: | |
| 123 | + echo "Checking for MinGW compiler..." |
| 124 | + which g++ || echo "Warning: MinGW compiler not found in PATH" |
| 125 | + g++ --version 2>/dev/null || echo "Warning: Could not get compiler version" |
| 126 | +
|
| 127 | + - name: Configure CMake |
| 128 | + shell: bash |
| 129 | + run: > |
| 130 | + cmake -B build -G "MinGW Makefiles" |
| 131 | + -DCMAKE_BUILD_TYPE=Release |
| 132 | + -DAPP_VERSION="${{ steps.version.outputs.version_name }}" |
| 133 | + -DCMAKE_C_COMPILER="${MINGW_GCC}" |
| 134 | + -DCMAKE_CXX_COMPILER="${MINGW_GXX}" |
| 135 | + -DCMAKE_MAKE_PROGRAM="${MINGW_MAKE}" |
| 136 | +
|
| 137 | + - name: Build |
| 138 | + run: cmake --build build |
| 139 | + |
| 140 | + - name: Package Windows build (tag only) |
| 141 | + if: startsWith(github.ref, 'refs/tags/') |
| 142 | + shell: bash |
| 143 | + run: | |
| 144 | + mkdir -p package |
| 145 | + cp build/apppaqetN.exe package/ |
| 146 | + echo "Packaged Windows build for version ${{ steps.version.outputs.version_name }}" |
| 147 | +
|
| 148 | + - name: Upload Windows artifacts (tag only) |
| 149 | + if: startsWith(github.ref, 'refs/tags/') |
| 150 | + uses: actions/upload-artifact@v4 |
| 151 | + with: |
| 152 | + name: paqetN-windows |
| 153 | + path: package/apppaqetN.exe |
| 154 | + |
| 155 | + build-macos: |
| 156 | + runs-on: macos-latest |
| 157 | + steps: |
| 158 | + - name: Checkout |
| 159 | + uses: actions/checkout@v4 |
| 160 | + with: |
| 161 | + submodules: recursive |
| 162 | + |
| 163 | + - name: Extract version from tag |
| 164 | + id: version |
| 165 | + run: | |
| 166 | + if [[ "${{ github.ref }}" == refs/tags/* ]]; then |
| 167 | + TAG="${{ github.ref_name }}" |
| 168 | + VERSION_NAME="${TAG#v}" |
| 169 | + echo "version_name=$VERSION_NAME" >> $GITHUB_OUTPUT |
| 170 | + echo "Extracted version: $VERSION_NAME from tag: $TAG" |
| 171 | + else |
| 172 | + echo "version_name=0.1.0" >> $GITHUB_OUTPUT |
| 173 | + echo "No tag detected, using default version: 0.1.0" |
| 174 | + fi |
| 175 | +
|
| 176 | + - name: Install Qt |
| 177 | + uses: jurplel/install-qt-action@v3 |
| 178 | + with: |
| 179 | + version: '6.8.0' |
| 180 | + modules: 'qt5compat qtimageformats' |
| 181 | + |
| 182 | + - name: Configure CMake |
| 183 | + run: cmake -B build -DCMAKE_BUILD_TYPE=Release -DAPP_VERSION=${{ steps.version.outputs.version_name }} |
| 184 | + |
| 185 | + - name: Build |
| 186 | + run: cmake --build build |
| 187 | + |
| 188 | + - name: Package macOS app bundle (tag only) |
| 189 | + if: startsWith(github.ref, 'refs/tags/') |
| 190 | + run: | |
| 191 | + cd build |
| 192 | + # CMake already produced app bundle |
| 193 | + cp -R apppaqetN.app paqetN.app |
| 194 | + echo "Packaged macOS build for version ${{ steps.version.outputs.version_name }}" |
| 195 | +
|
| 196 | + - name: Upload macOS artifacts (tag only) |
| 197 | + if: startsWith(github.ref, 'refs/tags/') |
| 198 | + uses: actions/upload-artifact@v4 |
| 199 | + with: |
| 200 | + name: paqetN-macos |
| 201 | + path: build/paqetN.app |
| 202 | + |
| 203 | + release: |
| 204 | + needs: [build-linux, build-windows, build-macos] |
| 205 | + if: startsWith(github.ref, 'refs/tags/') |
| 206 | + runs-on: ubuntu-latest |
| 207 | + permissions: |
| 208 | + contents: write |
| 209 | + steps: |
| 210 | + - name: Checkout |
| 211 | + uses: actions/checkout@v4 |
| 212 | + with: |
| 213 | + ref: ${{ github.ref }} |
| 214 | + |
| 215 | + - name: Extract changelog for tag |
| 216 | + run: | |
| 217 | + TAG="${{ github.ref_name }}" |
| 218 | + # Extract the section for this tag from CHANGELOG.md |
| 219 | + awk -v tag="$TAG" ' |
| 220 | + $0 ~ "^## \\[" tag "\\]" { found=1; print; next } |
| 221 | + found && $0 ~ /^## / { exit } |
| 222 | + found { print } |
| 223 | + ' CHANGELOG.md > release_notes.md |
| 224 | +
|
| 225 | + # If no specific changelog found, use a default message |
| 226 | + if [ ! -s release_notes.md ]; then |
| 227 | + echo "Release $TAG" > release_notes.md |
| 228 | + echo "" >> release_notes.md |
| 229 | + echo "See [CHANGELOG.md](CHANGELOG.md) for details." >> release_notes.md |
| 230 | + fi |
| 231 | +
|
| 232 | + - name: Download Linux artifacts |
| 233 | + uses: actions/download-artifact@v4 |
| 234 | + with: |
| 235 | + name: paqetN-linux |
| 236 | + path: artifacts/linux |
| 237 | + |
| 238 | + - name: Download Windows artifacts |
| 239 | + uses: actions/download-artifact@v4 |
| 240 | + with: |
| 241 | + name: paqetN-windows |
| 242 | + path: artifacts/windows |
| 243 | + |
| 244 | + - name: Download macOS artifacts |
| 245 | + uses: actions/download-artifact@v4 |
| 246 | + with: |
| 247 | + name: paqetN-macos |
| 248 | + path: artifacts/macos |
| 249 | + |
| 250 | + - name: Create release archives |
| 251 | + run: | |
| 252 | + cd artifacts |
| 253 | +
|
| 254 | + # Linux archive |
| 255 | + tar -czf paqetN-linux-${{ github.ref_name }}.tar.gz -C linux . |
| 256 | +
|
| 257 | + # Windows archive |
| 258 | + cd windows |
| 259 | + zip -r ../paqetN-windows-${{ github.ref_name }}.zip . |
| 260 | + cd .. |
| 261 | +
|
| 262 | + # macOS archive |
| 263 | + tar -czf paqetN-macos-${{ github.ref_name }}.tar.gz -C macos . |
| 264 | +
|
| 265 | + - name: List release files |
| 266 | + id: release_files |
| 267 | + run: | |
| 268 | + cd artifacts |
| 269 | + shopt -s nullglob |
| 270 | + archives=(*.tar.gz *.zip) |
| 271 | +
|
| 272 | + if [ ${#archives[@]} -eq 0 ]; then |
| 273 | + echo "::error::No release archives found" |
| 274 | + ls -la |
| 275 | + exit 1 |
| 276 | + fi |
| 277 | +
|
| 278 | + echo "Files to attach:" |
| 279 | + printf '%s\n' "${archives[@]}" | sort |
| 280 | +
|
| 281 | + echo "files<<EOF" >> $GITHUB_OUTPUT |
| 282 | + for file in "${archives[@]}"; do |
| 283 | + echo "artifacts/$file" >> $GITHUB_OUTPUT |
| 284 | + done |
| 285 | + echo "EOF" >> $GITHUB_OUTPUT |
| 286 | +
|
| 287 | + - name: Create GitHub Release |
| 288 | + uses: softprops/action-gh-release@v2 |
| 289 | + with: |
| 290 | + body_path: release_notes.md |
| 291 | + files: ${{ steps.release_files.outputs.files }} |
| 292 | + generate_release_notes: false |
| 293 | + draft: false |
| 294 | + prerelease: ${{ contains(github.ref_name, 'alpha') || contains(github.ref_name, 'beta') || contains(github.ref_name, 'rc') }} |
| 295 | + env: |
| 296 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments