Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions .github/workflows/ansible-smoke-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# SPDX-FileCopyrightText: 2026 LibreCode Coop and contributors
# SPDX-License-Identifier: AGPL-3.0-or-later
name: Ansible repository syntax contracts

on:
pull_request:
push:
branches: [main]
workflow_dispatch:

permissions:
contents: read

concurrency:
group: ansible-syntax-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
syntax:
runs-on: ubuntu-24.04
timeout-minutes: 12
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Install isolated Ansible core
run: |
python3 -m venv .venv
.venv/bin/pip install --disable-pip-version-check 'ansible-core>=2.18,<2.22'
- name: Verify bounded Galaxy installation retry policy
run: bash tests/ci/test-install-ansible-collection.sh
- name: Install required Docker collection
run: |
export PATH="$PWD/.venv/bin:$PATH"
bash ci/install-ansible-collection.sh community.docker:5.0.5 /tmp/ansible-collections
- name: Compile every role and root playbook without contacting hosts
env:
ANSIBLE_ROLES_PATH: ${{ github.workspace }}/roles
ANSIBLE_COLLECTIONS_PATH: /tmp/ansible-collections
ANSIBLE_CONFIG: ${{ github.workspace }}/ansible.cfg
run: |
set -euo pipefail
. .venv/bin/activate
ansible-playbook -i localhost, -c local --syntax-check tests/ansible/all-roles-syntax.yml
for playbook in ./*.yml; do
ansible-playbook -i localhost, -c local --syntax-check "$playbook"
done
8 changes: 7 additions & 1 deletion .github/workflows/nginx-proxy-role-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@ on:
paths:
- 'roles/nginx_proxy/**'
- '.github/workflows/nginx-proxy-role-ci.yml'
- 'ci/install-ansible-collection.sh'
- 'tests/ci/**'
push:
branches: [main]
paths:
- 'roles/nginx_proxy/**'
- '.github/workflows/nginx-proxy-role-ci.yml'
- 'ci/install-ansible-collection.sh'
- 'tests/ci/**'

permissions:
contents: read
Expand All @@ -26,7 +30,9 @@ jobs:
python3 -m venv /tmp/ansible-qa
/tmp/ansible-qa/bin/pip install 'ansible-core>=2.17,<2.21' 'ansible-lint>=24,<27'
- name: Install pinned community Docker collection
run: /tmp/ansible-qa/bin/ansible-galaxy collection install community.docker:5.0.5 -p /tmp/ansible-collections
run: |
export PATH="/tmp/ansible-qa/bin:$PATH"
bash ci/install-ansible-collection.sh community.docker:5.0.5 /tmp/ansible-collections
- name: Validate syntax and lint
run: |
export ANSIBLE_ROLES_PATH="$GITHUB_WORKSPACE/roles"
Expand Down
23 changes: 23 additions & 0 deletions ci/install-ansible-collection.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bash
# SPDX-FileCopyrightText: 2026 LibreCode Coop and contributors
# SPDX-License-Identifier: AGPL-3.0-or-later
# Bounded retries for transient remote Galaxy errors; never silence final failure.
set -euo pipefail

if [ "$#" -ne 2 ] || [[ ! "$1" =~ ^[a-zA-Z0-9_.]+:[0-9]+\.[0-9]+\.[0-9]+$ ]] || [ -z "$2" ]; then
echo 'Usage: install-ansible-collection.sh namespace.name:version destination' >&2
exit 2
fi

collection="$1"
destination="$2"
for attempt in 1 2 3; do
if ansible-galaxy collection install "$collection" -p "$destination"; then
exit 0
fi
if [ "$attempt" -eq 3 ]; then
echo 'Ansible Galaxy installation failed after three attempts' >&2
exit 1
fi
sleep "${CI_COLLECTION_RETRY_DELAY:-3}"
done
14 changes: 7 additions & 7 deletions tests/Talk/TalkContainerIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ static function () use ($service, $markers): bool {
}
return true;
},
95
95,
'Expected ' . $service . ' readiness markers were not observed'
);
}

Expand Down Expand Up @@ -148,11 +149,9 @@ public function testCoturnReadsProtectedConfigurationAndStartsUnprivileged(): vo

public function testJanusEventsAndRealAudioVideoMediaRecoverAfterSignalingRestart(): void
{
self::waitFor('janus', ['JANUS VideoRoom plugin initialized', 'WebSocketsEventHandler connected']);
self::waitFor(
'spreedbackend',
['Connected to Janus WebRTC Server', 'Processing Janus events from']
);
// Observe the signaling-to-Janus connection. Real media below proves
// Janus VideoRoom readiness without relying on incidental startup logs.
self::waitFor('spreedbackend', ['Connected to Janus WebRTC Server']);
$this->runMedia();
$previousJanus = substr_count(self::logs('janus'), 'WebSocketsEventHandler connected');
$previousSignaling = substr_count(
Expand All @@ -169,7 +168,8 @@ public function testJanusEventsAndRealAudioVideoMediaRecoverAfterSignalingRestar
self::logs('spreedbackend'),
'Connected to Janus WebRTC Server'
) > $previousSignaling,
55
55,
'Signaling restart did not re-establish the Janus event subscription'
);
$this->runMedia();
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Talk/TalkTestSupport.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public static function clean(string $directory): void
rmdir($directory);
}

public static function waitFor(callable $condition, int $seconds): void
public static function waitFor(callable $condition, int $seconds, string $context = 'Isolated test'): void
{
$deadline = microtime(true) + $seconds;
while (microtime(true) < $deadline) {
Expand All @@ -157,6 +157,6 @@ public static function waitFor(callable $condition, int $seconds): void
}
usleep(300_000);
}
throw new RuntimeException('Isolated test condition was not met');
throw new RuntimeException($context . ' (timeout ' . $seconds . 's)');
}
}
34 changes: 34 additions & 0 deletions tests/Unit/TalkTestSupportWaitForTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

/**
* SPDX-FileCopyrightText: 2026 LibreCode Coop and contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

declare(strict_types=1);

namespace LibreCode\AnsibleDocker\Tests\Unit;

use LibreCode\AnsibleDocker\Tests\Talk\TalkTestSupport;
use PHPUnit\Framework\TestCase;
use RuntimeException;

final class TalkTestSupportWaitForTest extends TestCase
{
public function testSatisfiedConditionReturnsImmediately(): void
{
$calls = 0;
TalkTestSupport::waitFor(static function () use (&$calls): bool {
++$calls;
return true;
}, 1);
self::assertSame(1, $calls);
}

public function testTimeoutReportsServiceContextWithoutIncludingRawLogs(): void
{
$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('Janus startup timed out (timeout 0s)');
TalkTestSupport::waitFor(static fn (): bool => false, 0, 'Janus startup timed out');
}
}
17 changes: 17 additions & 0 deletions tests/ansible/all-roles-syntax.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
# SPDX-FileCopyrightText: 2026 LibreCode Coop and contributors
# SPDX-License-Identifier: AGPL-3.0-or-later
# Syntax-only: never runs tasks or contacts a managed host.
- name: Compile all reusable roles with deployment disabled
hosts: localhost
connection: local
gather_facts: false
vars:
talk_deploy_enabled: false
mail_provision_enabled: false
roles:
- docker
- nginx_proxy
- onlyoffice
- nextcloud-talk
- nextcloud-mailcow-provision
40 changes: 40 additions & 0 deletions tests/ci/test-install-ansible-collection.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env bash
# SPDX-FileCopyrightText: 2026 LibreCode Coop and contributors
# SPDX-License-Identifier: AGPL-3.0-or-later
set -euo pipefail

root="$(cd "$(dirname "$0")/../.." && pwd)"
tmp="$(mktemp -d -t ansible-galaxy-test.XXXXXXXX)"
trap 'rm -rf -- "$tmp"' EXIT
mkdir -p "$tmp/bin" "$tmp/collections"
cat > "$tmp/bin/ansible-galaxy" <<'STUB'
#!/usr/bin/env bash
# SPDX-FileCopyrightText: 2026 LibreCode Coop and contributors
# SPDX-License-Identifier: AGPL-3.0-or-later
set -euo pipefail
n=0
test ! -f "$CI_GALAXY_ATTEMPT_FILE" || n="$(cat "$CI_GALAXY_ATTEMPT_FILE")"
n="$((n+1))"
printf '%s\n' "$n" > "$CI_GALAXY_ATTEMPT_FILE"
if [ "$n" -lt "$CI_GALAXY_SUCCEED_AT" ]; then exit 42; fi
exit 0
STUB
chmod 755 "$tmp/bin/ansible-galaxy"
export CI_GALAXY_ATTEMPT_FILE="$tmp/count"
export CI_COLLECTION_RETRY_DELAY=0
export PATH="$tmp/bin:$PATH"
CI_GALAXY_SUCCEED_AT=3 bash "$root/ci/install-ansible-collection.sh" community.docker:5.0.5 "$tmp/collections"
test "$(cat "$CI_GALAXY_ATTEMPT_FILE")" = 3
rm "$CI_GALAXY_ATTEMPT_FILE"
if CI_GALAXY_SUCCEED_AT=4 bash "$root/ci/install-ansible-collection.sh" community.docker:5.0.5 "$tmp/collections" >/dev/null 2>&1; then
echo 'Exhausted retries incorrectly returned success' >&2
exit 1
fi
test "$(cat "$CI_GALAXY_ATTEMPT_FILE")" = 3
rm "$CI_GALAXY_ATTEMPT_FILE"
if CI_GALAXY_SUCCEED_AT=1 bash "$root/ci/install-ansible-collection.sh" invalid "$tmp/collections" >/dev/null 2>&1; then
echo 'Unpinned collection incorrectly accepted' >&2
exit 1
fi
test ! -e "$CI_GALAXY_ATTEMPT_FILE"
echo 'GALAXY_RETRY_CONTRACT_PASS: transient, permanent failure, version pin'
Loading