name: ops-nn_action

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

env:
  org_name: "cann"
  repo_name: "ops-nn"
  MERGE_ID: ${{atomgit.event.pull_request.number}}
  TARGET_BRANCH: ${{atomgit.ref_name}}
  SOURCE_BRANCH: ${{atomgit.head_ref}}
  obs_path: "${{ vars.OBS_PATH }}/${{ env.MERGE_ID }}"
  obs_smoke_path: "${{ env.obs_path }}/presmoke/2"

stages:
  stage1:
    name: image
    jobs:
      JOB_image:
        name: image
        steps:
          - name: revise_image
            identifier: revise_image
            uses: cann/.gitcode/actions/revise-img@master
            with:
              repo_name: "ops-nn"
              target_branch: ${{ env.TARGET_BRANCH }}
              repo_url: ${{ vars.CI_PATH }}
          -
            name: show_output
            run: |
              echo "image: ${{ steps.revise_image.outputs.Compile_Ascend_X86  }}"
        if: "${{ default() }}"
        runs-on: ["codearts-hosted", "ubuntu-latest", "x64", "small"]
      JOB_pr:
        name: get_pr_files
        steps:
          -
            name: Checkout
            identifier: process_checkout
            uses: checkout
            with:
              ref: ${{ atomgit.event.pull_request.merge_commit_sha || atomgit.sha }}
              token: ${{secrets.GIT_TOKEN}}
          -
            name: get_pr
            identifier: get_pr
            uses: cann/.gitcode/actions/get-pr@master
            with:
              workspace: ${{ steps.process_checkout.outputs.path }}
              target_branch: ${{ env.TARGET_BRANCH }}
              git_token: ${{secrets.GIT_TOKEN}}
          -
            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 }}/pr_filelist.txt
                ${{ steps.process_checkout.outputs.path }}/pr_filelist_mod.txt
                ${{ steps.process_checkout.outputs.path }}/pr_filelist_precommit.txt
                ${{ steps.process_checkout.outputs.path }}/update_file_detail.txt
              object-prefix: ${{ env.obs_path }}/
        runs-on:
        - default
      JOB_shell:
        name: get_shell_files
        steps:
          -
            name: Checkout
            identifier: process_checkout
            uses: checkout
            with:
              ref: master
              token: ${{secrets.GIT_TOKEN}}
          -
            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 }}/.gitcode/scripts/*
              object-prefix: ${{ env.obs_path }}/
        if: "${{ default() }}"
        runs-on:
        - default
    pre:
    - type: auto
    fail-fast: true
  stage2:
    name: compile
    jobs:
      JOB_codecheck_action:
        name: codecheck_action
        uses: .gitcode/workflows/codecheck_action.yml
        with:
          precommit_image_version: ${{ jobs.JOB_image.outputs.precommit }}
          codecheck_image_version: ${{ jobs.JOB_image.outputs.codecheck }}
      JOB_x86_compile:
        name: x86_compile
        uses: .gitcode/workflows/x86_compile_action.yml
        with:
          task_name: 'x86_compile'
          image_version: ${{ jobs.JOB_image.outputs.Compile_Ascend_X86 }}
      JOB_x86_compile_ubuntu24:
        name: x86_compile_ubuntu24
        uses: .gitcode/workflows/x86_compile_action.yml
        with:
          task_name: 'x86_compile_ubuntu24'
          image_version: ${{ jobs.JOB_image.outputs.Compile_Ascend_X86_ubuntu24 }}
      JOB_X86_monitor_910b:
        name: X86_monitor_910b
        uses: .gitcode/workflows/x86_compile_action.yml
        with:
          task_name: 'X86_monitor_910b'
          image_version: ${{ jobs.JOB_image.outputs.Compile_X86_monitor_910b }}
      JOB_X86_monitor_910c:
        name: X86_monitor_910c
        uses: .gitcode/workflows/x86_compile_action.yml
        with:
          task_name: 'X86_monitor_910c'
          image_version: ${{ jobs.JOB_image.outputs.Compile_X86_monitor_910c }}
      JOB_X86_monitor_950:
        name: X86_monitor_950
        uses: .gitcode/workflows/x86_compile_action.yml
        with:
          task_name: 'X86_monitor_950'
          image_version: ${{ jobs.JOB_image.outputs.Compile_X86_monitor_9_0_0 }}
      JOB_Compile_Ascend_X86_950_ubuntu24:
        name: Compile_Ascend_X86_950_ubuntu24
        uses: .gitcode/workflows/x86_compile_action.yml
        with:
          task_name: 'Compile_Ascend_X86_950_ubuntu24'
          image_version: ${{ jobs.JOB_image.outputs.Compile_Ascend_X86_950_ubuntu24 }}
      JOB_Compile_Ascend_X86_mobile_station:
        name: Compile_Ascend_X86_mobile_station
        uses: .gitcode/workflows/x86_compile_action.yml
        with:
          task_name: 'Compile_Ascend_X86_mobile_station'
          image_version: ${{ jobs.JOB_image.outputs.Compile_Ascend_X86_mobile_station }}
      JOB_Compile_Ascend_X86_mobile_station_ubuntu24:
        name: Compile_Ascend_X86_mobile_station_ubuntu24
        uses: .gitcode/workflows/x86_compile_action.yml
        with:
          task_name: 'Compile_Ascend_X86_mobile_station_ubuntu24'
          image_version: ${{ jobs.JOB_image.outputs.Compile_Ascend_X86_mobile_station_ubuntu24 }}
      JOB_Compile_Ascend_X86_950:
        name: Compile_Ascend_X86_950
        uses: .gitcode/workflows/x86_compile_action.yml
        with:
          task_name: 'Compile_Ascend_X86_950'
          image_version: ${{ jobs.JOB_image.outputs.Compile_Ascend_X86_950 }}
      JOB_Pre_compile:
        name: Pre_compile
        uses: .gitcode/workflows/arm_compile_action.yml
        with:
          task_name: 'Pre_compile'
          image_version: ${{ jobs.JOB_image.outputs.Pre_Compile }}
      JOB_compile_single:
        name: compile_single
        uses: .gitcode/workflows/arm_compile_action.yml
        with:
          task_name: 'compile_single'
          image_version: ${{ jobs.JOB_image.outputs.Compile_Ascend_single }}
      JOB_arm_compile:
        name: arm_compile
        uses: .gitcode/workflows/arm_compile_action.yml
        with:
          task_name: 'arm_compile'
          image_version: ${{ jobs.JOB_image.outputs.Compile_Ascend_ARM }}
      JOB_arm_compile_ubuntu24:
        name: arm_compile_ubuntu24
        uses: .gitcode/workflows/arm_compile_action.yml
        with:
          task_name: 'arm_compile_ubuntu24'
          image_version: ${{ jobs.JOB_image.outputs.Compile_Ascend_ARM_ubuntu24 }}
      JOB_compile_single_ubuntu24:
        name: compile_single_ubuntu24
        uses: .gitcode/workflows/arm_compile_action.yml
        with:
          task_name: 'compile_single_ubuntu24'
          image_version: ${{ jobs.JOB_image.outputs.Compile_Ascend_single_ubuntu24 }}
      JOB_Compile_Ascend_experimental:
        name: Compile_Ascend_experimental
        uses: .gitcode/workflows/arm_compile_action.yml
        with:
          task_name: 'Compile_Ascend_experimental'
          image_version: ${{ jobs.JOB_image.outputs.Compile_Ascend_experimental }}
      JOB_Compile_Ascend_experimental_ubuntu24:
        name: Compile_Ascend_experimental_ubuntu24
        uses: .gitcode/workflows/arm_compile_action.yml
        with:
          task_name: 'Compile_Ascend_experimental_ubuntu24'
          image_version: ${{ jobs.JOB_image.outputs.Compile_Ascend_experimental_ubuntu24 }}
      JOB_Compile_Ascend_ARM_950_ubuntu24:
        name: Compile_Ascend_ARM_950_ubuntu24
        uses: .gitcode/workflows/arm_compile_action.yml
        with:
          task_name: 'Compile_Ascend_ARM_950_ubuntu24'
          image_version: ${{ jobs.JOB_image.outputs.Compile_Ascend_ARM_950_ubuntu24 }}
      JOB_Compile_Ascend_ARM_950:
        name: Compile_Ascend_ARM_950
        uses: .gitcode/workflows/arm_compile_action.yml
        with:
          task_name: 'Compile_Ascend_ARM_950'
          image_version: ${{ jobs.JOB_image.outputs.Compile_Ascend_ARM_950 }}
      JOB_staticcheck_markdown:
        name: staticcheck_markdown
        uses: .gitcode/workflows/staticcheck_action.yml
        with:
          check_type: 'markdown'
          image_version: ${{ jobs.JOB_image.outputs.staticcheck }}
      JOB_staticcheck_codespell_check:
        name: staticcheck_codespell_check
        uses: .gitcode/workflows/staticcheck_action.yml
        with:
          check_type: 'codespell_check'
          image_version: ${{ jobs.JOB_image.outputs.staticcheck }}
      JOB_staticcheck_tag_closed_check:
        name: staticcheck_tag_closed_check
        uses: .gitcode/workflows/staticcheck_action.yml
        with:
          check_type: 'tag_closed_check'
          image_version: ${{ jobs.JOB_image.outputs.staticcheck }}
      JOB_staticcheck_resource_existence_check:
        name: staticcheck_resource_existence_check
        uses: .gitcode/workflows/staticcheck_action.yml
        with:
          check_type: 'resource_existence_check'
          image_version: ${{ jobs.JOB_image.outputs.staticcheck }}
      JOB_staticcheck_link_validity_check:
        name: staticcheck_link_validity_check
        uses: .gitcode/workflows/staticcheck_action.yml
        with:
          check_type: 'link_validity_check'
          image_version: ${{ jobs.JOB_image.outputs.staticcheck }}
    pre:
    - type: auto
    fail-fast: true
  stage3:
    name: ut
    jobs:
      JOB_UT_Test_ophost:
        name: UT_Test_ophost
        uses: .gitcode/workflows/llt_action.yml
        with:
          ut_type: 'ophost'
          ut_package: 'coverage_*.info'
          image_version: ${{ jobs.JOB_image.outputs.UT_Test_ophost }}
      JOB_UT_Test_opapi:
        name: UT_Test_opapi
        uses: .gitcode/workflows/llt_action.yml
        with:
          ut_type: 'opapi'
          ut_package: 'coverage_*.info'
          image_version: ${{ jobs.JOB_image.outputs.UT_Test_opapi }}
      JOB_UT_Test_kernel:
        name: UT_Test_kernel
        uses: .gitcode/workflows/llt_action.yml
        with:
          ut_type: 'opkernel'
          ut_package: 'coverage_*.info'
          image_version: ${{ jobs.JOB_image.outputs.UT_Test_kernel }}
      JOB_UT_Test_opgraph:
        name: UT_Test_opgraph
        uses: .gitcode/workflows/llt_action.yml
        with:
          ut_type: 'opgraph'
          ut_package: 'coverage_*.info'
          image_version: ${{ jobs.JOB_image.outputs.UT_Test_opgraph }}
    pre:
    - type: auto
    fail-fast: true
  stage4:
    name: PreSmoke
    jobs:
      A2_smoke:
        name: A2_pre_smoke
        steps:
          -
            name: Checkout
            identifier: process_checkout
            uses: checkout
            with:
              token: ${{secrets.GIT_TOKEN}}
              path: "./runner"
          -
            name: Checkout gitcode
            identifier: process_checkout_gitcode
            uses: checkout
            with:
              repository: "https://gitcode.com/cann/.gitcode.git"
              ref: master
              path: "./runner/ci"
          -
            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: tar businesscode
            run: |
              echo "############${{ steps.process_checkout.outputs.path }}#################"
              echo "#####image: swr.cn-south-1.myhuaweicloud.com/pre_smoke/${{ jobs.JOB_image.outputs.PreSmoke_A900 }}#####"
              cd ${{ steps.process_checkout.outputs.path }}
              tar -zcf ../smoke_data.tar.gz .
              mv ../smoke_data.tar.gz ./
          -
            name: upload
            identifier: process_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 }}/smoke_data.tar.gz
              object-prefix: ${{ env.obs_smoke_path }}/
          -
            name: smoke executor
            uses: manifest-management-plugin
            with:
              action: DEPLOY
              repo: ${{ steps.process_checkout.outputs.path }}
              file_path: ${{ steps.process_checkout.outputs.path }}/ci/smoke-conf/smoke-A2.yaml
              manifest_image: swr.cn-south-1.myhuaweicloud.com/pre_smoke/${{ jobs.JOB_image.outputs.PreSmoke_A900 }}
              custom_shell_script: |-
                set -e
                export single_tar_url=${{jobs.JOB_compile_single.outputs.arm_run_url}}
                export experimental_run_url=${{jobs.JOB_Compile_Ascend_experimental_ubuntu24.outputs.arm_run_url}}
                export fatrelu_run_url=${{jobs.JOB_Pre_compile.outputs.arm_run_url}}
                export repo_name=${{env.repo_name}}
                export pr_id=${{ env.MERGE_ID }}
                export AK=${{secrets.AK}}
                export SK=${{secrets.SK}}
                mkdir -p /home/taskspace && cd /home/taskspace
                wget -nv ${{ steps.process_upload.outputs.primary-url }}
                tar -zxf $(basename "${{ steps.process_upload.outputs.primary-url }}")
                bash /home/taskspace/pre_smoke.sh
          -
            name: smoke resource clean
            uses: manifest-management-plugin
            with:
              action: CRUSH
              repo: ${{ steps.process_checkout.outputs.path }}
              file_path: ${{ steps.process_checkout.outputs.path }}/ci/smoke-conf/smoke-A2.yaml

        if: "${{ default() }}"
        runs-on: ['self-hosted','arch=arm','smoke=204']
    pre:
    - type: auto
    fail-fast: true