diff --git a/.github/workflows/ansible-smoke-ci.yml b/.github/workflows/ansible-smoke-ci.yml new file mode 100644 index 0000000..9e6d848 --- /dev/null +++ b/.github/workflows/ansible-smoke-ci.yml @@ -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 diff --git a/.github/workflows/nginx-proxy-role-ci.yml b/.github/workflows/nginx-proxy-role-ci.yml index cf509cf..42543dc 100644 --- a/.github/workflows/nginx-proxy-role-ci.yml +++ b/.github/workflows/nginx-proxy-role-ci.yml @@ -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 @@ -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" diff --git a/ci/install-ansible-collection.sh b/ci/install-ansible-collection.sh new file mode 100755 index 0000000..c7241fe --- /dev/null +++ b/ci/install-ansible-collection.sh @@ -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 diff --git a/tests/Talk/TalkContainerIntegrationTest.php b/tests/Talk/TalkContainerIntegrationTest.php index 234f3ac..632de9c 100644 --- a/tests/Talk/TalkContainerIntegrationTest.php +++ b/tests/Talk/TalkContainerIntegrationTest.php @@ -89,7 +89,8 @@ static function () use ($service, $markers): bool { } return true; }, - 95 + 95, + 'Expected ' . $service . ' readiness markers were not observed' ); } @@ -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( @@ -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(); } diff --git a/tests/Talk/TalkTestSupport.php b/tests/Talk/TalkTestSupport.php index 0463cd4..52f8ed8 100644 --- a/tests/Talk/TalkTestSupport.php +++ b/tests/Talk/TalkTestSupport.php @@ -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) { @@ -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)'); } } diff --git a/tests/Unit/TalkTestSupportWaitForTest.php b/tests/Unit/TalkTestSupportWaitForTest.php new file mode 100644 index 0000000..04eecfb --- /dev/null +++ b/tests/Unit/TalkTestSupportWaitForTest.php @@ -0,0 +1,34 @@ +expectException(RuntimeException::class); + $this->expectExceptionMessage('Janus startup timed out (timeout 0s)'); + TalkTestSupport::waitFor(static fn (): bool => false, 0, 'Janus startup timed out'); + } +} diff --git a/tests/ansible/all-roles-syntax.yml b/tests/ansible/all-roles-syntax.yml new file mode 100644 index 0000000..a014b96 --- /dev/null +++ b/tests/ansible/all-roles-syntax.yml @@ -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 diff --git a/tests/ci/test-install-ansible-collection.sh b/tests/ci/test-install-ansible-collection.sh new file mode 100755 index 0000000..4b7dbc4 --- /dev/null +++ b/tests/ci/test-install-ansible-collection.sh @@ -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'