name: PR-pipeline_runtime

concurrency:
  max: 15
  exceed-action: QUEUE
  enable: true
  preemption:
    enable: true
    events: [mr_id]

on:
  pull_request_comment:
    types: [created]
    branches: [ '**' ]
    comments: [ '^(?:\/)?compile*' ]
  pr_comment:
    types: [ created ]
    keyword: '^(?:\/)?compile*'

env:
  org_name: "${{ vars.ORG_NAME }}"
  repo_name: ${{atomgit.event.repository.name}}
  MERGE_ID: ${{atomgit.event.pull_request.number}}
  obs_path: "${{ env.org_name }}/${{ env.repo_name }}/ci/package/${{ env.MERGE_ID }}"
  obs_smoke_path: "${{ env.obs_path }}/presmoke/2"
  TARGET_BRANCH: ${{atomgit.ref_name}}
  SOURCE_BRANCH: ${{atomgit.head_ref}}
  online: ${{ vars.APPLY_LABEL }}

stages:
  stage1:
    name: PreBuild
    jobs:
      JOB_image:
        name: Test_image
        steps:
          - name: revise_image
            identifier: revise_image
            uses: cann/.gitcode/actions/revise-img@master
            with:
              repo_name: ${{ env.repo_name }}
              target_branch: ${{ env.TARGET_BRANCH }}
              comment: ${{ atomgit.event.comment.body }}
              token: ${{ secrets.TESTTOKEN }}
          -
            name: show_output
            run: |
              echo "image: ${{ steps.revise_image.outputs.Compile_Ascend_X86 }}"
        if: "${{ default() }}"
        runs-on: ["self-hosted", "arch=x64", "spec=slim"]
        container:
          image: swr.cn-north-4.myhuaweicloud.com/ci_cann/ubuntu20.04.05_x86:k8s_v1.1006
      JOB_pre:
        name: Test_PreBuild
        uses: cann/.gitcode/.gitcode/workflows/pre_action.yml@master
    pre:
    - type: auto
    fail-fast: true
  stage2:
    name: Compile
    jobs:
      JOB_Compile_Ascend_X86:
        name: Compile_Ascend_X86
        uses: .gitcode/workflows/compile_action.yml
        with:
          task_name: 'Compile_Ascend_X86'
          package_name: 'cann-runtime_linux-x86_64.run'
          image_version: ${{ jobs.JOB_image.outputs.Compile_Ascend_X86 }}
          arch: 'x64'
          spec: 'large'
      JOB_Compile_Ascend_ARM:
        name: Compile_Ascend_ARM
        uses: .gitcode/workflows/compile_action.yml
        with:
          task_name: 'Compile_Ascend_ARM'
          package_name: 'cann-runtime_linux-aarch64.run'
          image_version: ${{ jobs.JOB_image.outputs.Compile_Ascend_ARM }}
          arch: 'arm64'
          spec: 'xlarge'
      JOB_Compile_Ascend_X86_ubuntu24:
        name: Compile_Ascend_X86_ubuntu24
        uses: .gitcode/workflows/compile_action.yml
        with:
          task_name: 'Compile_Ascend_X86_ubuntu24'
          package_name: 'cann-runtime_linux-x86_64_ubuntu24.run'
          image_version: ${{ jobs.JOB_image.outputs.Compile_Ascend_X86_ubuntu24 }}
          arch: 'x64'
          spec: 'large'
      JOB_Compile_Ascend_ARM_ubuntu24:
        name: Compile_Ascend_ARM_ubuntu24
        uses: .gitcode/workflows/compile_action.yml
        with:
          task_name: 'Compile_Ascend_ARM_ubuntu24'
          package_name: 'cann-runtime_linux-aarch64_ubuntu24.run'
          image_version: ${{ jobs.JOB_image.outputs.Compile_Ascend_ARM_ubuntu24 }}
          arch: 'arm64'
          spec: 'xlarge'
      JOB_codecheck_action:
        name: CodeCheck
        uses: cann/.gitcode/.gitcode/workflows/codecheck_action.yml@master
        with:
          precommit_image_version: ${{ jobs.JOB_image.outputs.precommit }}
          codecheck_image_version: ${{ jobs.JOB_image.outputs.codecheck }}
      JOB_staticcheck_md_check:
        name: CodeCheck_staticcheck_md_check
        uses: .gitcode/workflows/staticcheck_action.yml
        with:
          check_type: 'md_check'
          image_version: ${{ jobs.JOB_image.outputs.staticcheck }}
    pre:
    - type: auto
    fail-fast: false
  stage3:
    name: UT
    jobs:
      JOB_api_check:
        name: API_Check
        steps:
          -
            name: api-check
            identifier: api-check
            uses: cann/.gitcode/actions/api-check@master
            with:
              org_name: ${{ env.org_name }}
              mode: check
              repo_name: ${{ env.repo_name }}
              merge_id: ${{ env.MERGE_ID }}
        if: env.TARGET_BRANCH == 'master'
        runs-on: ["self-hosted", "arch=x64", "spec=small"]
        container:
          image: swr.cn-north-4.myhuaweicloud.com/ci_cann/${{ jobs.JOB_image.outputs.API_Check }}
      JOB_UT_Test_acl:
        name: UT_Test_acl
        uses: .gitcode/workflows/llt_action.yml
        with:
          task_name: 'UT_Test_acl'
          ut_package: 'ut_cov_*.tar.gz'
          ge_st_rt2: 'acl'
          spec: 'large'
          image_version: ${{ jobs.JOB_image.outputs.UT_Test_acl }}
      JOB_UT_Test_rts_v201:
        name: UT_Test_rts_v201
        uses: .gitcode/workflows/llt_action.yml
        with:
          task_name: 'UT_Test_rts_v201'
          ut_package: 'coverage_rts_*.info'
          ge_st_rt2: 'rts_v201'
          spec: 'large'
          image_version: ${{ jobs.JOB_image.outputs.UT_Test_acl }}
      JOB_UT_Test_rts_c:
        name: UT_Test_rts_c
        uses: .gitcode/workflows/llt_action.yml
        with:
          task_name: 'UT_Test_rts_c'
          ut_package: 'ut_cov_rts_*.tar.gz'
          ge_st_rt2: 'rts_c'
          spec: 'large'
          image_version: ${{ jobs.JOB_image.outputs.UT_Test_acl }}
      JOB_UT_Test_rts_david:
        name: UT_Test_rts_david
        uses: .gitcode/workflows/llt_action.yml
        with:
          task_name: 'UT_Test_rts_david'
          ut_package: 'coverage_rts_*.info'
          ge_st_rt2: 'rts_david'
          spec: 'large'
          image_version: ${{ jobs.JOB_image.outputs.UT_Test_acl }}
      JOB_UT_Test_rts_910b:
        name: UT_Test_rts_910b
        uses: .gitcode/workflows/llt_action.yml
        with:
          task_name: 'UT_Test_rts_910b'
          ut_package: 'coverage_rts_*.info'
          ge_st_rt2: 'rts_910b'
          spec: 'large'
          image_version: ${{ jobs.JOB_image.outputs.UT_Test_acl }}
      JOB_UT_Test_rts_common:
        name: UT_Test_rts_common
        uses: .gitcode/workflows/llt_action.yml
        with:
          task_name: 'UT_Test_rts_common'
          ut_package: 'coverage_rts_*.info'
          ge_st_rt2: 'rts_common'
          spec: 'xlarge'
          image_version: ${{ jobs.JOB_image.outputs.UT_Test_acl }}
      JOB_UT_Test_platform:
        name: UT_Test_platform
        uses: .gitcode/workflows/llt_action.yml
        with:
          task_name: 'UT_Test_platform'
          ut_package: 'ut_cov_*.tar.gz'
          ge_st_rt2: 'platform'
          spec: 'xlarge'
          image_version: ${{ jobs.JOB_image.outputs.UT_Test_platform }}
      JOB_UT_Test_qs:
        name: UT_Test_qs
        uses: .gitcode/workflows/llt_action.yml
        with:
          task_name: 'UT_Test_qs'
          ut_package: 'ut_cov_*.tar.gz'
          ge_st_rt2: 'qs'
          spec: 'large'
          image_version: ${{ jobs.JOB_image.outputs.UT_Test_qs }}
      JOB_UT_Test_aicpusd:
        name: UT_Test_aicpusd
        uses: .gitcode/workflows/llt_action.yml
        with:
          task_name: 'UT_Test_aicpusd'
          ut_package: 'ut_cov_*.tar.gz'
          ge_st_rt2: 'aicpusd'
          spec: '2xlarge'
          image_version: ${{ jobs.JOB_image.outputs.UT_Test_aicpusd }}
      JOB_UT_Test_tsd:
        name: UT_Test_tsd
        uses: .gitcode/workflows/llt_action.yml
        with:
          task_name: 'UT_Test_tsd'
          ut_package: 'ut_cov_*.tar.gz'
          ge_st_rt2: 'tsd'
          spec: 'xlarge'
          image_version: ${{ jobs.JOB_image.outputs.UT_Test_tsd }}
      JOB_UT_Test_error_manager:
        name: UT_Test_error_manager
        uses: .gitcode/workflows/llt_action.yml
        with:
          task_name: 'UT_Test_error_manager'
          ut_package: 'ut_cov_dfx_error_*.tar.gz'
          ge_st_rt2: 'dfx_error_manager'
          spec: 'large'
          image_version: ${{ jobs.JOB_image.outputs.UT_Test_dfx }}
        if: env.TARGET_BRANCH != '9.0.0'
      JOB_UT_Test_slog:
        name: UT_Test_slog
        uses: .gitcode/workflows/llt_action.yml
        with:
          task_name: 'UT_Test_slog'
          ut_package: 'ut_cov_dfx_*.tar.gz'
          ge_st_rt2: 'dfx_log'
          spec: 'large'
          image_version: ${{ jobs.JOB_image.outputs.UT_Test_dfx }}
        if: env.TARGET_BRANCH != '9.0.0'
      JOB_UT_Test_atrace:
        name: UT_Test_atrace
        uses: .gitcode/workflows/llt_action.yml
        with:
          task_name: 'UT_Test_atrace_ut'
          ut_package: 'ut_cov_dfx_*.tar.gz'
          ge_st_rt2: 'dfx_trace'
          spec: 'large'
          image_version: ${{ jobs.JOB_image.outputs.UT_Test_dfx }}
        if: env.TARGET_BRANCH != '9.0.0'
      JOB_UT_Test_msprof_part1:
        name: UT_Test_msprof_part1
        uses: .gitcode/workflows/llt_action.yml
        with:
          task_name: 'UT_Test_msprof_ut'
          ut_package: 'coverage_dfx_msprof_*.info'
          ge_st_rt2: 'dfx_msprof_part1'
          spec: 'xlarge'
          image_version: ${{ jobs.JOB_image.outputs.UT_Test_dfx }}
        if: env.TARGET_BRANCH == 'master'
      JOB_UT_Test_msprof_part2:
        name: UT_Test_msprof_part2
        uses: .gitcode/workflows/llt_action.yml
        with:
          task_name: 'UT_Test_msprof_ut'
          ut_package: 'coverage_dfx_msprof_*.info'
          ge_st_rt2: 'dfx_msprof_part2'
          spec: 'xlarge'
          image_version: ${{ jobs.JOB_image.outputs.UT_Test_dfx }}
        if: env.TARGET_BRANCH == 'master'
      JOB_UT_Test_adump:
        name: UT_Test_adump
        uses: .gitcode/workflows/llt_action.yml
        with:
          task_name: 'UT_Test_adump'
          ut_package: 'ut_cov_dfx_*.tar.gz'
          ge_st_rt2: 'dfx_adump'
          spec: 'large'
          image_version: ${{ jobs.JOB_image.outputs.UT_Test_dfx }}
        if: env.TARGET_BRANCH != '9.0.0'
      JOB_UT_Test_mmpa:
        name: UT_Test_mmpa
        uses: .gitcode/workflows/llt_action.yml
        with:
          task_name: 'UT_Test_mmpa'
          ut_package: 'ut_cov_*.tar.gz'
          ge_st_rt2: 'mmpa'
          spec: 'large'
          image_version: ${{ jobs.JOB_image.outputs.UT_Test_mmpa }}
      JOB_UT_Test_camodel_check:
        name: UT_Test_camodel_check
        uses: .gitcode/workflows/llt_action.yml
        with:
          task_name: 'UT_Test_camodel'
          ut_package: '1'
          ge_st_rt2: 'camodel'
          spec: 'xlarge'
          image_version: ${{ jobs.JOB_image.outputs.UT_Test_camodel }}
        if: env.TARGET_BRANCH == 'master'
      JOB_UT_Test_msprof:
        name: UT_Test_msprof
        uses: .gitcode/workflows/llt_action.yml
        with:
          task_name: 'UT_Test_msprof_ut'
          ut_package: 'ut_cov_dfx_*.tar.gz'
          ge_st_rt2: 'dfx_msprof'
          spec: 'large'
          image_version: ${{ jobs.JOB_image.outputs.UT_Test_dfx }}
        if: env.TARGET_BRANCH == '9.1.0'
    pre:
    - type: auto
    fail-fast: false
  stage4:
    name: UT_report
    select: selected_by_default
    jobs:
      JOB_ut_report_rts:
        name: ut_report_rts
        steps:
          -
            name: Checkout
            identifier: process_checkout
            uses: checkout
            with:
              ref: ${{ atomgit.event.pull_request.merge_commit_sha }}
              allow-unsafe-pr-checkout: true
          -
            name: download
            uses: obs-download
            with:
              endpoint: "https://obs.cn-north-4.myhuaweicloud.com"
              bucket: "ascend-ci"
              key: |
                ${{ env.obs_path }}/pr_filelist.txt
                ${{ env.obs_path }}/pr_filelist_mod.txt
              path: ${{ steps.process_checkout.outputs.path }}
          -
            name: ut_report
            identifier: ut-report
            uses: cann/.gitcode/actions/ut-cov-report@master
            with:
              workspace: ${{ steps.process_checkout.outputs.path }}
              cov_mode: "report"
              ut_field: "rts_common"
              modules: "rts_v201 rts_david rts_910b rts_common"
              source_branch: ${{ env.SOURCE_BRANCH }}
              target_branch: ${{ env.TARGET_BRANCH }}
              obs_path: ${{ env.obs_path }}
          -
            name: upload
            uses: obs-upload
            with:
              endpoint: "https://obs.cn-north-4.myhuaweicloud.com"
              bucket: "ascend-ci"
              access-key: ${{secrets.AK}}
              secret-key: ${{secrets.SK}}
              artifact-path: |
                ${{ steps.process_checkout.outputs.path }}/ut_cov_*.tar.gz
              object-prefix: ${{ env.obs_path }}/
        if: env.TARGET_BRANCH == 'master'
        runs-on: ["self-hosted", "arch=x64", "spec=medium"]
        container:
          image: swr.cn-north-4.myhuaweicloud.com/ci_cann/${{ jobs.JOB_image.outputs.UT_Test_acl }}
      JOB_ut_report_dfx_msprof:
        name: ut_report_dfx_msprof
        steps:
          -
            name: Checkout
            identifier: process_checkout
            uses: checkout
            with:
              ref: ${{ atomgit.event.pull_request.merge_commit_sha }}
              allow-unsafe-pr-checkout: true
          -
            name: download
            uses: obs-download
            with:
              endpoint: "https://obs.cn-north-4.myhuaweicloud.com"
              bucket: "ascend-ci"
              key: |
                ${{ env.obs_path }}/pr_filelist.txt
                ${{ env.obs_path }}/pr_filelist_mod.txt
              path: ${{ steps.process_checkout.outputs.path }}
          -
            name: ut_report
            identifier: ut-report
            uses: cann/.gitcode/actions/ut-cov-report@master
            with:
              workspace: ${{ steps.process_checkout.outputs.path }}
              cov_mode: "report"
              ut_field: "dfx_msprof"
              modules: "dfx_msprof_part1 dfx_msprof_part2"
              source_branch: ${{ env.SOURCE_BRANCH }}
              target_branch: ${{ env.TARGET_BRANCH }}
              obs_path: ${{ env.obs_path }}
          -
            name: upload
            uses: obs-upload
            with:
              endpoint: "https://obs.cn-north-4.myhuaweicloud.com"
              bucket: "ascend-ci"
              access-key: ${{secrets.AK}}
              secret-key: ${{secrets.SK}}
              artifact-path: |
                ${{ steps.process_checkout.outputs.path }}/ut_cov_*.tar.gz
              object-prefix: ${{ env.obs_path }}/
        if: env.TARGET_BRANCH == 'master'
        runs-on: ["self-hosted", "arch=x64", "spec=medium"]
        container:
          image: swr.cn-north-4.myhuaweicloud.com/ci_cann/${{ jobs.JOB_image.outputs.UT_Test_acl }}
    pre:
    - type: auto
    fail-fast: true
  stage5:
    name: PreSmoke
    jobs:
      PreSmoke_A2:
        name: PreSmoke_A2
        steps:
          -
            name: Checkout
            identifier: process_checkout
            uses: checkout
            with:
              ref: ${{ atomgit.event.pull_request.merge_commit_sha }}
              allow-unsafe-pr-checkout: true
          -
            name: download
            uses: obs-download
            with:
              endpoint: "https://obs.cn-north-4.myhuaweicloud.com"
              bucket: "ascend-ci"
              access-key: ${{ secrets.AK }}
              secret-key: ${{ secrets.SK }}
              key: |
                ${{ env.obs_path }}/pr_filelist.txt
                ${{ env.obs_path }}/pr_filelist_mod.txt
                ${{ env.obs_path }}/update_file_detail.txt
                ${{ env.obs_path }}/pre_smoke.sh
              path: ${{ steps.process_checkout.outputs.path }}
          -
            name: smoke executor
            timeout-minutes: 30
            run: |
              set -e
              export smoke_run_file_url=${{jobs.JOB_Compile_Ascend_ARM.outputs.arm_run_url}}
              export repo_name=${{env.repo_name}}
              export pr_id=${{ env.MERGE_ID }}
              export AK=${{secrets.AK}}
              export SK=${{secrets.SK}}
              export WORKSPACE=${{ steps.process_checkout.outputs.path }}
              cd ${{ steps.process_checkout.outputs.path }}
              bash ${{ steps.process_checkout.outputs.path }}/pre_smoke.sh
          - name: upload
            uses: obs-upload
            with:
              endpoint: "https://obs.cn-north-4.myhuaweicloud.com"
              bucket: "ascend-ci"
              access-key: ${{ secrets.AK }}
              secret-key: ${{ secrets.SK }}
              artifact-path: "${{ steps.process_checkout.outputs.path }}/slog*.tar.gz"
              object-prefix: ${obs_smoke_path}/plog/

        if: env.TARGET_BRANCH == 'master'
        runs-on: ['self-hosted','npu=1','smoke=204']
        container:
          image: swr.cn-south-1.myhuaweicloud.com/pre_smoke/${{ jobs.JOB_image.outputs.Smoke_A900_npupool }}
    pre:
    - type: auto
    fail-fast: true
post:
  jobs:
    job_post:
      name: Test_post
      uses: cann/.gitcode/.gitcode/workflows/post_action.yml@master