From 567dd43c9665cd654482f2c1edf4a36e6fbf88e8 Mon Sep 17 00:00:00 2001 From: Fergus Molloy Date: Mon, 21 Jul 2025 23:55:46 +0100 Subject: [PATCH] add basic backend workflow --- .gitea/workflows/backend.yaml | 41 ++++++++++++++++++++++------------- backend/Justfile | 4 +--- backend/scripts/test.sh | 14 ++++++++++++ 3 files changed, 41 insertions(+), 18 deletions(-) create mode 100755 backend/scripts/test.sh diff --git a/.gitea/workflows/backend.yaml b/.gitea/workflows/backend.yaml index c537cc6..e3b4b8d 100644 --- a/.gitea/workflows/backend.yaml +++ b/.gitea/workflows/backend.yaml @@ -1,19 +1,30 @@ -name: Gitea Actions Demo -run-name: ${{ gitea.actor }} is testing out Gitea Actions 🚀 +name: Backend Actions +run-name: ${{ gitea.actor }} is running backend actions on: [push] jobs: - Explore-Gitea-Actions: - runs-on: ubuntu-latest + build: + runs-on: rust-latest steps: - - run: echo "🎉 The job was automatically triggered by a ${{ gitea.event_name }} event." - - run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by Gitea!" - - run: echo "🔎 The name of your branch is ${{ gitea.ref }} and your repository is ${{ gitea.repository }}." - - name: Check out repository code - uses: actions/checkout@v4 - - run: echo "💡 The ${{ gitea.repository }} repository has been cloned to the runner." - - run: echo "🖥️ The workflow is now ready to test your code on the runner." - - name: List files in the repository - run: | - ls ${{ gitea.workspace }} - - run: echo "🍏 This job's status is ${{ job.status }}." + - uses: actions/checkout@v4 + - name: Load Cache + uses: actions/cache@v4 + working-directory: ./backend + with: + path: | + ~/.cargo/registry + ~/.cargo/git + target + key: ${{ runner.os }}-cargo-${{ hashFiles('Cargo.lock') }} + - name: Build Binary + working-directory: ./backend + run: cargo build --release --locked + - name: Run Tests + working-directory: ./backend + run: ./scripts/test.sh + - name: Upload Test Logs + uses: actions/upload-artifact@v4 + working-directory: ./backend + with: + name: nuchat-${{ hashFiles('src/**') }}-${{ hashFiles('tests/**') }}.log + path: logs/* diff --git a/backend/Justfile b/backend/Justfile index f14fbb6..713cbc1 100644 --- a/backend/Justfile +++ b/backend/Justfile @@ -8,9 +8,7 @@ start: cargo run --features shutdown 2>&1 > logs/nuchat.log test: - cargo run --features shutdown -- --port 7001 2>&1 > logs/nuchat.log & - cargo test - curl -s -X POST localhost:7001/admin/shutdown + ./scripts/test.sh default := 'run' watch CMD=default: diff --git a/backend/scripts/test.sh b/backend/scripts/test.sh new file mode 100755 index 0000000..303a4bd --- /dev/null +++ b/backend/scripts/test.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +if [ ! -d logs ]; then + mkdir logs +fi + +# ensure server is not started +curl -s -X POST localhost:7001/admin/shutdown 2>&1 > /dev/null + +# start server +cargo run --features shutdown -- --port 7001 2>&1 > logs/nuchat.log & + +# run tests +cargo test | tee logs/test-output.log