yavsc/.forgejo/workflows/buildAndTest.yml

97 lines
3.3 KiB
YAML
Raw Normal View History

2026-02-02 00:39:06 +00:00
# This workflow will build a .NET project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net
name: Dotnet build and test
on:
workflow_dispatch:
inputs:
logLevel:
description: 'Log level'
required: true
default: 'warning'
type: choice
options:
- info
- warning
- debug
tags:
description: 'Test scenario tags'
required: false
type: boolean
push:
branches: [ "main", "release/*", "hotfix/*", "fix/*" ]
2026-02-02 00:39:06 +00:00
pull_request:
branches: [ "main", "release/*", "hotfix/*", "fix/*" ]
2026-02-02 00:39:06 +00:00
jobs:
build:
2026-08-16 13:03:17 +01:00
runs-on: docker
2026-08-26 04:52:57 +01:00
container:
2026-11-09 17:17:10 +00:00
image: pazof/yavsc-build-env:debian13-dotnet10-android36-jdk21-v5
2026-02-02 00:39:06 +00:00
steps:
- name: Clone yavsc
run: |
2026-09-13 03:25:09 +01:00
set -e
cd /src
2026-11-10 14:18:52 +00:00
echo "🔄 Cloning repository ${FORGEJO_SERVER_URL}/${FORGEJO_REPOSITORY}.git"
2026-09-19 18:00:09 +01:00
git clone "${FORGEJO_SERVER_URL}/${FORGEJO_REPOSITORY}.git" _src
cd _src
if [ -n "${GITHUB_REF:-}" ]; then
git fetch origin "$GITHUB_REF"
git checkout FETCH_HEAD
fi
git submodule update --init --recursive
2026-08-26 01:42:59 +01:00
echo "✅ Checked out at $(git rev-parse HEAD) on $(git branch --show-current 2>/dev/null || echo detached HEAD)"
2026-09-07 11:54:48 +01:00
- name: Secret scan
2026-09-07 12:08:57 +01:00
run: |
echo "🔍 Scanning for secrets..."
2026-11-09 15:32:01 +00:00
cd /src/_src && dotnet tool restore || true
dotnet picket git --verbose --redact --exit-code 1 --log-opts main..HEAD
- name: Build
run: |
echo "🏗️ Building the solution..."
cd /src/_src && dotnet build --verbosity normal
2026-11-10 14:18:52 +00:00
- name: Start PostgreSQL
2026-11-09 22:02:53 +00:00
run: |
2026-11-10 14:18:52 +00:00
set -e
echo "🐘 Starting local PostgreSQL..."
if docker ps -a --format '{{.Names}}' | grep -qx 'yavsc-ci-postgres'; then
echo "PostgreSQL container already exists; restarting it"
docker rm -f yavsc-ci-postgres >/dev/null 2>&1 || true
fi
docker run -d \
--name yavsc-ci-postgres \
-e POSTGRES_USER=postgres \
-e POSTGRES_PASSWORD=postgres \
-e POSTGRES_DB=postgres \
-p 55432:5432 \
postgres:16
for i in $(seq 1 40); do
2026-11-09 22:02:53 +00:00
if pg_isready -h 127.0.0.1 -p 55432 -U postgres >/dev/null 2>&1; then
2026-11-10 14:18:52 +00:00
echo "✅ PostgreSQL is ready"
2026-11-09 22:02:53 +00:00
exit 0
fi
2026-11-10 14:18:52 +00:00
echo "PostgreSQL not ready yet ($i/40)"
2026-11-09 22:02:53 +00:00
sleep 2
done
echo "❌ PostgreSQL did not become ready in time" >&2
2026-11-10 14:18:52 +00:00
docker logs yavsc-ci-postgres || true
2026-11-09 22:02:53 +00:00
exit 1
2026-02-02 00:39:06 +00:00
- name: Test
2026-11-09 21:20:26 +00:00
env:
YAVSC_API_TEST_DB_PROVIDER: npgsql
2026-11-09 22:02:53 +00:00
YAVSC_API_TEST_NPGSQL_ADMIN_CONNECTION: Host=127.0.0.1;Port=55432;Database=postgres;Username=postgres;Password=postgres;Include Error Detail=true
2026-08-25 23:06:25 +01:00
run: |
2026-08-26 05:44:46 +01:00
echo "🚀 Lancement des tests..."
cd /src/_src && dotnet test \
--report-xunit \
--report-xunit-html \
--report-xunit-html-filename "test-results.html"
2026-09-25 23:05:16 +01:00
TEST_EXIT_CODE=$?
echo "Test exit code: $TEST_EXIT_CODE"
if [ $TEST_EXIT_CODE -ne 0 ]; then
echo "❌ Tests failed with exit code $TEST_EXIT_CODE"
exit $TEST_EXIT_CODE
else
echo "✅ All tests passed successfully."
fi