|
| 1 | +name: Build and Test |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main, master, develop ] |
| 6 | + pull_request: |
| 7 | + branches: [ main, master, develop ] |
| 8 | + workflow_dispatch: |
| 9 | + workflow_call: |
| 10 | + |
| 11 | +jobs: |
| 12 | + python-tests: |
| 13 | + name: Test Python Package |
| 14 | + runs-on: ubuntu-latest |
| 15 | + strategy: |
| 16 | + matrix: |
| 17 | + python-version: ['3.8', '3.9', '3.10', '3.11', '3.12'] |
| 18 | + steps: |
| 19 | + - uses: actions/checkout@v4 |
| 20 | + with: |
| 21 | + submodules: recursive |
| 22 | + |
| 23 | + - name: Set up Python ${{ matrix.python-version }} |
| 24 | + uses: actions/setup-python@v5 |
| 25 | + with: |
| 26 | + python-version: ${{ matrix.python-version }} |
| 27 | + |
| 28 | + - name: Install dependencies |
| 29 | + timeout-minutes: 10 |
| 30 | + run: | |
| 31 | + python -m pip install --upgrade pip setuptools wheel |
| 32 | + pip install -e ".[dev]" |
| 33 | +
|
| 34 | + - name: Run tests |
| 35 | + timeout-minutes: 10 |
| 36 | + run: pytest --cov=lddecode --cov-report=xml |
| 37 | + |
| 38 | + - name: Upload coverage |
| 39 | + uses: codecov/codecov-action@v4 |
| 40 | + with: |
| 41 | + files: ./coverage.xml |
| 42 | + |
| 43 | + functional-tests: |
| 44 | + name: Functional Tests |
| 45 | + runs-on: ubuntu-latest |
| 46 | + steps: |
| 47 | + - uses: actions/checkout@v4 |
| 48 | + with: |
| 49 | + submodules: recursive |
| 50 | + |
| 51 | + - name: Set up Python |
| 52 | + uses: actions/setup-python@v5 |
| 53 | + with: |
| 54 | + python-version: '3.11' |
| 55 | + |
| 56 | + - name: Install dependencies |
| 57 | + timeout-minutes: 10 |
| 58 | + run: | |
| 59 | + sudo apt-get update |
| 60 | + sudo apt-get install -y cmake ffmpeg |
| 61 | + python -m pip install --upgrade pip setuptools wheel |
| 62 | + pip install -e . |
| 63 | +
|
| 64 | + - name: Configure CMake |
| 65 | + run: | |
| 66 | + mkdir -p build/testout |
| 67 | + cd build |
| 68 | + cmake -DCMAKE_BUILD_TYPE=Release .. |
| 69 | +
|
| 70 | + - name: Run functional tests |
| 71 | + timeout-minutes: 60 |
| 72 | + working-directory: build |
| 73 | + run: ctest --output-on-failure -V |
| 74 | + |
| 75 | + build-python-wheel: |
| 76 | + name: Build Python Wheel for PyPI |
| 77 | + runs-on: ubuntu-latest |
| 78 | + needs: [python-tests, functional-tests] |
| 79 | + steps: |
| 80 | + - uses: actions/checkout@v4 |
| 81 | + |
| 82 | + - name: Set up Python |
| 83 | + uses: actions/setup-python@v5 |
| 84 | + with: |
| 85 | + python-version: '3.11' |
| 86 | + |
| 87 | + - name: Build Python wheel |
| 88 | + run: | |
| 89 | + python -m pip install --upgrade pip build |
| 90 | + python -m build |
| 91 | +
|
| 92 | + - name: Upload Python wheel |
| 93 | + uses: actions/upload-artifact@v4 |
| 94 | + with: |
| 95 | + name: python-wheel |
| 96 | + path: dist/* |
| 97 | + retention-days: 7 |
| 98 | + |
| 99 | + build-flatpak: |
| 100 | + name: Build Flatpak |
| 101 | + runs-on: ubuntu-latest |
| 102 | + needs: [python-tests, functional-tests] |
| 103 | + container: |
| 104 | + image: bilelmoussaoui/flatpak-github-actions:freedesktop-24.08 |
| 105 | + options: --privileged |
| 106 | + steps: |
| 107 | + - uses: actions/checkout@v4 |
| 108 | + |
| 109 | + - name: Determine version |
| 110 | + id: version |
| 111 | + run: | |
| 112 | + if [[ "${{ github.ref }}" =~ ^refs/tags/v(.*)$ ]]; then |
| 113 | + echo "version=${BASH_REMATCH[1]}" >> $GITHUB_OUTPUT |
| 114 | + else |
| 115 | + echo "version=0.0.0-dev-${{ github.sha }}" >> $GITHUB_OUTPUT |
| 116 | + fi |
| 117 | +
|
| 118 | + - name: Generate version file |
| 119 | + run: | |
| 120 | + BRANCH="release" |
| 121 | + COMMIT="unknown" |
| 122 | + DIRTY="" |
| 123 | + |
| 124 | + if git describe --tags --exact-match > /dev/null 2>&1; then |
| 125 | + COMMIT=$(git describe --tags --exact-match | sed 's/^v//') |
| 126 | + BRANCH="release" |
| 127 | + elif git describe --tags --always > /dev/null 2>&1; then |
| 128 | + COMMIT=$(git describe --tags --always | sed 's/^v//') |
| 129 | + fi |
| 130 | + |
| 131 | + if [ -z "$BRANCH" ] || [ "$BRANCH" = "HEAD" ]; then |
| 132 | + BRANCH=$(git rev-parse --abbrev-ref HEAD) |
| 133 | + if [ "$BRANCH" = "HEAD" ]; then |
| 134 | + BRANCH="release" |
| 135 | + fi |
| 136 | + fi |
| 137 | + |
| 138 | + if [ -n "$(git status --porcelain)" ]; then |
| 139 | + DIRTY=":dirty" |
| 140 | + fi |
| 141 | + |
| 142 | + VERSION_STRING="${BRANCH}:${COMMIT}${DIRTY}" |
| 143 | + echo "$VERSION_STRING" > lddecode/version |
| 144 | + echo "Version: $VERSION_STRING" |
| 145 | +
|
| 146 | + - name: Build Flatpak |
| 147 | + uses: flatpak/flatpak-github-actions/flatpak-builder@v6 |
| 148 | + with: |
| 149 | + bundle: ld-decode-${{ steps.version.outputs.version }}-x86_64.flatpak |
| 150 | + manifest-path: packaging/flatpak/com.github.happycube.LdDecode.yml |
| 151 | + cache-key: flatpak-builder-${{ github.sha }} |
| 152 | + |
| 153 | + - name: Upload Flatpak |
| 154 | + uses: actions/upload-artifact@v4 |
| 155 | + with: |
| 156 | + name: flatpak-package |
| 157 | + path: ld-decode-*.flatpak |
| 158 | + retention-days: 90 |
| 159 | + |
| 160 | + build-windows: |
| 161 | + name: Build Windows MSI |
| 162 | + runs-on: windows-latest |
| 163 | + needs: [python-tests, functional-tests] |
| 164 | + steps: |
| 165 | + - uses: actions/checkout@v4 |
| 166 | + |
| 167 | + - name: Set up Python |
| 168 | + uses: actions/setup-python@v5 |
| 169 | + with: |
| 170 | + python-version: '3.11' |
| 171 | + |
| 172 | + - name: Install WiX Toolset |
| 173 | + shell: pwsh |
| 174 | + run: | |
| 175 | + choco install wixtoolset -y |
| 176 | + $wixPath = "C:\Program Files (x86)\WiX Toolset v3.14\bin" |
| 177 | + if (Test-Path "C:\Program Files (x86)\WiX Toolset v3.11\bin") { |
| 178 | + $wixPath = "C:\Program Files (x86)\WiX Toolset v3.11\bin" |
| 179 | + } |
| 180 | + echo $wixPath | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append |
| 181 | + Write-Host "WiX path: $wixPath" |
| 182 | +
|
| 183 | + - name: Build MSI |
| 184 | + shell: pwsh |
| 185 | + run: | |
| 186 | + $version = "0.0.0.dev0+git.${{ github.sha }}" |
| 187 | + if ("${{ github.ref }}" -match '^refs/tags/v(.*)$') { |
| 188 | + $version = $matches[1] |
| 189 | + } |
| 190 | + |
| 191 | + # Generate version file before build |
| 192 | + $branch = "release" |
| 193 | + $commit = "unknown" |
| 194 | + $dirty = "" |
| 195 | + |
| 196 | + try { |
| 197 | + $tagDesc = & git describe --tags --exact-match 2>$null |
| 198 | + if ($LASTEXITCODE -eq 0) { |
| 199 | + $commit = $tagDesc.Trim() -replace '^v', '' |
| 200 | + $branch = "release" |
| 201 | + } else { |
| 202 | + $describeResult = & git describe --tags --always 2>$null |
| 203 | + if ($LASTEXITCODE -eq 0) { |
| 204 | + $commit = $describeResult.Trim() -replace '^v', '' |
| 205 | + } |
| 206 | + $branchResult = & git rev-parse --abbrev-ref HEAD 2>$null |
| 207 | + if ($LASTEXITCODE -eq 0) { |
| 208 | + $branch = $branchResult.Trim() |
| 209 | + if ($branch -eq "HEAD") { $branch = "release" } |
| 210 | + } |
| 211 | + } |
| 212 | + |
| 213 | + $statusResult = & git status --porcelain 2>$null |
| 214 | + if ($LASTEXITCODE -eq 0 -and $statusResult.Length -gt 0) { |
| 215 | + $dirty = ":dirty" |
| 216 | + } |
| 217 | + } catch { |
| 218 | + Write-Host "Note: Could not get git info, using defaults" -ForegroundColor Gray |
| 219 | + } |
| 220 | + |
| 221 | + $versionString = "$branch`:$commit$dirty" |
| 222 | + Set-Content "lddecode/version" $versionString |
| 223 | + Write-Host "Version: $versionString" -ForegroundColor Cyan |
| 224 | + |
| 225 | + .\packaging\windows\build_msi.ps1 -Version $version |
| 226 | +
|
| 227 | + - name: Upload MSI |
| 228 | + uses: actions/upload-artifact@v4 |
| 229 | + with: |
| 230 | + name: windows-msi |
| 231 | + path: ld-decode-*-win64.msi |
| 232 | + retention-days: 90 |
| 233 | + |
| 234 | + build-macos: |
| 235 | + name: Build macOS DMG |
| 236 | + runs-on: macos-latest |
| 237 | + needs: [python-tests, functional-tests] |
| 238 | + steps: |
| 239 | + - uses: actions/checkout@v4 |
| 240 | + |
| 241 | + - name: Set up Python |
| 242 | + uses: actions/setup-python@v5 |
| 243 | + with: |
| 244 | + python-version: '3.11' |
| 245 | + |
| 246 | + - name: Install dependencies and build bundle |
| 247 | + run: | |
| 248 | + python -m pip install --upgrade pip pyinstaller |
| 249 | + pip install -e . |
| 250 | + pyinstaller packaging/macos/ld-decode.spec --clean |
| 251 | +
|
| 252 | + - name: Install create-dmg |
| 253 | + run: brew install create-dmg |
| 254 | + |
| 255 | + - name: Package DMG |
| 256 | + run: | |
| 257 | + # Generate version file before build |
| 258 | + BRANCH="release" |
| 259 | + COMMIT="unknown" |
| 260 | + DIRTY="" |
| 261 | + |
| 262 | + if git describe --tags --exact-match > /dev/null 2>&1; then |
| 263 | + COMMIT=$(git describe --tags --exact-match | sed 's/^v//') |
| 264 | + BRANCH="release" |
| 265 | + elif git describe --tags --always > /dev/null 2>&1; then |
| 266 | + COMMIT=$(git describe --tags --always | sed 's/^v//') |
| 267 | + fi |
| 268 | + |
| 269 | + if [ -z "$BRANCH" ] || [ "$BRANCH" = "HEAD" ]; then |
| 270 | + BRANCH=$(git rev-parse --abbrev-ref HEAD) |
| 271 | + if [ "$BRANCH" = "HEAD" ]; then |
| 272 | + BRANCH="release" |
| 273 | + fi |
| 274 | + fi |
| 275 | + |
| 276 | + if [ -n "$(git status --porcelain)" ]; then |
| 277 | + DIRTY=":dirty" |
| 278 | + fi |
| 279 | + |
| 280 | + VERSION_STRING="${BRANCH}:${COMMIT}${DIRTY}" |
| 281 | + echo "$VERSION_STRING" > lddecode/version |
| 282 | + echo "Version: $VERSION_STRING" |
| 283 | + |
| 284 | + VERSION="0.0.0-dev-${{ github.sha }}" |
| 285 | + if [[ "${{ github.ref }}" =~ ^refs/tags/v(.*)$ ]]; then |
| 286 | + VERSION="${BASH_REMATCH[1]}" |
| 287 | + fi |
| 288 | + |
| 289 | + create-dmg \ |
| 290 | + --volname "ld-decode" \ |
| 291 | + --window-pos 200 120 \ |
| 292 | + --window-size 800 400 \ |
| 293 | + --icon-size 100 \ |
| 294 | + --icon "ld-decode.app" 200 190 \ |
| 295 | + --hide-extension "ld-decode.app" \ |
| 296 | + --app-drop-link 600 185 \ |
| 297 | + "ld-decode-${VERSION}-macos.dmg" \ |
| 298 | + "dist/ld-decode.app" || true |
| 299 | + |
| 300 | + # Fallback to hdiutil if create-dmg fails |
| 301 | + if [ ! -f "ld-decode-${VERSION}-macos.dmg" ]; then |
| 302 | + echo "Using hdiutil fallback..." |
| 303 | + mkdir -p dmg_staging |
| 304 | + cp -R dist/ld-decode.app dmg_staging/ |
| 305 | + ln -s /Applications dmg_staging/Applications |
| 306 | + |
| 307 | + hdiutil create -volname "ld-decode" \ |
| 308 | + -srcfolder dmg_staging \ |
| 309 | + -ov -format UDZO \ |
| 310 | + "ld-decode-${VERSION}-macos.dmg" |
| 311 | + |
| 312 | + rm -rf dmg_staging |
| 313 | + fi |
| 314 | +
|
| 315 | + - name: Upload DMG |
| 316 | + uses: actions/upload-artifact@v4 |
| 317 | + with: |
| 318 | + name: macos-dmg |
| 319 | + path: ld-decode-*-macos.dmg |
| 320 | + retention-days: 90 |
0 commit comments