test commit #2
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
name: Tests | |
on: # yamllint disable-line rule:truthy | |
pull_request: | |
workflow_call: | |
concurrency: | |
group: '${{ github.workflow }} @ ${{ github.ref }}' | |
cancel-in-progress: true | |
jobs: | |
check_versions: | |
name: Tests - Version checking | |
runs-on: ubuntu-latest | |
outputs: | |
version: ${{ steps.sogo.outputs.VERSION }} | |
steps: | |
- name: Get latest version of SOGo | |
id: sogo | |
run: | | |
echo "VERSION=$(curl -s https://api.github.com/repos/Alinto/sogo/releases/latest | jq -r '.tag_name' | sed 's/SOGo-//')" >> "$GITHUB_OUTPUT" | |
test_build: | |
name: Tests - Build image for testing | |
needs: check_versions | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Build and export to Docker | |
uses: docker/build-push-action@v5 | |
with: | |
file: ./Dockerfile | |
load: true | |
platforms: linux/amd64 | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
tags: test-sogo:${{ github.run_id }} | |
outputs: type=docker,dest=/tmp/test-sogo-${{ github.run_id }}.tar | |
build-args: | | |
SOGO_VERSION=${{ needs.check_versions.outputs.version }} | |
- name: Upload artifact | |
uses: actions/upload-artifact@v2 | |
with: | |
name: test-sogo-${{ github.run_id }} | |
path: /tmp/test-sogo-${{ github.run_id }}.tar | |
end_to_end_plist: | |
name: Tests - E2E Testing | |
needs: test_build | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Download artifact | |
uses: actions/download-artifact@v2 | |
with: | |
name: test-sogo-${{ github.run_id }} | |
path: /tmp | |
- name: Load Docker image | |
env: | |
RUN_ID: ${{ github.run_id }} | |
run: | | |
docker load --input /tmp/test-sogo-$RUN_ID.tar | |
- name: Setup test configurations | |
run: | | |
mkdir -p /test-sogo | |
plist_config=$(cat sample-config.conf) | |
echo "$plist_config" > /test-sogo/sogo.conf | |
- name: Setup test PostgreSQL | |
run: | | |
docker network create test-sogo | |
docker run -d \ | |
--name test-postgres \ | |
--network test-sogo \ | |
-e POSTGRES_PASSWORD=sogo \ | |
-e POSTGRES_USER=sogo \ | |
-e POSTGRES_DB=sogo \ | |
postgres | |
- name: Run test SOGo container | |
run: | | |
docker run -d \ | |
--name sogo \ | |
--network test-sogo \ | |
-p 80:80/tcp \ | |
-v /test-sogo/sogo.conf:/etc/sogo/sogo.conf | |
--stop-timeout 30 \ | |
test-sogo:${{ github.run_id }} | |
- name: Wait for test SOGo container to start | |
run: | | |
TIMEOUT_SECONDS=180 | |
START_TIME=$(date +%s) | |
while ! docker logs sogo 2>&1 | grep -q 'INFO success: sogo entered RUNNING state, process has stayed up for > than 1 seconds'; do | |
CURRENT_TIME=$(date +%s) | |
ELAPSED_TIME=$((CURRENT_TIME - START_TIME)) | |
if [ $ELAPSED_TIME -gt $TIMEOUT_SECONDS ]; then | |
echo "Timeout reached. Server failed to start within $TIMEOUT_SECONDS seconds." | |
printf "\e[0;32m%s\e[0m\n" "*****Test container logs*****" | |
docker logs sogo | |
exit 1 | |
fi | |
echo "Waiting for test SOGo container to start..." | |
sleep 5 | |
done | |
- name: Test HTTP status code | |
run: | | |
TIMEOUT=60 | |
elapsed_time=0 | |
SUCCESS_CODE=302 | |
while true; do | |
http_status=$(curl -s -o /dev/null -w "%{http_code}" "http://localhost:80/SOGo") | |
if [ $http_status -eq $SUCCESS_CODE ]; then | |
echo "Health check successful. HTTP Status Code: $http_status" | |
exit 0 | |
fi | |
elapsed_time=$((elapsed_time + 1)) | |
if [ $elapsed_time -ge $TIMEOUT ]; then | |
echo "Timeout reached. HTTP Health check failed." | |
exit 1 | |
fi | |
# Wait for a second before next health check | |
sleep 1 | |
done | |
end_to_end_yaml: | |
name: Tests - E2E Testing (YAML Config) | |
needs: test_build | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Download artifact | |
uses: actions/download-artifact@v2 | |
with: | |
name: test-sogo-${{ github.run_id }} | |
path: /tmp | |
- name: Load Docker image | |
env: | |
RUN_ID: ${{ github.run_id }} | |
run: | | |
docker load --input /tmp/test-sogo-$RUN_ID.tar | |
- name: Setup test configurations | |
run: | | |
mkdir -p /test-sogo | |
yaml_config=$(cat sample-config.yaml) | |
echo "$yaml_config" > /test-sogo/sogo.yaml | |
- name: Setup test PostgreSQL | |
run: | | |
docker network create test-sogo | |
docker run -d \ | |
--name test-postgres \ | |
--network test-sogo \ | |
-e POSTGRES_PASSWORD=sogo \ | |
-e POSTGRES_USER=sogo \ | |
-e POSTGRES_DB=sogo \ | |
postgres | |
- name: Run test SOGo container | |
run: | | |
docker run -d \ | |
--name sogo \ | |
--network test-sogo \ | |
-p 80:80/tcp \ | |
-v /test-sogo/sogo.yaml:/etc/sogo/sogo.conf.d/00-test.yaml | |
--stop-timeout 30 \ | |
test-sogo:${{ github.run_id }} | |
- name: Wait for test SOGo container to start | |
run: | | |
TIMEOUT_SECONDS=180 | |
START_TIME=$(date +%s) | |
while ! docker logs sogo 2>&1 | grep -q 'INFO success: sogo entered RUNNING state, process has stayed up for > than 1 seconds'; do | |
CURRENT_TIME=$(date +%s) | |
ELAPSED_TIME=$((CURRENT_TIME - START_TIME)) | |
if [ $ELAPSED_TIME -gt $TIMEOUT_SECONDS ]; then | |
echo "Timeout reached. Server failed to start within $TIMEOUT_SECONDS seconds." | |
printf "\e[0;32m%s\e[0m\n" "*****Test container logs*****" | |
docker logs sogo | |
exit 1 | |
fi | |
echo "Waiting for test SOGo container to start..." | |
sleep 5 | |
done | |
- name: Test HTTP status code | |
run: | | |
TIMEOUT=60 | |
elapsed_time=0 | |
SUCCESS_CODE=302 | |
while true; do | |
http_status=$(curl -s -o /dev/null -w "%{http_code}" "http://localhost:80/SOGo") | |
if [ $http_status -eq $SUCCESS_CODE ]; then | |
echo "Health check successful. HTTP Status Code: $http_status" | |
exit 0 | |
fi | |
elapsed_time=$((elapsed_time + 1)) | |
if [ $elapsed_time -ge $TIMEOUT ]; then | |
echo "Timeout reached. HTTP Health check failed." | |
exit 1 | |
fi | |
# Wait for a second before next health check | |
sleep 1 | |
done |