1
0
forked from baron/baron-sso
Files
baron-sso/.gitea/workflows/code_check.yml
2026-02-20 08:51:53 +09:00

439 lines
16 KiB
YAML

name: Code Check
on:
push:
branches:
- dev
pull_request:
branches:
- dev
workflow_dispatch:
inputs:
run_lint:
description: "Run linters for Go and Flutter"
required: true
type: boolean
default: true
run_backend_tests:
description: "Run backend Go tests"
required: true
type: boolean
default: true
run_userfront_tests:
description: "Run userfront Flutter tests"
required: true
type: boolean
default: true
run_adminfront_tests:
description: "Run adminfront Playwright tests"
required: true
type: boolean
default: true
run_devfront_tests:
description: "Run devfront Playwright tests"
required: true
type: boolean
default: true
jobs:
lint:
if: ${{ github.event_name != 'workflow_dispatch' || inputs.run_lint == true }}
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
- name: i18n resource check
run: |
mkdir -p reports
node tools/i18n-scanner/index.js
node tools/i18n-scanner/report.js
cat reports/i18n-report.txt
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: "1.25"
cache-dependency-path: backend/go.sum
- name: Setup Flutter
uses: subosito/flutter-action@v2
with:
channel: "stable"
cache: true
- name: Lint Go backend
uses: golangci/golangci-lint-action@v6
with:
version: v1.59
working-directory: backend
args: --enable-only=gofmt,gofumpt
- name: Analyze Flutter userfront
run: |
cd userfront
flutter analyze --no-fatal-warnings --no-fatal-infos
backend-tests:
needs: lint
if: ${{ always() && (github.event_name != 'workflow_dispatch' || inputs.run_backend_tests == true) }}
runs-on: ubuntu-latest
services:
redis:
image: redis:7-alpine
options: >
--health-cmd "redis-cli ping" --health-interval 10s --health-timeout 5s --health-retries 5
clickhouse:
image: clickhouse/clickhouse-server:24.6
options: >
--health-cmd "wget -qO- 'http://localhost:8123/ping'" --health-interval 10s --health-timeout 5s --health-retries 5
env:
REDIS_ADDR: redis:6379
CLICKHOUSE_HOST: clickhouse
CLICKHOUSE_PORT_NATIVE: 9000
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: "1.25"
cache-dependency-path: backend/go.sum
- name: Run backend tests
run: |
mkdir -p reports
set +e
cd backend
go test -v ./... 2>&1 | tee ../reports/backend-test.log
test_exit_code=${PIPESTATUS[0]}
cd ..
if [ "$test_exit_code" -ne 0 ]; then
{
echo "# Backend Test Failure Report"
echo
echo "- Workflow: \`${GITHUB_WORKFLOW:-Code Check}\`"
echo "- Job: \`backend-tests\`"
echo "- Exit Code: \`$test_exit_code\`"
echo
echo "## Command"
echo "\`go test -v ./...\`"
echo
echo "## Log Tail (last 200 lines)"
echo '```text'
tail -n 200 reports/backend-test.log
echo '```'
} > reports/backend-test-failure-report.md
fi
exit "$test_exit_code"
- name: Publish backend failure summary
if: ${{ failure() }}
run: |
if [ -f reports/backend-test-failure-report.md ]; then
cat reports/backend-test-failure-report.md >> "$GITHUB_STEP_SUMMARY"
fi
- name: Upload backend failure report artifact
if: ${{ failure() }}
uses: actions/upload-artifact@v4
with:
name: backend-test-failure-report
path: |
reports/backend-test-failure-report.md
reports/backend-test.log
if-no-files-found: ignore
userfront-tests:
needs: lint
if: ${{ always() && (github.event_name != 'workflow_dispatch' || inputs.run_userfront_tests == true) }}
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Flutter
uses: subosito/flutter-action@v2
with:
channel: "stable"
cache: true
- name: Ensure browser for Flutter web tests
run: |
has_runnable_browser=false
for candidate in google-chrome google-chrome-stable chromium chromium-browser; do
if command -v "$candidate" >/dev/null 2>&1 && "$candidate" --version >/dev/null 2>&1; then
has_runnable_browser=true
break
fi
done
if [ "$has_runnable_browser" = true ]; then
echo "Runnable Chrome/Chromium already installed."
exit 0
fi
if command -v sudo >/dev/null 2>&1; then
sudo apt-get update
sudo apt-get install -y chromium || sudo apt-get install -y chromium-browser
else
apt-get update
apt-get install -y chromium || apt-get install -y chromium-browser
fi
for candidate in google-chrome google-chrome-stable chromium chromium-browser; do
if command -v "$candidate" >/dev/null 2>&1 && "$candidate" --version >/dev/null 2>&1; then
echo "Installed browser: $candidate"
exit 0
fi
done
echo "No runnable Chrome/Chromium found after install."
exit 1
- name: Run userfront tests
run: |
cd userfront
if [ -d test ]; then
CHROME_BIN=""
for candidate in google-chrome google-chrome-stable chromium chromium-browser; do
if command -v "$candidate" >/dev/null 2>&1 && "$candidate" --version >/dev/null 2>&1; then
CHROME_BIN="$(command -v "$candidate")"
break
fi
done
if [ -z "$CHROME_BIN" ]; then
echo "Chrome/Chromium not found for web tests."
exit 1
fi
echo "Using browser: $CHROME_BIN"
export CHROME_EXECUTABLE="$CHROME_BIN"
mkdir -p ../reports
set +e
flutter test 2>&1 | tee ../reports/userfront-test-vm.log
vm_test_exit_code=${PIPESTATUS[0]}
web_test_exit_code=0
if [ "$vm_test_exit_code" -eq 0 ]; then
flutter test --platform chrome test/locale_storage_platform_test.dart 2>&1 | tee ../reports/userfront-test-web.log
web_test_exit_code=${PIPESTATUS[0]}
fi
set -e
if [ "$vm_test_exit_code" -ne 0 ] || [ "$web_test_exit_code" -ne 0 ]; then
{
echo "# Userfront Test Failure Report"
echo
echo "- Workflow: \`${GITHUB_WORKFLOW:-Code Check}\`"
echo "- Job: \`userfront-tests\`"
echo "- Browser: \`$CHROME_BIN\`"
echo "- VM Test Exit Code: \`$vm_test_exit_code\`"
echo "- Web Test Exit Code: \`$web_test_exit_code\`"
echo
echo "## Commands"
echo "1. \`flutter test\`"
echo "2. \`flutter test --platform chrome test/locale_storage_platform_test.dart\`"
echo
if [ -f ../reports/userfront-test-vm.log ]; then
echo "## VM Test Log Tail (last 200 lines)"
echo '```text'
tail -n 200 ../reports/userfront-test-vm.log
echo '```'
echo
fi
if [ -f ../reports/userfront-test-web.log ]; then
echo "## Web Test Log Tail (last 200 lines)"
echo '```text'
tail -n 200 ../reports/userfront-test-web.log
echo '```'
fi
} > ../reports/userfront-test-failure-report.md
exit 1
fi
else
echo "No userfront tests: skipping (test/ directory not found)."
fi
- name: Publish userfront failure summary
if: ${{ failure() }}
run: |
if [ -f reports/userfront-test-failure-report.md ]; then
cat reports/userfront-test-failure-report.md >> "$GITHUB_STEP_SUMMARY"
fi
- name: Upload userfront failure report artifact
if: ${{ failure() }}
uses: actions/upload-artifact@v4
with:
name: userfront-test-failure-report
path: |
reports/userfront-test-failure-report.md
reports/userfront-test-vm.log
reports/userfront-test-web.log
if-no-files-found: ignore
adminfront-tests:
needs: lint
if: ${{ always() && (github.event_name != 'workflow_dispatch' || inputs.run_adminfront_tests == true) }}
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
cache: "npm"
cache-dependency-path: adminfront/package-lock.json
- name: Install adminfront dependencies
run: |
cd adminfront
npm ci
- name: Provision browsers for adminfront tests
run: |
cd adminfront
npx playwright install --with-deps
- name: Run adminfront tests
run: |
mkdir -p reports
set +e
cd adminfront
npm test 2>&1 | tee ../reports/adminfront-test.log
test_exit_code=${PIPESTATUS[0]}
cd ..
set -e
if [ "$test_exit_code" -ne 0 ]; then
{
echo "# Adminfront Test Failure Report"
echo
echo "- Workflow: \`${GITHUB_WORKFLOW:-Code Check}\`"
echo "- Job: \`adminfront-tests\`"
echo "- Exit Code: \`$test_exit_code\`"
echo
echo "## Commands"
echo "1. \`cd adminfront\`"
echo "2. \`npm ci\`"
echo "3. \`npx playwright install --with-deps\`"
echo "4. \`npm test\`"
echo
echo "## Log Tail (last 200 lines)"
echo '```text'
tail -n 200 reports/adminfront-test.log
echo '```'
} > reports/adminfront-test-failure-report.md
fi
exit "$test_exit_code"
- name: Publish adminfront failure summary
if: ${{ failure() }}
run: |
if [ -f reports/adminfront-test-failure-report.md ]; then
cat reports/adminfront-test-failure-report.md >> "$GITHUB_STEP_SUMMARY"
fi
- name: Upload adminfront failure report artifact
if: ${{ failure() }}
uses: actions/upload-artifact@v4
with:
name: adminfront-test-failure-report
path: |
reports/adminfront-test-failure-report.md
reports/adminfront-test.log
adminfront/playwright-report
adminfront/test-results
if-no-files-found: ignore
devfront-tests:
needs: lint
if: ${{ always() && (github.event_name != 'workflow_dispatch' || inputs.run_devfront_tests == true) }}
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
cache: "npm"
cache-dependency-path: devfront/package-lock.json
- name: Install devfront dependencies
run: |
cd devfront
npm ci
- name: Provision browsers for devfront tests
run: |
cd devfront
npx playwright install --with-deps
- name: Run devfront tests
run: |
mkdir -p reports
set +e
cd devfront
npm test 2>&1 | tee ../reports/devfront-test.log
test_exit_code=${PIPESTATUS[0]}
cd ..
set -e
if [ "$test_exit_code" -ne 0 ]; then
{
echo "# Devfront Test Failure Report"
echo
echo "- Workflow: \`${GITHUB_WORKFLOW:-Code Check}\`"
echo "- Job: \`devfront-tests\`"
echo "- Exit Code: \`$test_exit_code\`"
echo
echo "## Commands"
echo "1. \`cd devfront\`"
echo "2. \`npm ci\`"
echo "3. \`npx playwright install --with-deps\`"
echo "4. \`npm test\`"
echo
echo "## Log Tail (last 200 lines)"
echo '```text'
tail -n 200 reports/devfront-test.log
echo '```'
} > reports/devfront-test-failure-report.md
fi
exit "$test_exit_code"
- name: Publish devfront failure summary
if: ${{ failure() }}
run: |
if [ -f reports/devfront-test-failure-report.md ]; then
cat reports/devfront-test-failure-report.md >> "$GITHUB_STEP_SUMMARY"
fi
- name: Upload devfront failure report artifact
if: ${{ failure() }}
uses: actions/upload-artifact@v4
with:
name: devfront-test-failure-report
path: |
reports/devfront-test-failure-report.md
reports/devfront-test.log
devfront/playwright-report
devfront/test-results
if-no-files-found: ignore