---
- job:
    name: codegenerator-rust-base
    parent: unittests
    description: |
      Base job for generation of the Rust code
    attempts: 1
    timeout: 1800
    pre-run:
      - playbooks/codegenerator/pre.yaml
    post-run:
      - playbooks/rust/post.yaml
    vars:
      codegenerator_service_metadata_target_map:
        - service: "block-storage"
          metadata: "metadata/block-storage_metadata.yaml"
          targets: ["rust-sdk", "rust-cli", "rust-tui", "rust-types"]
        - service: "compute"
          metadata: "metadata/compute_metadata.yaml"
          targets: ["rust-sdk", "rust-cli", "rust-tui", "rust-types"]
        - service: "container-infrastructure-management"
          metadata: "metadata/container-infrastructure-management_metadata.yaml"
          targets: ["rust-sdk", "rust-cli", "rust-types"]
        - service: "dns"
          metadata: "metadata/dns_metadata.yaml"
          targets: ["rust-sdk", "rust-cli", "rust-tui", "rust-types"]
        - service: "identity"
          metadata: "metadata/identity_metadata.yaml"
          targets: ["rust-sdk", "rust-cli", "rust-tui", "rust-types"]
        - service: "image"
          metadata: "metadata/image_metadata.yaml"
          targets: ["rust-sdk", "rust-cli", "rust-tui", "rust-types"]
        - service: "load-balancer"
          metadata: "metadata/load-balancer_metadata.yaml"
          targets: ["rust-sdk", "rust-cli", "rust-tui", "rust-types"]
        - service: "network"
          metadata: "metadata/network_metadata.yaml"
          targets: ["rust-sdk", "rust-cli", "rust-tui", "rust-types"]
        - service: "object-store"
          metadata: "metadata/object-store_metadata.yaml"
          targets: ["rust-sdk", "rust-types"]
        - service: "placement"
          metadata: "metadata/placement_metadata.yaml"
          targets: ["rust-sdk", "rust-cli", "rust-types"]
        # - service: "shared-file-system"
        #   metadata: "metadata/shared-file-system_metadata.yaml"
        #   targets: ["rust-sdk"]

- job:
    name: codegenerator-rust-all
    parent: codegenerator-rust-base
    # It takes a while to optimize and compile the project
    timeout: 5400
    description: |
      Generate Rust SDK/CLI
    dependencies:
      - name: codegenerator-openapi-block-storage-tips-with-api-ref
        soft: true
      - name: codegenerator-openapi-compute-tips-with-api-ref
        soft: true
      - name: codegenerator-openapi-container-infrastructure-management-tips-with-api-ref
        soft: true
      - name: codegenerator-openapi-dns-tips-with-api-ref
        soft: true
      - name: codegenerator-openapi-identity-tips-with-api-ref
        soft: true
      - name: codegenerator-openapi-image-tips-with-api-ref
        soft: true
      - name: codegenerator-openapi-load-balancing-tips-with-api-ref
        soft: true
      - name: codegenerator-openapi-network-tips-with-api-ref
        soft: true
      - name: codegenerator-openapi-object-store-static
        soft: true
      - name: codegenerator-openapi-placement-tips-with-api-ref
        soft: true
      - name: codegenerator-openapi-shared-file-system-tips-with-api-ref
        soft: true
    pre-run: playbooks/openapi/fetch.yaml
    run: playbooks/rust/all.yaml
    vars:
      codegenerator_base_dir: "{{ ansible_user_dir }}/{{ zuul.project.src_dir }}"
      openapi_dest: "{{ codegenerator_base_dir }}/wrk/openapi_specs"
      patch_path: "{{ ansible_user_dir }}/{{ zuul.change }}.patch"
      rust_sdk_git_repo: "https://github.com/gtema/openstack"
      rust_project_dir: "{{ ansible_user_dir }}/openstack"

- job:
    name: codegenerator-propose-rust-openstack-change
    description: |
      Propose changes to the Rust OpenStack project with the code newly
      generated in this change.

      This job is applying the git patch created by the
      `codegenerator-rust-all` job. It accesses target repository using SSH
      and a public key of the project (`curl
      https://zuul.opendev.org/api/tenant/openstack/project-ssh-key/openstack/codegenerator.pub`)
      being added as a deploy key in GitHub repository with read/write access.
      Pull Request itself is not opened, since it requires additionally API
      token what would require hardcoding secret (and GitHub does everything
      possible not to have long lasting tokens).
    post-review: true
    run: playbooks/rust/propose-github.yaml
    nodeset:
      nodes: []
    vars:
      rust_sdk_git_repo: "git@github.com:gtema/openstack.git"
      rust_project_dir: "{{ ansible_user_dir }}/openstack"
      download_artifact_job: "codegenerator-rust-all"