aboutsummaryrefslogtreecommitdiff
path: root/.github/workflows/ci.yml
blob: b9c03f5f29827729608d0fcb4f4cdcb208208de8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
name: CI

on:
  push:
    branches: [main]
    tags: ['v*']
  pull_request:
  workflow_dispatch:

env:
  REGISTRY: ghcr.io
  IMAGE_NAME: ghcr.io/sulfurnitride/fluorine-builder

jobs:
  build:
    runs-on: ubuntu-latest
    permissions:
      contents: write
      packages: write

    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Log in to GHCR
        uses: docker/login-action@v3
        with:
          registry: ${{ env.REGISTRY }}
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}

      - name: Pull or build Docker image
        run: |
          if docker pull ${{ env.IMAGE_NAME }}:latest; then
            docker tag ${{ env.IMAGE_NAME }}:latest fluorine-builder:latest
          else
            echo "Pull failed, building from scratch..."
            docker build -t fluorine-builder:latest docker/
          fi

      - name: Restore ccache
        uses: actions/cache@v4
        with:
          path: ~/.cache/fluorine-ccache
          key: ccache-${{ runner.os }}-${{ github.sha }}
          restore-keys: |
            ccache-${{ runner.os }}-

      - name: Build inside container
        run: |
          mkdir -p ~/.cache/fluorine-ccache
          docker run --rm \
            -v "${{ github.workspace }}:/src:rw" \
            -v "$HOME/.cache/fluorine-ccache:/ccache:rw" \
            -e CCACHE_DIR=/ccache \
            -e CCACHE_BASEDIR=/src \
            -e CCACHE_COMPILERCHECK=content \
            -e CCACHE_SLOPPINESS=time_macros,include_file_mtime,include_file_ctime,pch_defines \
            -e CCACHE_MAXSIZE=5G \
            -e BUILD_MODE=tarball \
            -w /src \
            fluorine-builder:latest \
            bash -c 'ccache -s; bash /src/docker/build-inner.sh; echo "=== ccache stats after build ==="; ccache -s'

      - name: Upload build
        uses: actions/upload-artifact@v4
        with:
          name: Fluorine-Manager
          path: build/fluorine-manager/
          compression-level: 6
          if-no-files-found: warn

  build-nixos-mobase:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Install Nix
        uses: cachix/install-nix-action@v30
        with:
          nix_path: nixpkgs=channel:nixos-unstable

      - name: Cache Nix store
        uses: actions/cache@v4
        with:
          path: /tmp/nix-cache
          key: nix-mobase-${{ hashFiles('nix/mobase-shell.nix') }}
          restore-keys: nix-mobase-

      - name: Build mobase.so for NixOS
        run: |
          nix-shell nix/mobase-shell.nix --run "
            set -euo pipefail

            # Build libloot from source (not in nixpkgs)
            git clone --depth 1 https://github.com/loot/libloot.git /tmp/libloot
            cmake -S /tmp/libloot/cpp -B /tmp/libloot/build -G Ninja \
              -DCMAKE_BUILD_TYPE=Release \
              -DBUILD_SHARED_LIBS=ON \
              -DLIBLOOT_INSTALL_DOCS=OFF \
              -DBUILD_TESTING=OFF \
              -DCMAKE_INSTALL_PREFIX=/tmp/libloot-install
            cmake --build /tmp/libloot/build --parallel
            cmake --install /tmp/libloot/build

            # Configure full project (only mobase target will be built)
            # Use NIX_PYTHON3 (real nix python) for cmake, not the venv wrapper
            PYBIND11_DIR=\$(python3 -c 'import pybind11; print(pybind11.get_cmake_dir())')
            cmake -S . -B build-nix -G Ninja \
              -DCMAKE_BUILD_TYPE=RelWithDebInfo \
              -DPython_EXECUTABLE=\"\${NIX_PYTHON3}\" \
              -Dpybind11_DIR=\"\${PYBIND11_DIR}\" \
              -DBUILD_PLUGIN_PYTHON=ON \
              -DCMAKE_PREFIX_PATH=/tmp/libloot-install \
              -Dlibloot_DIR=/tmp/libloot-install

            # Build only mobase target
            cmake --build build-nix --target mobase --parallel

            # Package it
            mkdir -p nixos-mobase
            cp build-nix/libs/plugin_python/src/mobase/mobase.cpython-*-linux-gnu.so nixos-mobase/
            echo 'NixOS-compatible mobase pybind11 module for Fluorine Manager.' > nixos-mobase/README.txt
            echo 'Drop this .so into your plugins/libs/ directory, replacing the existing one.' >> nixos-mobase/README.txt
          "

      - name: Upload NixOS mobase
        uses: actions/upload-artifact@v4
        with:
          name: mobase-nixos
          path: nixos-mobase/
          compression-level: 6
          if-no-files-found: warn