# Workflow 5: Integration test and mirror
depends_on:
  - build-1
  - build-2
  - build-3

when:
  event: push
  branch: main

steps:
  integration-test:
    image: registry.celestium.life/dockerhub-cache/alpine/k8s:1.30.2
    environment:
      DOCKERHUB_USER:
        from_secret: docker_username
      DOCKERHUB_TOKEN:
        from_secret: docker_password
    commands:
      - bash infra/inttest/run_pipeline.sh --image-tag ${CI_COMMIT_SHA} --results-file inttest-results.json
    backend_options:
      kubernetes:
        resources:
          requests:
            memory: 256Mi
            cpu: 200m
          limits:
            memory: 512Mi
            cpu: 1000m

  mirror-github:
    image: registry.celestium.life/dockerhub-cache/alpine/git
    failure: ignore
    environment:
      GITHUB_SSH_KEY:
        from_secret: github_ssh_key
    commands:
      - "[ -z \"$GITHUB_SSH_KEY\" ] && echo 'No SSH key configured, skipping mirror' && exit 0"
      - mkdir -p ~/.ssh
      - echo "$GITHUB_SSH_KEY" > ~/.ssh/id_ed25519
      - chmod 600 ~/.ssh/id_ed25519
      - ssh-keyscan github.com >> ~/.ssh/known_hosts 2>/dev/null
      - git remote add github git@github.com:celesrenata/stonks-oracle.git || git remote set-url github git@github.com:celesrenata/stonks-oracle.git
      - git fetch --unshallow origin || true
      - git push github main --force
      - git push github --tags --force
    depends_on:
      - integration-test
