name: Validate CI/CD Actions
on:
  push:
    branches:
      - main
    paths:
      - .github/actions/**
      - .github/workflows/actions-*.yml
jobs:
  test-cicd-actions:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Setup environment
        uses: ./.github/actions/setup-env

      - name: Setup Ansible environment
        uses: ./.github/actions/setup-ansible-env
        with:
          project-id: ${{ secrets.BW_PROJECT_ID }}
          organization-id: ${{ secrets.BW_ORGANIZATION_ID }}
          access-token: ${{ secrets.BW_ACCESS_TOKEN }}
          ansible-user: ${{ secrets.ANSIBLE_USER }}

      - name: Setup Terraform environment
        uses: ./.github/actions/setup-terraform-env

      - name: Setup Terraform environment
        uses: ./.github/actions/setup-opentofu-env

      - name: Setup Kubernetes Environment
        uses: ./.github/actions/setup-k8s-env
        with:
          project-id: ${{ secrets.BW_PROJECT_ID }}
          organization-id: ${{ secrets.BW_ORGANIZATION_ID }}
          access-token: ${{ secrets.BW_ACCESS_TOKEN }}
          ansible-user: ${{ secrets.ANSIBLE_USER }}

      - name: Get remote host info
        uses: ./.github/actions/get-host-info
        id: get-host-info
        with:
          project-id: ${{ secrets.BW_PROJECT_ID }}
          organization-id: ${{ secrets.BW_ORGANIZATION_ID }}
          access-token: ${{ secrets.BW_ACCESS_TOKEN }}
          ansible-user: ${{ secrets.ANSIBLE_USER }}

      - name: Test ansible
        env:
          ANSIBLE_USER: ${{ secrets.ANSIBLE_USER }}
        run: |
          ansible -i inventory/hosts -u ${{ secrets.ANSIBLE_USER }} -m ping all

      - name: Test kubectl get nodes
        run: |
          kubectl get nodes --insecure-skip-tls-verify

      - name: Test terraform
        run: |
          terraform --version

      - name: Test opentofu
        run: |
            tofu --version
  
      - name: Show remote host info
        run: |
          echo "System ID: ${{ steps.get-host-info.outputs.system-id }}"
