---
# Main tasks for Forgejo deployment

- name: Include variables from vars/main.yml
  ansible.builtin.include_vars:
    file: "{{ role_path }}/vars/main.yml"

- name: Set facts for kubeconfig and context
  ansible.builtin.set_fact:
    k8s_auth_params:
      kubeconfig: "{{ k8s_auth_params.kubeconfig | default(kubeconfig) | default(omit) }}"
      context: "{{ k8s_context | default(omit) }}"
      validate_certs: "{{ k8s_validate_certs | default(k8s_auth_params.validate_certs) | default(true) }}"

# Always clean up resources when migrating from gitea to forgejo
- name: Check if we need to clean up resources
  ansible.builtin.set_fact:
    cleanup_resources: true

- name: Clean up existing Forgejo resources
  ansible.builtin.include_tasks: cleanup_resources.yml

# Create namespace for Forgejo
- name: Setup Forgejo namespace
  ansible.builtin.include_tasks: namespace_setup.yml

# Setup persistent storage
- name: Setup storage for Forgejo
  ansible.builtin.include_tasks: storage_setup.yml

# Initialize storage with proper permissions
- name: Initialize storage directories
  ansible.builtin.include_tasks: init_storage.yml

# Install Forgejo using Helm
- name: Install Forgejo using Helm
  ansible.builtin.include_tasks: helm_install.yml

# Verify Forgejo deployment
- name: Verify Forgejo deployment
  ansible.builtin.include_tasks: verify_deployment.yml
