Skip to content

Instantly share code, notes, and snippets.

@vdemeester
Created November 26, 2025 10:53
Show Gist options
  • Select an option

  • Save vdemeester/0e0c639a827a4b64d7446d947ff9ad40 to your computer and use it in GitHub Desktop.

Select an option

Save vdemeester/0e0c639a827a4b64d7446d947ff9ad40 to your computer and use it in GitHub Desktop.

Revisions

  1. vdemeester created this gist Nov 26, 2025.
    101 changes: 101 additions & 0 deletions gistfile0.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,101 @@
    #!/bin/bash

    set --noprofile --norc -e -o pipefail

    # Test script to validate the detect logic from ci.yaml

    echo "Testing detect logic for non-docs and yaml outputs"
    echo "==================================================="
    echo ""

    # Test function
    test_scenario() {
    local scenario_name="$1"
    local changed_files="$2"

    echo "Scenario: $scenario_name"
    echo "Changed files:"
    echo "$changed_files" | sed 's/^/ /'
    echo ""

    # Test non-docs detection
    if [[ -n "${changed_files}" ]]; then
    non_docs=$(echo "${changed_files}" | grep -qv '\.md$' && echo 'true')
    yaml=$(echo "${changed_files}" | grep -q '\.ya\?ml$' && echo 'true')
    else
    non_docs=""
    yaml=""
    fi

    echo " non-docs: ${non_docs:-false}"
    echo " yaml: ${yaml:-false}"
    echo ""
    echo "---"
    echo ""
    }

    # Test 1: Only markdown files
    test_scenario "Only markdown files" "README.md
    docs/guide.md
    CONTRIBUTING.md"

    # Test 2: Only Go files (non-docs)
    test_scenario "Only Go files" "main.go
    pkg/handler.go
    cmd/app/main.go"

    # Test 3: Only YAML files
    test_scenario "Only YAML files" "config.yaml
    deployment.yml
    values.yaml"

    # Test 4: Mix of markdown and Go files
    test_scenario "Mix of markdown and Go files" "README.md
    main.go
    docs/api.md
    pkg/server.go"

    # Test 5: Mix of YAML and Go files
    test_scenario "Mix of YAML and Go files" "main.go
    config.yaml
    pkg/handler.go
    deployment.yml"

    # Test 6: Mix of markdown, YAML, and Go files
    test_scenario "Mix of all types" "README.md
    main.go
    config.yaml
    docs/guide.md
    pkg/handler.go
    deployment.yml"

    # Test 7: GitHub workflow YAML files
    test_scenario "GitHub workflow YAML files" ".github/workflows/ci.yaml
    .github/workflows/release.yml"

    # Test 8: Mix of workflow YAML and other YAML
    test_scenario "Mix of workflow and config YAML" ".github/workflows/ci.yaml
    config/deployment.yaml
    manifests/service.yml"

    # Test 9: Only workflow YAML (should yaml=true currently)
    test_scenario "Only workflow YAML" ".github/workflows/ci.yaml
    .github/workflows/test.yml"

    # Test 10: Empty changes
    test_scenario "Empty changes" ""

    # Test 11: Single markdown file
    test_scenario "Single markdown file" "README.md"

    # Test 12: Single non-markdown file
    test_scenario "Single Go file" "main.go"

    # Test 13: YAML with different extensions
    test_scenario "YAML variations" "config.yaml
    settings.yml
    data.YAML
    options.YML"

    echo "==================================================="
    echo "Test completed!"