# 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:
  # Main collection changes

  - type: remove_paths
    # Remove all unsupported roles.
    # Remove all 'meta/main.yml' files within any role directory.
    paths:
      - "roles/os_ansible_user"  # non-SAP
      - "roles/os_etchosts"  # non-SAP
      - "roles/os_knownhosts"  # non-SAP
      - "roles/sap_fapolicy"  # non-SUSE
      - "roles/sap_firewall"  # obsolete, replaced with posix and LSR
      - "roles/sap_hana_backint"  # TODO: Add after rework
      - "roles/sap_hana_sr_takeover"  # TODO: Add after rework
      - "roles/sap_rfc"  # TODO: Add after rework
      - "roles/sap_rhsm"  # non-SUSE
      - "roles/*/meta/main.yml"

  - 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"
      - "roles/*/README.md"
    patterns:
      # - "sap_rhsm"
      # - "sap_fapolicy"
      - "\\[Ansible Lint"
      - 'param: "all"'

  - 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"
    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_operations/blob/main/README.md" }

  - type: replace_text
    # Replace obsolete plugin with sap_libs
    files:
      - "roles/*/README.md"
    replacements:
      - { find: "community.sap_operations.sap_facts:", replace: "community.sap_libs.sap_system_facts:" }

  - 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"
      - "roles/*/tests"
      - ".git*"
      - "*/.git*"
      - "*/*/.git*"
      - ".ansible-lint"
      - "*/*/.ansible-lint"
      - ".yamllint*"
      - "*/*/.yamllint*"
      - ".pylintrc*"
      - "bindep*"
      - ".pre-commit-config.yaml"
      - "changelogs/.plugin-cache.yaml"
      - "changelogs/fragments"
      - "plugins"
      - "docs/module*"
      - "playbooks"