|
1 | | -name: Build |
| 1 | +name: Build & Release |
2 | 2 |
|
3 | 3 | on: |
4 | 4 | push: |
5 | 5 | branches: |
6 | 6 | - main |
7 | 7 | - master |
| 8 | + - ci-cd |
8 | 9 | pull_request: |
9 | 10 | branches: |
10 | 11 | - main |
11 | 12 | - master |
| 13 | + - ci-cd |
12 | 14 |
|
13 | 15 | jobs: |
14 | | - pre-build: |
15 | | - name: Pre-Build |
| 16 | + # ── Read variables from vars.yml ──────────────────────────────────── |
| 17 | + read-vars: |
| 18 | + name: Read Variables |
16 | 19 | runs-on: ubuntu-latest |
| 20 | + outputs: |
| 21 | + version: ${{ steps.parse.outputs.version }} |
| 22 | + flutter_version: ${{ steps.parse.outputs.flutter_version }} |
| 23 | + steps: |
| 24 | + - uses: actions/checkout@v4 |
| 25 | + - name: Parse vars.yml |
| 26 | + id: parse |
| 27 | + run: | |
| 28 | + version=$(grep 'name: tk_version' vars.yml -A1 | grep 'value:' | awk '{print $2}') |
| 29 | + flutter_version=$(grep 'name: flutter_version' vars.yml -A1 | grep 'value:' | awk '{print $2}') |
| 30 | + echo "version=$version" >> "$GITHUB_OUTPUT" |
| 31 | + echo "flutter_version=$flutter_version" >> "$GITHUB_OUTPUT" |
| 32 | + echo "Version: $version" |
| 33 | + echo "Flutter: $flutter_version" |
| 34 | +
|
| 35 | + # ── Build Flutter web client ──────────────────────────────────────── |
| 36 | + build-web-client: |
| 37 | + name: Build Web Client |
| 38 | + needs: [read-vars] |
| 39 | + runs-on: ubuntu-latest |
| 40 | + steps: |
| 41 | + - uses: actions/checkout@v4 |
| 42 | + - uses: subosito/flutter-action@v2 |
| 43 | + with: |
| 44 | + flutter-version: ${{ needs.read-vars.outputs.flutter_version }} |
| 45 | + channel: stable |
| 46 | + - name: Generate Flutter Icons |
| 47 | + working-directory: client |
| 48 | + run: dart run flutter_launcher_icons |
| 49 | + - name: Build Flutter web (release) |
| 50 | + working-directory: client |
| 51 | + run: flutter build web --release --wasm --no-web-resources-cdn |
| 52 | + - name: Upload web client artifact |
| 53 | + uses: actions/upload-artifact@v4 |
| 54 | + with: |
| 55 | + name: web-client |
| 56 | + path: client/build/web/ |
| 57 | + retention-days: 1 |
| 58 | + |
| 59 | + # ── Build server binaries ─────────────────────────────────────────── |
| 60 | + build-server: |
| 61 | + name: Build Server (${{ matrix.name }}) |
| 62 | + needs: [read-vars, build-web-client] |
| 63 | + strategy: |
| 64 | + matrix: |
| 65 | + include: |
| 66 | + - name: linux-x86_64 |
| 67 | + runner: ubuntu-latest |
| 68 | + target: x86_64-unknown-linux-musl |
| 69 | + artifact: timekeeper-server-linux-x86_64 |
| 70 | + archive: tar.gz |
| 71 | + - name: windows-x86_64 |
| 72 | + runner: ubuntu-latest |
| 73 | + target: x86_64-pc-windows-gnu |
| 74 | + artifact: timekeeper-server-windows-x86_64 |
| 75 | + archive: zip |
| 76 | + - name: macos-x86_64 |
| 77 | + runner: macos-latest |
| 78 | + target: x86_64-apple-darwin |
| 79 | + artifact: timekeeper-server-macos-x86_64 |
| 80 | + archive: tar.gz |
| 81 | + - name: macos-aarch64 |
| 82 | + runner: macos-latest |
| 83 | + target: aarch64-apple-darwin |
| 84 | + artifact: timekeeper-server-macos-aarch64 |
| 85 | + archive: tar.gz |
| 86 | + runs-on: ${{ matrix.runner }} |
| 87 | + env: |
| 88 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 89 | + steps: |
| 90 | + - uses: actions/checkout@v4 |
| 91 | + |
| 92 | + - name: Install Protoc |
| 93 | + uses: arduino/setup-protoc@v3 |
| 94 | + with: |
| 95 | + repo-token: ${{ secrets.GITHUB_TOKEN }} |
| 96 | + |
| 97 | + - uses: actions-rust-lang/setup-rust-toolchain@v1 |
| 98 | + with: |
| 99 | + target: ${{ matrix.target }} |
| 100 | + |
| 101 | + # Linux-specific: install musl toolchain |
| 102 | + - name: Install musl tools |
| 103 | + if: matrix.target == 'x86_64-unknown-linux-musl' |
| 104 | + run: sudo apt-get update && sudo apt-get install -y musl-tools |
| 105 | + |
| 106 | + # Windows cross-compile: install mingw-w64 |
| 107 | + - name: Install mingw-w64 |
| 108 | + if: matrix.target == 'x86_64-pc-windows-gnu' |
| 109 | + run: sudo apt-get update && sudo apt-get install -y gcc-mingw-w64-x86-64 |
| 110 | + |
| 111 | + # Build the server |
| 112 | + - name: Build server (release) |
| 113 | + run: cargo build --release --target ${{ matrix.target }} |
| 114 | + |
| 115 | + # Download the web client artifact |
| 116 | + - name: Download web client |
| 117 | + uses: actions/download-artifact@v4 |
| 118 | + with: |
| 119 | + name: web-client |
| 120 | + path: staging/client/build/web |
| 121 | + |
| 122 | + # Prepare the release archive |
| 123 | + - name: Prepare archive (tar.gz) |
| 124 | + if: matrix.archive == 'tar.gz' |
| 125 | + run: | |
| 126 | + mkdir -p staging |
| 127 | + cp target/${{ matrix.target }}/release/main staging/timekeeper-server |
| 128 | + chmod +x staging/timekeeper-server |
| 129 | + cd staging |
| 130 | + tar -czf ../${{ matrix.artifact }}.tar.gz . |
| 131 | +
|
| 132 | + - name: Prepare archive (zip) |
| 133 | + if: matrix.archive == 'zip' |
| 134 | + run: | |
| 135 | + mkdir -p staging |
| 136 | + cp target/${{ matrix.target }}/release/main.exe staging/timekeeper-server.exe |
| 137 | + cd staging |
| 138 | + zip -r ../${{ matrix.artifact }}.zip . |
| 139 | +
|
| 140 | + - name: Upload release artifact |
| 141 | + uses: actions/upload-artifact@v4 |
| 142 | + with: |
| 143 | + name: ${{ matrix.artifact }} |
| 144 | + path: ${{ matrix.artifact }}.${{ matrix.archive }} |
| 145 | + retention-days: 5 |
17 | 146 |
|
| 147 | + # ── Build client desktop & Android ────────────────────────────────── |
| 148 | + build-client: |
| 149 | + name: Build Client (${{ matrix.name }}) |
| 150 | + needs: [read-vars] |
| 151 | + strategy: |
| 152 | + matrix: |
| 153 | + include: |
| 154 | + - name: linux-x86_64 |
| 155 | + runner: ubuntu-latest |
| 156 | + build-cmd: linux |
| 157 | + artifact: timekeeper-client-linux-x86_64 |
| 158 | + artifact-path: client/build/linux/x64/release/bundle |
| 159 | + archive: tar.gz |
| 160 | + - name: windows-x86_64 |
| 161 | + runner: windows-latest |
| 162 | + build-cmd: windows |
| 163 | + artifact: timekeeper-client-windows-x86_64 |
| 164 | + artifact-path: client/build/windows/x64/runner/Release |
| 165 | + archive: zip |
| 166 | + - name: macos-x86_64 |
| 167 | + runner: macos-latest |
| 168 | + build-cmd: macos |
| 169 | + artifact: timekeeper-client-macos-x86_64 |
| 170 | + artifact-path: client/build/macos/Build/Products/Release |
| 171 | + archive: zip |
| 172 | + - name: macos-aarch64 |
| 173 | + runner: macos-latest |
| 174 | + build-cmd: macos |
| 175 | + artifact: timekeeper-client-macos-aarch64 |
| 176 | + artifact-path: client/build/macos/Build/Products/Release |
| 177 | + archive: zip |
| 178 | + - name: android |
| 179 | + runner: ubuntu-latest |
| 180 | + build-cmd: apk |
| 181 | + artifact: timekeeper-client-android |
| 182 | + artifact-path: client/build/app/outputs/flutter-apk/app-release.apk |
| 183 | + archive: none |
| 184 | + runs-on: ${{ matrix.runner }} |
18 | 185 | steps: |
19 | 186 | - uses: actions/checkout@v4 |
| 187 | + |
| 188 | + - uses: subosito/flutter-action@v2 |
| 189 | + with: |
| 190 | + flutter-version: ${{ needs.read-vars.outputs.flutter_version }} |
| 191 | + channel: stable |
| 192 | + |
| 193 | + # Android needs Java |
| 194 | + - name: Setup Java |
| 195 | + if: matrix.build-cmd == 'apk' |
| 196 | + uses: actions/setup-java@v4 |
| 197 | + with: |
| 198 | + distribution: temurin |
| 199 | + java-version: "17" |
| 200 | + |
| 201 | + # Linux desktop needs build dependencies |
| 202 | + - name: Install Linux dependencies |
| 203 | + if: matrix.build-cmd == 'linux' |
| 204 | + run: | |
| 205 | + sudo apt-get update |
| 206 | + sudo apt-get install -y clang cmake ninja-build pkg-config libgtk-3-dev liblzma-dev libstdc++-12-dev |
| 207 | +
|
| 208 | + - name: Generate Flutter Icons |
| 209 | + working-directory: client |
| 210 | + run: dart run flutter_launcher_icons |
| 211 | + |
| 212 | + - name: Build client (release) |
| 213 | + working-directory: client |
| 214 | + run: flutter build ${{ matrix.build-cmd }} --release |
| 215 | + |
| 216 | + # Archive: tar.gz (Linux) |
| 217 | + - name: Prepare archive (tar.gz) |
| 218 | + if: matrix.archive == 'tar.gz' |
| 219 | + run: | |
| 220 | + cd ${{ matrix.artifact-path }} |
| 221 | + tar -czf ${{ github.workspace }}/${{ matrix.artifact }}.tar.gz . |
| 222 | +
|
| 223 | + # Archive: zip (Windows/macOS) |
| 224 | + - name: Prepare archive (zip - Unix) |
| 225 | + if: matrix.archive == 'zip' && runner.os != 'Windows' |
| 226 | + run: | |
| 227 | + cd "${{ matrix.artifact-path }}" |
| 228 | + zip -r "${{ github.workspace }}/${{ matrix.artifact }}.zip" . |
| 229 | +
|
| 230 | + - name: Prepare archive (zip - Windows) |
| 231 | + if: matrix.archive == 'zip' && runner.os == 'Windows' |
| 232 | + shell: pwsh |
| 233 | + run: | |
| 234 | + Compress-Archive -Path "${{ matrix.artifact-path }}\*" -DestinationPath "${{ github.workspace }}\${{ matrix.artifact }}.zip" |
| 235 | +
|
| 236 | + # Upload archived artifact |
| 237 | + - name: Upload artifact (archived) |
| 238 | + if: matrix.archive != 'none' |
| 239 | + uses: actions/upload-artifact@v4 |
| 240 | + with: |
| 241 | + name: ${{ matrix.artifact }} |
| 242 | + path: ${{ matrix.artifact }}.${{ matrix.archive }} |
| 243 | + retention-days: 5 |
| 244 | + |
| 245 | + # Upload APK directly (no archive needed) |
| 246 | + - name: Upload artifact (apk) |
| 247 | + if: matrix.archive == 'none' |
| 248 | + uses: actions/upload-artifact@v4 |
| 249 | + with: |
| 250 | + name: ${{ matrix.artifact }} |
| 251 | + path: ${{ matrix.artifact-path }} |
| 252 | + retention-days: 5 |
| 253 | + |
| 254 | + # ── Create GitHub Release ─────────────────────────────────────────── |
| 255 | + release: |
| 256 | + name: Create Release |
| 257 | + needs: [read-vars, build-server, build-client] |
| 258 | + if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master' || github.ref == 'refs/heads/ci-cd') |
| 259 | + runs-on: ubuntu-latest |
| 260 | + permissions: |
| 261 | + contents: write |
| 262 | + steps: |
| 263 | + - uses: actions/checkout@v4 |
| 264 | + |
| 265 | + - name: Download all artifacts |
| 266 | + uses: actions/download-artifact@v4 |
| 267 | + with: |
| 268 | + path: artifacts |
| 269 | + pattern: timekeeper-* |
| 270 | + |
| 271 | + - name: List artifacts |
| 272 | + run: find artifacts -type f |
| 273 | + |
| 274 | + - name: Create GitHub Release |
| 275 | + uses: softprops/action-gh-release@v2 |
| 276 | + with: |
| 277 | + tag_name: v${{ needs.read-vars.outputs.version }} |
| 278 | + name: TimeKeeper v${{ needs.read-vars.outputs.version }} |
| 279 | + draft: true |
| 280 | + prerelease: false |
| 281 | + files: | |
| 282 | + artifacts/**/* |
0 commit comments