Files
action-stalwart-install/.github/workflows/test.yml
Sebastian Krupinski 171107d359
Some checks failed
Test Stalwart Installation Action / Basic Installation (No Config) (pull_request) Failing after 35s
Test Stalwart Installation Action / Installation with Admin Password (pull_request) Failing after 2m16s
Test Stalwart Installation Action / Error Handling Tests (pull_request) Successful in 2m17s
Test Stalwart Installation Action / Full Configuration (Domains + Users) (pull_request) Failing after 2m21s
Test Stalwart Installation Action / Test on Ubuntu ubuntu-20.04 (pull_request) Has been cancelled
Test Stalwart Installation Action / Test on Ubuntu ubuntu-22.04 (pull_request) Has been cancelled
Test Stalwart Installation Action / Test on Ubuntu ubuntu-24.04 (pull_request) Has been cancelled
Test Stalwart Installation Action / Test Summary (pull_request) Has been cancelled
feat: initial version
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
2026-02-14 23:31:21 -05:00

312 lines
9.6 KiB
YAML

name: Test Stalwart Installation Action
on:
push:
branches: [main, develop]
pull_request:
branches: [main]
workflow_dispatch:
jobs:
# Test basic installation without configuration
test-basic-install:
name: Basic Installation (No Config)
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y jq curl
- name: Run basic installation
uses: ./
# No inputs - should install with defaults
- name: Verify Stalwart service is running
run: |
sleep 10 # Give service time to start
sudo systemctl status stalwart --no-pager
if ! sudo systemctl is-active --quiet stalwart; then
echo "::error::Stalwart service is not running"
exit 1
fi
- name: Check Stalwart binary
run: |
if [ ! -f /opt/stalwart/bin/stalwart ]; then
echo "::error::Stalwart binary not found"
exit 1
fi
/opt/stalwart/bin/stalwart --version
- name: Test web admin accessibility
run: |
# Wait for API to be ready
for i in {1..30}; do
if curl -sf http://localhost:8080/login >/dev/null 2>&1; then
echo "✓ Web admin is accessible"
exit 0
fi
sleep 2
done
echo "::error::Web admin not accessible after 60 seconds"
exit 1
# Test installation with admin password
test-with-password:
name: Installation with Admin Password
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y jq curl
- name: Install with admin password
uses: ./
with:
admin_password: 'TestPassword123!@#'
- name: Verify service is running
run: |
sleep 10
sudo systemctl status stalwart --no-pager
sudo systemctl is-active --quiet stalwart
- name: Test authentication with new password
run: |
# Wait for API
sleep 5
# Try to authenticate with new password
RESPONSE=$(curl -sf -X POST http://localhost:8080/api/authenticate \
-H "Content-Type: application/json" \
-d '{"login":"admin","password":"TestPassword123!@#"}')
TOKEN=$(echo "$RESPONSE" | jq -r '.token // empty')
if [ -z "$TOKEN" ]; then
echo "::error::Failed to authenticate with new password"
exit 1
fi
echo "✓ Successfully authenticated with new password"
# Test full configuration with domains and users
test-full-config:
name: Full Configuration (Domains + Users)
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y jq curl
- name: Install with full configuration
uses: ./
with:
admin_password: 'AdminPass123!@#'
domains: |
[
{
"name": "test1.local",
"description": "Primary test domain"
},
{
"name": "test2.local",
"description": "Secondary test domain"
}
]
users: |
[
{
"email": "user1@test1.local",
"password": "UserPass123!",
"name": "Test User One",
"quota": 1073741824
},
{
"email": "user2@test1.local",
"password": "UserPass456!",
"name": "Test User Two",
"quota": 2147483648
},
{
"email": "admin@test2.local",
"password": "AdminUser789!",
"name": "Admin User",
"quota": 5368709120
}
]
- name: Verify service is running
run: |
sleep 10
sudo systemctl status stalwart --no-pager
sudo systemctl is-active --quiet stalwart
- name: Verify admin password was changed
run: |
sleep 5
RESPONSE=$(curl -sf -X POST http://localhost:8080/api/authenticate \
-H "Content-Type: application/json" \
-d '{"login":"admin","password":"AdminPass123!@#"}')
TOKEN=$(echo "$RESPONSE" | jq -r '.token // empty')
if [ -z "$TOKEN" ]; then
echo "::error::Failed to authenticate with admin password"
exit 1
fi
echo "✓ Admin authentication successful"
echo "TOKEN=$TOKEN" >> $GITHUB_ENV
- name: Verify domains were created
run: |
# List domains via API
DOMAINS=$(curl -sf -X GET http://localhost:8080/api/domain \
-H "Authorization: Bearer $TOKEN")
echo "Domains response: $DOMAINS"
# Check if our test domains exist
if echo "$DOMAINS" | jq -e '.[] | select(.name == "test1.local")' >/dev/null; then
echo "✓ Domain test1.local found"
else
echo "::warning::Domain test1.local not found (API might use different structure)"
fi
- name: Verify users were created
run: |
# List accounts via API
ACCOUNTS=$(curl -sf -X GET http://localhost:8080/api/account \
-H "Authorization: Bearer $TOKEN")
echo "Accounts response: $ACCOUNTS"
# Check if users exist
if echo "$ACCOUNTS" | jq -e '.[] | select(.name == "user1@test1.local")' >/dev/null; then
echo "✓ User user1@test1.local found"
else
echo "::warning::User user1@test1.local not found (API might use different structure)"
fi
- name: Show logs on failure
if: failure()
run: |
echo "=== Stalwart Service Status ==="
sudo systemctl status stalwart --no-pager || true
echo -e "\n=== Stalwart Logs ==="
sudo journalctl -u stalwart -n 100 --no-pager || true
echo -e "\n=== Configuration File ==="
sudo cat /opt/stalwart/etc/config.toml || true
# Test error handling
test-error-handling:
name: Error Handling Tests
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Test invalid JSON (domains)
id: test_invalid_domains
continue-on-error: true
uses: ./
with:
admin_password: 'TestPass123'
domains: 'invalid json string'
- name: Verify invalid JSON was caught
run: |
if [ "${{ steps.test_invalid_domains.outcome }}" = "success" ]; then
echo "::error::Action should have failed with invalid JSON"
exit 1
fi
echo "✓ Invalid domains JSON was properly rejected"
- name: Clean up after failed test
if: always()
run: |
sudo systemctl stop stalwart || true
sudo rm -rf /opt/stalwart || true
# Test on different Ubuntu versions
test-ubuntu-versions:
name: Test on Ubuntu ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-20.04, ubuntu-22.04, ubuntu-24.04]
fail-fast: false
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y jq curl
- name: Install Stalwart
uses: ./
with:
admin_password: 'TestPassword123'
- name: Verify installation
run: |
sleep 10
sudo systemctl is-active --quiet stalwart
echo "✓ Stalwart running on ${{ matrix.os }}"
- name: Test API accessibility
run: |
sleep 5
curl -sf http://localhost:8080/login >/dev/null
echo "✓ API accessible on ${{ matrix.os }}"
# Summary job
test-summary:
name: Test Summary
runs-on: ubuntu-latest
needs: [test-basic-install, test-with-password, test-full-config, test-ubuntu-versions]
if: always()
steps:
- name: Check test results
run: |
echo "## Test Results Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "- Basic Install: ${{ needs.test-basic-install.result }}" >> $GITHUB_STEP_SUMMARY
echo "- With Password: ${{ needs.test-with-password.result }}" >> $GITHUB_STEP_SUMMARY
echo "- Full Config: ${{ needs.test-full-config.result }}" >> $GITHUB_STEP_SUMMARY
echo "- Ubuntu Versions: ${{ needs.test-ubuntu-versions.result }}" >> $GITHUB_STEP_SUMMARY
# Fail if any required test failed
if [ "${{ needs.test-basic-install.result }}" != "success" ] || \
[ "${{ needs.test-with-password.result }}" != "success" ] || \
[ "${{ needs.test-full-config.result }}" != "success" ]; then
echo "::error::One or more tests failed"
exit 1
fi
echo "✓ All tests passed!"