diff --git a/.github/workflows/c-cpp.yml b/.github/workflows/c-cpp.yml index da625fc..9a0232a 100644 --- a/.github/workflows/c-cpp.yml +++ b/.github/workflows/c-cpp.yml @@ -1,86 +1,114 @@ +--- name: C/C++ CI -on: +"on": push: - branches: [ "main" ] + branches: ["main"] pull_request: - branches: [ "main" ] + branches: ["main"] jobs: install-dependencies: name: Installing Dependencies runs-on: ubuntu-latest - container: ghcr.io/gravity-sim/deps:latest steps: - uses: actions/checkout@v4 - - name: Setup complete - run: echo "Dependencies are pre-installed in the container" + - name: Cache APT packages + uses: actions/cache@v3 + with: + path: /var/cache/apt + key: "${{ runner.os }}-apt-${{ hashFiles('.github/workflows/c-cpp.yml') }}" + restore-keys: "${{ runner.os }}-apt-" + - name: Cache build artifacts + uses: actions/cache@v3 + with: + path: | + src/*.o + tests/*.o + key: "${{ runner.os }}-build-${{ hashFiles('**/*.c') }}" + restore-keys: "${{ runner.os }}-build-" + - name: Install dependencies + run: | + sudo apt-get update + sudo apt-get install -y build-essential libgl1-mesa-dev libglew-dev libglfw3-dev libopenmpi-dev - build: - name: Build + test: + name: Test runs-on: ubuntu-latest needs: install-dependencies - container: ghcr.io/gravity-sim/deps:latest steps: - uses: actions/checkout@v4 - - name: Restore build cache - id: build-cache - uses: actions/cache/restore@v3 + - name: Cache APT packages + uses: actions/cache@v3 with: - path: | - src/*.o - tests/*.o - key: ${{ runner.os }}-build-${{ hashFiles('**/*.c') }} - - name: Build - run: make - - name: Save build cache - if: steps.build-cache.outputs.cache-hit != 'true' - uses: actions/cache/save@v3 + path: /var/cache/apt + key: "${{ runner.os }}-apt-${{ hashFiles('.github/workflows/c-cpp.yml') }}" + restore-keys: "${{ runner.os }}-apt-" + - name: Install dependencies + run: | + sudo apt-get update + sudo apt-get install -y build-essential libgl1-mesa-dev libglew-dev libglfw3-dev libopenmpi-dev + - name: Restore build cache + uses: actions/cache@v3 with: path: | src/*.o tests/*.o - key: ${{ steps.build-cache.outputs.cache-primary-key }} + key: "${{ runner.os }}-build-${{ hashFiles('**/*.c') }}" + restore-keys: "${{ runner.os }}-build-" + - name: Test + run: make test - test: - name: Test + build: + name: Build runs-on: ubuntu-latest - needs: build - container: ghcr.io/gravity-sim/deps:latest + needs: test steps: - uses: actions/checkout@v4 + - name: Cache APT packages + uses: actions/cache@v3 + with: + path: /var/cache/apt + key: "${{ runner.os }}-apt-${{ hashFiles('.github/workflows/c-cpp.yml') }}" + restore-keys: "${{ runner.os }}-apt-" + - name: Install dependencies + run: | + sudo apt-get update + sudo apt-get install -y build-essential libgl1-mesa-dev libglew-dev libglfw3-dev libopenmpi-dev - name: Restore build cache - uses: actions/cache/restore@v3 + uses: actions/cache@v3 with: path: | src/*.o tests/*.o - key: ${{ runner.os }}-build-${{ hashFiles('**/*.c') }} - - name: Test - run: make test + key: "${{ runner.os }}-build-${{ hashFiles('**/*.c') }}" + restore-keys: "${{ runner.os }}-build-" + - name: Build + run: make clean && make make: name: Make runs-on: ubuntu-latest - needs: test - container: ghcr.io/gravity-sim/deps:latest + needs: build steps: - - uses: actions/checkout@v4 - - name: Install dependencies - run: | - sudo apt-get update - sudo apt-get install -y build-essential libgl1-mesa-dev libglew-dev libglfw3-dev - - name: Build - run: make - - name: Test - run: make test - uses: actions/checkout@v4 + - name: Cache APT packages + uses: actions/cache@v3 + with: + path: /var/cache/apt + key: "${{ runner.os }}-apt-${{ hashFiles('.github/workflows/c-cpp.yml') }}" + restore-keys: "${{ runner.os }}-apt-" + - name: Install dependencies + run: | + sudo apt-get update + sudo apt-get install -y build-essential libgl1-mesa-dev libglew-dev libglfw3-dev libopenmpi-dev - name: Restore build cache - uses: actions/cache/restore@v3 + uses: actions/cache@v3 with: path: | src/*.o tests/*.o - key: ${{ runner.os }}-build-${{ hashFiles('**/*.c') }} + key: "${{ runner.os }}-build-${{ hashFiles('**/*.c') }}" + restore-keys: "${{ runner.os }}-build-" - name: Make - run: make + run: make clean && make diff --git a/README.md b/README.md index 5370b9c..cc3ac06 100644 --- a/README.md +++ b/README.md @@ -77,11 +77,11 @@ To set up and compile the project on your local machine, follow these steps: ## Continuous Integration -This project uses a GitHub Actions workflow that runs inside a prebuilt Docker -container containing all required OpenGL dependencies. The workflow consists of -four sequential jobs: **Installing Dependencies**, **Build**, **Test**, and -**Make**. Compiled object files are cached between jobs to speed up subsequent -steps. +This project uses a GitHub Actions workflow with four sequential jobs: +**Installing Dependencies**, **Test**, **Build**, and **Make**. Each job +installs the required packages with `apt-get`, and compiled object files are +cached between jobs to speed up subsequent runs. The build steps run +`make clean` before `make` to ensure a fresh compilation each time. ## Usage