Playbooks Testing Infrastructure #31
This file contains hidden or 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: Test Playbooks | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| playbook_id: | |
| description: 'Specific playbook ID to test (leave empty to test all changed playbooks)' | |
| required: false | |
| type: string | |
| pull_request: | |
| paths: | |
| - 'playbooks/**' | |
| jobs: | |
| detect-changes: | |
| name: Detect Changed Playbooks | |
| runs-on: ubuntu-latest | |
| outputs: | |
| playbooks: ${{ steps.detect.outputs.playbooks }} | |
| has_playbooks: ${{ steps.detect.outputs.has_playbooks }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Detect changed playbooks | |
| id: detect | |
| run: | | |
| if [ -n "${{ github.event.inputs.playbook_id }}" ]; then | |
| # Manual trigger with specific playbook | |
| echo "playbooks=[\"${{ github.event.inputs.playbook_id }}\"]" >> $GITHUB_OUTPUT | |
| echo "has_playbooks=true" >> $GITHUB_OUTPUT | |
| else | |
| # Detect changed playbooks from PR | |
| CHANGED_FILES=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }} -- 'playbooks/core/*' 'playbooks/supplemental/*' 2>/dev/null || echo "") | |
| # Extract unique playbook IDs | |
| PLAYBOOK_IDS=$(echo "$CHANGED_FILES" | grep -E '^playbooks/(core|supplemental)/[^/]+/' | sed 's|playbooks/[^/]*/\([^/]*\)/.*|\1|' | sort -u | jq -R -s -c 'split("\n") | map(select(length > 0))') | |
| if [ "$PLAYBOOK_IDS" = "[]" ] || [ -z "$PLAYBOOK_IDS" ]; then | |
| echo "playbooks=[]" >> $GITHUB_OUTPUT | |
| echo "has_playbooks=false" >> $GITHUB_OUTPUT | |
| else | |
| echo "playbooks=$PLAYBOOK_IDS" >> $GITHUB_OUTPUT | |
| echo "has_playbooks=true" >> $GITHUB_OUTPUT | |
| fi | |
| fi | |
| - name: Display detected playbooks | |
| run: | | |
| echo "Playbooks to test: ${{ steps.detect.outputs.playbooks }}" | |
| test-playbooks-windows: | |
| name: Test Playbooks (Windows) | |
| needs: detect-changes | |
| if: needs.detect-changes.outputs.has_playbooks == 'true' | |
| runs-on: [self-hosted, Windows, halo] | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| playbook: ${{ fromJson(needs.detect-changes.outputs.playbooks) }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Setup Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.11' | |
| - name: Install test dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install pyyaml | |
| - name: Extract and run tests | |
| id: run_tests | |
| shell: powershell | |
| run: | | |
| python .github/scripts/run_playbook_tests.py --playbook "${{ matrix.playbook }}" --platform windows | |
| - name: Upload test artifacts | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: test-results-${{ matrix.playbook }}-windows | |
| path: test-results/ | |
| if-no-files-found: ignore | |
| - name: Test Summary | |
| if: always() | |
| shell: powershell | |
| run: | | |
| $summary = @" | |
| ### Test Results for ``${{ matrix.playbook }}`` (Windows) | |
| See the test artifacts for detailed logs. | |
| "@ | |
| Add-Content -Path $env:GITHUB_STEP_SUMMARY -Value $summary |