name: PR-pipeline_sip

concurrency:
  max: 5
  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: "cann"
  repo_name: "sip"
  MERGE_ID: ${{atomgit.event.pull_request.number}}
  TARGET_BRANCH: ${{atomgit.ref_name}}
  SOURCE_BRANCH: ${{atomgit.head_ref}}
  obs_path: "${{ vars.OBS_PATH }}/${{ atomgit.event.pull_request.number }}"
  obs_ut_path: "${{ vars.OBS_PATH }}/${{ atomgit.event.pull_request.number }}/ut"
  obs_pre_smoke_path: "${{ vars.OBS_PATH }}/${{ atomgit.event.pull_request.number }}/pre_smoke"
  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 }}
              repo_url: ${{ vars.CI_PATH }}
          -
            name: show_output
            run: |
              echo "image: ${{ steps.revise_image.outputs.Compile_Ascend_X86  }}"
        if: "${{ default() }}"
        runs-on: ["dedicate-hosted", "x64", "small"]
        container:
          image: swr.cn-north-4.myhuaweicloud.com/ci_cann/ubuntu20.04.05_x86:k8s_v1.1006
      JOB_pr:
        name: Test_get_pr
        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 }}
              owner: ${{ env.org_name }}
              repo: ${{ env.repo_name }}
              pr_number: ${{ atomgit.event.pull_request.number }}
              git_token: ${{secrets.GIT_TOKEN}}
          -
            name: upload
            uses: obs-upload
            with:
              endpoint: "https://obs.cn-north-4.myhuaweicloud.com"
              bucket: "ascend-cann-open"
              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
                ${{ steps.process_checkout.outputs.path }}/gitdiff.txt
              object-prefix: ${{ env.obs_path }}/
        runs-on:
        - default
      JOB_shell:
        name: Test_get_shell
        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-cann-open"
              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
      JOB_pre:
        name: Test_pre_pipeline
        steps:
          - name: pre_pipeline
            uses: cann/.gitcode/actions/pre-pipeline@master
            with:
              owner: ${{ env.org_name }}
              repo: ${{ env.repo_name }}
              pr_number: ${{ atomgit.event.pull_request.number }}
              token: ${{ secrets.GIT_TOKEN }}
              apply_label: ${{ vars.APPLY_LABEL }}
          - name: associate-pr-comment
            uses: associate-pr-comment
            if: env.online == 'true'
        runs-on: [dedicate-hosted, x64, small]
        container:
          image: swr.cn-north-4.myhuaweicloud.com/ci_cann/ubuntu20.04.05_x86:k8s_v1.1006
    pre:
    - type: auto
    fail-fast: true
  stage2:
    name: Compile
    jobs:
      JOB_Compile_X86:
        name: Compile_X86
        uses: .gitcode/workflows/x86_compile_action.yml
        with:
          task_name: 'Compile_X86'
          image_version: ${{ jobs.JOB_image.outputs.Compile_Ascend_X86 }}
      JOB_Compile_ARM:
        name: Compile_ARM
        uses: .gitcode/workflows/arm_compile_action.yml
        with:
          task_name: 'Compile_ARM'
          image_version: ${{ jobs.JOB_image.outputs.Compile_Ascend_ARM }}
      JOB_PreSmoke_ARM:
        name: PreSmoke_ARM
        uses: .gitcode/workflows/arm_pre_smoke.yml
        with:
          task_name: 'PreSmoke_ARM'
          image_version: ${{ jobs.JOB_image.outputs.PreSmoke }}
      JOB_UT_Test:
        name: UT_Test
        uses: .gitcode/workflows/llt_action.yml
        with:
          image_version: ${{ jobs.JOB_image.outputs.UT_Test }}
      JOB_codecheck_action:
        name: CodeCheck
        uses: .gitcode/workflows/codecheck_action.yml
        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: true
post:
  jobs:
    job_post:
      name: Test_post
      uses: cann/.gitcode/.gitcode/workflows/post_action.yml@master