# Configuration file for changes before build.

# Types of available options for transformation:
# - remove_paths - Removes the specified files or directories.
# - remove_lines - Removes lines matching the patterns from the files matching specified glob patterns.
# - replace_text - Replaces text in files matching specified glob patterns.
# - update_yaml_key - Updates a specific key's value in the specified YAML files matching specified glob patterns.
# - append_yaml_list - Appends a new item to a list in the specified YAML files matching specified glob patterns.
# - set_yaml_value - Sets or replaces a specific key's value in the specified YAML files matching specified glob patterns.
# - remove_yaml_list_items - Removes specific items from a list in the specified YAML files matching specified glob patterns.

changes:
  - type: remove_paths
    # Remove all unsupported roles.
    # Remove all 'meta/main.yml' files within any role directory.
    paths:
      # Remove meta files within any role directory.
      - "roles/*/meta/main.yml"
      - "roles/*/meta/collection-requirements.yml"
      - "roles/*/meta/runtime.yml"
      # Removal of other files is part of galaxy.yml build_ignore list.
      - "roles/sap_hypervisor_node_preconfigure"
      - "roles/sap_vm_preconfigure"
      - "roles/sap_vm_verify"

  - type: remove_lines
    # Remove Ansible lint links
    files:
      - "README.md"
      - "roles/*/README.md"
    patterns:
      - "\\[Ansible Lint"

  - type: remove_lines
    # Remove specific lines from README.md and all role README.md files.
    # This is used to clean up any mention of unsupported roles and leftover Ansible Lint markers.
    files:
      - "README.md"
      - "docs/README.md"
      - "roles/*/README.md"
    patterns:
      - "sap_hypervisor_node_preconfigure"
      - "sap_vm_preconfigure"
      - "sap_vm_verify"

  - type: replace_text
    # Replace specific text strings in galaxy.yml and README.md files.
    # This is used to update the namespace and repository links from 'community' to 'suse'.
    files:
      - "galaxy.yml"
      - "README.md"
      - "docs/README.md"
      - "roles/*/*.md"
    replacements:
      - { find: "namespace: community", replace: "namespace: suse" }
      - { find: "github.com/sap-linuxlab/community", replace: "github.com/SUSE/community" }
      - { find: "documentation:.*", replace: "documentation: https://github.com/SUSE/community.sap_infrastructure/blob/main/README.md" }
      - { find: "name: community.sap_infrastructure.", replace: "name: suse.sap_infrastructure." }
      - { find: "community.sap_infrastructure Ansible Collection", replace: "suse.sap_infrastructure Ansible Collection" }

  - type: update_yaml_key
    # Update the 'authors' key in galaxy.yml to 'SUSE'.
    files:
      - "galaxy.yml"
    key: "authors"
    value:
      - SUSE

  - type: update_yaml_key
    # Update the 'build_ignore' key in galaxy.yml to ignore specific files and directories during the build process.
    # This is used to exclude test files, git directories, linting configuration files, and workflows.
    files:
      - "galaxy.yml"
    key: "build_ignore"
    value:
      - "tests"
      - ".git*"
      - "*/.git*"
      - "*/*/.git*"
      - ".ansible-lint"
      - ".yamllint*"
      - ".pylintrc*"
      - "bindep*"
      - ".pre-commit-config.yaml"
      - "playbooks"
