name: ut_action

on:
  workflow_call:
    inputs:
      ut_type:
        required: true
        type: string
      ut_package:
        type: string
        default: 'ut_cov_*.tar.gz'
      image_version:
        required: true
        type: string
      arch:
        description: '编译架构:x64 或 arm64'
        required: true
        type: string

jobs:
  JOB_ut:
    name: ut
    steps:
      -
        name: Checkout
        identifier: process_checkout
        uses: checkout
        with:
          ref: ${{ atomgit.event.pull_request.merge_commit_sha }}
          token: ${{secrets.GIT_TOKEN}}
      -
        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
            ${{ env.obs_path }}/ut.sh
          path: ${{ steps.process_checkout.outputs.path }}
      -
        name: redis-cache
        uses: cann/.gitcode/actions/redis-cache@master
      -
        name: ut_acc
        identifier: ut
        run: |
          export WORKSPACE=${{ steps.process_checkout.outputs.path }}
          cd ${{ steps.process_checkout.outputs.path }}
          export ut_type=${{ inputs.ut_type }}
          export TARGET_BRANCH=${{ env.TARGET_BRANCH }}
          bash ut.sh
      -
        name: ut_cov
        identifier: ut_cov
        uses: cann/.gitcode/actions/ut-cov-report@master
        with:
          ut_process: ${{ steps.ut.outputs.ut_process }}
          workspace: ${{ steps.process_checkout.outputs.path }}
          ut_type: ${{ inputs.ut_type }}
          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 }}/${{ inputs.ut_package }}
          object-prefix: ${{ env.obs_path }}/
    if: "${{ default() }}"
    runs-on:
      - dedicate-hosted
      - ${{ inputs.arch }}
      - xlarge
    container:
      image: swr.cn-north-4.myhuaweicloud.com/ci_cann/${{ inputs.image_version }}