apiVersion: scaffolder.backstage.io/v1beta3
kind: Template
metadata:
  name: spring-petclinic
  title: Spring PetClinic template
  description: An example template for the scaffolder that creates a 'fork' of Spring's PetClinic
spec:
  owner: user:guest
  type: service

  parameters:
    - title: Fill in some steps
      required:
        - name
      properties:
        name:
          title: Project Name
          type: string
          description: Unique name of the fork app
          ui:autofocus: true
        upstreamurl:
          title: Repo to Fork
          type: string
          description: The URL of the repo to fork
          default: https://forgejo.edf-bootstrap.cx.fg1.ffm.osc.live/Patrick.Sy/ipcei-petclinic/src/branch/main
          ui:emptyValue: 'https://forgejo.edf-bootstrap.cx.fg1.ffm.osc.live/Patrick.Sy/ipcei-petclinic/src/branch/main'

  steps:
    - id: fetch-code # get the latest upstream code
      name: Fetch Code
      action: fetch:plain
      input:
        # url: https://github.com/spring-projects/spring-petclinic/tree/main
        url: ${{ parameters.upstreamurl }}

    - id: fetch-overrides # Apply specific overrides to add features and make modifications for compatibility
      name: Fetch Overrides
      action: fetch:template
      input:
        # url: ./skeleton/.github/workflows
        # targetPath: ./.github/workflows
        url: ./skeleton/
        targetPath: ./
        replace: true
        values:
          name: ${{ parameters.name }}
          namespace: ${{ parameters.name }}

    - id: publish
      name: Publish to Gitea
      action: publish:gitea
      input:
        repoUrl: only-forgejo.t09.de:443/?repo=${{parameters.name}}
        description: This is the repository for ${{ parameters.name }}
        sourcePath: ./
        defaultBranch: main

    - id: create-argocd-app
      name: Create ArgoCD App
      action: cnoe:create-argocd-app
      input:
        appName: ${{parameters.name}}
        appNamespace: ${{parameters.name}}
        argoInstance: in-cluster
        projectName: default
        # necessary until we generate our own cert
        repoUrl: https://only-forgejo.t09.de:443/giteaAdmin/${{parameters.name}}
        path: "k8s"

    - id: register
      name: Register in Catalog
      action: catalog:register
      input:
        repoContentsUrl: ${{ steps['publish'].output.repoContentsUrl }}
        catalogInfoPath: 'catalog-info.yaml'

  output:
    links:
      - title: Repository
        url: ${{ steps['publish'].output.remoteUrl }}
      - title: Open in Catalog
        icon: catalog
        entityRef: ${{ steps['register'].output.entityRef }}

