github.com/matrixorigin/matrixone@v0.7.0/.github/workflows/robot.yml (about)

     1  name: WeWork Robot
     2  
     3  # Controls when the workflow will run
     4  on:
     5    issues:
     6      types: [closed, assigned, opened]
     7    schedule:
     8      - cron: '30 8 * * *'
     9    workflow_dispatch:
    10  
    11  
    12  # A workflow run is made up of one or more jobs that can run sequentially or in parallel.
    13  jobs:
    14    issue-notify:
    15      if : github.event_name == 'issues' && github.event.action == 'assigned' 
    16      runs-on: ubuntu-latest
    17      steps:
    18        - name : ISSUE Triggered
    19          uses: chf007/action-wechat-work@master
    20          env:
    21            WECHAT_WORK_BOT_WEBHOOK: ${{secrets.WECHAT_WORK_BOT_WEBHOOK}}
    22          with:
    23            msgtype: markdown
    24            mentioned_list: '["@all"]'
    25            content: "New Issue Opened or Assigned: [${{ github.event.issue.title }}](${{ github.event.issue.html_url }})\nAssignees:<font color=\"warning\">${{ join(github.event.issue.assignees.*.login, ', ') }}</font>\nOpen Issue Number: <font color=\"warning\">${{ github.event.repository.open_issues }}</font>"
    26  
    27    add-projects-milestone:
    28      if: github.event_name == 'issues' && github.event.action == 'opened'
    29      runs-on: ubuntu-latest
    30      steps:
    31        - name: Issue Add Projects
    32          if: contains(github.event.issue.labels.*.name, 'kind/bug')
    33          uses: actions/add-to-project@v0.3.0
    34          with:
    35            project-url: https://github.com/orgs/matrixorigin/projects/13
    36            github-token: ${{ secrets.TOKEN_ACTION }}
    37            labeled: kind/bug
    38            label-operator: OR
    39  
    40        - name: Issue Add  Milestone
    41          if: contains(github.event.issue.labels.*.name, 'kind/bug')
    42          uses: cgetc/automatically-set-milestone-to-issue@v0.1.2
    43          with:
    44            github-token: ${{ secrets.TOKEN_ACTION }}
    45            version-prefix: "v0.7.0"
    46  
    47    check-bvt-issue:
    48      if: github.event.action == 'closed'
    49      runs-on: ubuntu-latest
    50      steps:
    51        - name: CheckOut
    52          uses: actions/checkout@v3
    53  
    54        - name: Check the code to see if the issue number is removed
    55          if: contains(github.event.issue.labels.*.name, 'bvt') || contains(github.event.issue.labels.*.name, 'cn-dn-bvt')
    56          id: get_check_val
    57          env:
    58            ISSUE_NUM: ${{ github.event.issue.number }}
    59          run: |
    60            res=`grep -r "issue#$ISSUE_NUM" ${{ github.workspace }}/test || true`
    61  
    62            if [ -n "$res" ]; then
    63              echo "::set-output name=check_val::True"
    64            else
    65              echo "::set-output name=check_val::False"
    66            fi
    67  
    68        - name: Reopen Issue
    69          if: ${{ steps.get_check_val.outputs.check_val == 'True' }}
    70          uses: actions-cool/issues-helper@v3
    71          with:
    72            actions: 'open-issue'
    73            token: ${{ secrets.TOKEN_ACTION }}
    74            issue-number: ${{ github.event.issue.number }}
    75  
    76        - name: create-comment
    77          if: ${{ steps.get_check_val.outputs.check_val == 'True' }}
    78          uses: actions-cool/issues-helper@v3
    79          with:
    80            actions: 'create-comment'
    81            token: ${{ secrets.TOKEN_ACTION }}
    82            issue-number: ${{ github.event.issue.number }}
    83            body: |
    84              Hello @${{ github.event.issue.user.login }}. The bug issue in the BVT test code has not been removed,issues automatically open.
    85  
    86    issue-reopen:
    87      runs-on: ubuntu-latest
    88      steps:
    89        - name: Reopen Issue
    90          if: github.event.issue.user.login != github.event.sender.login && github.event.action == 'closed' && github.event.sender.login != 'sukki37' && github.event.sender.login != 'aressu1985' && github.event.sender.login != 'fengttt'
    91          uses: actions-cool/issues-helper@v3
    92          with:
    93            actions: 'open-issue'
    94            token: ${{ secrets.TOKEN_ACTION }}
    95            issue-number: ${{ github.event.issue.number }}
    96  
    97    nightly-check:
    98      if: github.event_name != 'issues'
    99      runs-on: ubuntu-latest
   100      steps:
   101        - uses: actions/checkout@v3
   102          with:
   103            fetch-depth: '3'
   104            path: ./matrixone
   105  
   106        - name: Set up Go
   107          uses: actions/setup-go@v2
   108          with:
   109            go-version: 1.19
   110  
   111        - name: Build MatrixOne
   112          run: |
   113            cd $GITHUB_WORKSPACE/matrixone && make clean && make build
   114  
   115        - name: Static Code Analysis
   116          continue-on-error: true
   117          run: |
   118            cd $GITHUB_WORKSPACE/matrixone
   119            make install-static-check-tools
   120            make static-check &>lint.out
   121            
   122        - name: count sca failed files
   123          run: |
   124            cd $GITHUB_WORKSPACE/matrixone
   125            echo "FAILED_FILES_NUM=$(cat lint.out | grep -E '^pkg|^cmd' | awk -F ".go" '{if(NF>=2) {print $1}}' | sort -u | wc -l)" >> $GITHUB_ENV
   126  
   127        - name: Set Variables
   128          run: |
   129            echo "ut_report='UT-Report.out'" >> $GITHUB_ENV
   130            echo "raw_ut_coverage='ut_coverage.raw'" >> $GITHUB_ENV
   131            echo "raw_bvt_coverage='bvt_coverage.raw'" >> $GITHUB_ENV
   132            echo "ut_coverage='ut_coverage.out'" >> $GITHUB_ENV
   133            echo "bvt_coverage='bvt_coverage.out'" >> $GITHUB_ENV
   134            echo "ut_html_coverage='ut_coverage.html'" >> $GITHUB_ENV
   135            echo "bvt_html_coverage='bvt_coverage.html'" >> $GITHUB_ENV
   136            echo "ut_excluded_pkg='pkg/pb\|pkg/sql/parsers/goyacc'" >> $GITHUB_ENV
   137            echo "bvt_excluded_pkg='pkg/pb'" >> $GITHUB_ENV
   138  
   139        - name: Clone test-tool repository
   140          if: ${{ env.Job-Status }} == 2
   141          uses: actions/checkout@v3
   142          with:
   143            repository: matrixorigin/mo-tester
   144            path: ./mo-tester
   145            ref: main
   146  
   147        - name: Set up JDK 8 for x64
   148          if: ${{ env.Job-Status }} == 2
   149          uses: actions/setup-java@v3
   150          with:
   151            java-version: '8'
   152            distribution: 'adopt'
   153            architecture: x64
   154  
   155        - name: Start Test Service
   156          timeout-minutes: 10
   157          run: |
   158            cd $GITHUB_WORKSPACE/matrixone
   159            if  [ -d  "./store"  ]; then rm -rf ./store; fi
   160            go test -c -tags service_test -cover -covermode=count -coverpkg=./pkg/... ./cmd/mo-service/ -o service_test
   161            ./service_test -test.coverprofile=${{ env.raw_bvt_coverage }} -launch ./etc/launch-tae-multi-CN-tae-DN/launch.toml &>service.log &
   162            
   163        - name: Start BVT Test
   164          if: ${{ env.Job-Status }} == 2
   165          id: bvt_on_pr_version
   166          continue-on-error: true
   167          run: |
   168            sleep 300s
   169            cd $GITHUB_WORKSPACE/mo-tester
   170            ./run.sh -n -g -p $GITHUB_WORKSPACE/matrixone/test/distributed/cases 2>&1
   171  
   172        - name: Generate BVT Coverage File
   173          timeout-minutes: 10
   174          run: |
   175            cd $GITHUB_WORKSPACE/matrixone
   176            ps aux|grep 'service_test' | grep -v 'grep' | awk '{print $2}'
   177            ps aux|grep 'service_test' | grep -v 'grep' | awk '{print $2}' | xargs kill -s SIGINT
   178            sleep 60
   179            cat ${{ env.raw_bvt_coverage }} | grep -v ${{ env.bvt_excluded_pkg }} > ${{ env.bvt_coverage }}
   180            echo "bvt_coverage finished"
   181            go tool cover -o ${{ env.bvt_html_coverage }} -html=${{ env.bvt_coverage }}
   182            echo "bvt_html_coverage finished"
   183  
   184  
   185        - name: Unit Test
   186          timeout-minutes: 120
   187          run: |
   188            cd $GITHUB_WORKSPACE/matrixone
   189            test_scope=$(go list ./... | grep -v 'driver\|engine/aoe\|engine/memEngine\|pkg/catalog')
   190            echo "ut start"
   191            CGO_CFLAGS="-I${GITHUB_WORKSPACE}/matrixone/cgo" CGO_LDFLAGS="-L${GITHUB_WORKSPACE}/matrixone/cgo -lmo" go test -v -tags matrixone_test -p 6 -covermode=count -coverprofile=${{ env.raw_ut_coverage }} -coverpkg=./pkg/... ${test_scope} | tee ${{ env.ut_report }}
   192            echo "ut finished"
   193            cat ${{ env.raw_ut_coverage }} | grep -v ${{ env.ut_excluded_pkg }} > ${{ env.ut_coverage }}
   194            echo "ut_coverage finished"
   195            go tool cover -o ${{ env.ut_html_coverage }} -html=${{ env.ut_coverage }}
   196            echo "ut_html_coverage finished"
   197            rm -rf ${{ env.raw_ut_coverage }}
   198            
   199  
   200        - name: Coverage Calculate
   201          run: |
   202            cd $GITHUB_WORKSPACE/matrixone
   203            echo "UT_CODE_COVERAGE: $(awk 'BEGIN {covered_line=0;all_line=0} {if ($3>=1 && !($1 in covered)) {covered[$1] = $2; covered_line+=$2;} if (!($1 in all)) { all[$1] = $2; all_line+=$2;}} END {print covered_line/all_line}' ${{ env.ut_coverage }})" > coverage_report.txt
   204            echo "BVT_CODE_COVERAGE: $(awk 'BEGIN {covered_line=0;all_line=0} {if ($3>=1 && !($1 in covered)) {covered[$1] = $2; covered_line+=$2;} if (!($1 in all)) { all[$1] = $2; all_line+=$2;}} END {print covered_line/all_line}' ${{ env.bvt_coverage }})"  >> coverage_report.txt
   205            echo "UT_CODE_COVERAGE=$(awk 'BEGIN {covered_line=0;all_line=0} {if ($3>=1 && !($1 in covered)) {covered[$1] = $2; covered_line+=$2;} if (!($1 in all)) { all[$1] = $2; all_line+=$2;}} END {print covered_line/all_line}' ${{ env.ut_coverage }})" >> $GITHUB_ENV
   206            echo "BVT_CODE_COVERAGE=$(awk 'BEGIN {covered_line=0;all_line=0} {if ($3>=1 && !($1 in covered)) {covered[$1] = $2; covered_line+=$2;} if (!($1 in all)) { all[$1] = $2; all_line+=$2;}} END {print covered_line/all_line}' ${{ env.bvt_coverage }})" >> $GITHUB_ENV
   207            coverage="$(cat ${{ env.ut_coverage }} ${{ env.bvt_coverage }} | awk 'BEGIN {covered_line=0;all_line=0} {if ($3>=1 && !($1 in covered)) {covered[$1] = $2; covered_line+=$2;} if (!($1 in all)) { all[$1] = $2; all_line+=$2;}} END {print covered_line/all_line}')"
   208            echo "Overall Coverage: ${coverage}"  >> coverage_report.txt
   209            echo "GENERAL_CODE_COVERAGE=${coverage}" >> $GITHUB_ENV
   210            pkgs=$(go list ./pkg/... | awk -v FS='/' -v OFS='/' '{if ($5=="vm" || $5=="sql") print $4,$5,$6"/"; else print $4,$5"/"}' | sort -u | grep -v ${{ env.ut_excluded_pkg }} | grep -v '//')
   211            echo -e "\n------------ut detail coverage----------"  >> coverage_report.txt
   212            echo "" > ut_tmp.txt
   213            for pkg in ${pkgs[@]}
   214            do
   215            if [ "$(cat ${{ env.ut_coverage }} |grep $pkg | grep -v "grep" | wc -l)" -gt 0 ];
   216            then
   217                c="$(cat ${{ env.ut_coverage }} |grep $pkg|awk 'BEGIN {covered_line=0;all_line=0} {if ($3>=1 && !($1 in covered)) {covered[$1] = $2; covered_line+=$2;} if (!($1 in all)) { all[$1] = $2; all_line+=$2;}} END {print covered_line/all_line}')";
   218                echo -e "${pkg}:\t${c}" >> ut_tmp.txt;
   219            else
   220                echo -e "${pkg}:\t0" >> ut_tmp.txt;
   221            fi
   222            done
   223            cat ut_tmp.txt | sort -k 1 -k 2n  >> coverage_report.txt
   224            pkgs=$(go list ./pkg/... | awk -v FS='/' -v OFS='/' '{if ($5=="vm" || $5=="sql") print $4,$5,$6"/"; else print $4,$5"/"}' | sort -u | grep -v ${{ env.bvt_excluded_pkg }} | grep -v '//')
   225            echo -e "\n------------bvt detail coverage----------" >> coverage_report.txt
   226            echo "" > bvt_tmp.txt
   227            for pkg in ${pkgs[@]}
   228            do
   229            if [ "$(cat ${{ env.bvt_coverage }} |grep $pkg | grep -v "grep" | wc -l)" -gt 0 ];
   230            then
   231                c="$(cat ${{ env.bvt_coverage }} |grep $pkg|awk 'BEGIN {covered_line=0;all_line=0} {if ($3>=1 && !($1 in covered)) {covered[$1] = $2; covered_line+=$2;} if (!($1 in all)) { all[$1] = $2; all_line+=$2;}} END {print covered_line/all_line}')";
   232                echo -e "${pkg}:\t${c}" >> bvt_tmp.txt;
   233            else
   234                echo -e "${pkg}:\t0" >> bvt_tmp.txt;
   235            fi
   236            done
   237            cat bvt_tmp.txt | sort -k 1 -k 2n >> coverage_report.txt
   238            zip -r code_quality_reports.zip ${{ env.bvt_html_coverage }} ${{ env.ut_html_coverage }} coverage_report.txt lint.out UT-Report.out
   239  
   240        - name: Generate Notice Content
   241          run: |
   242            cd $GITHUB_WORKSPACE/matrixone
   243            cat coverage_report.txt
   244            echo "Today=$(date -d now +%Y-%m-%d)" >> $GITHUB_ENV
   245            echo "Url=${{ github.event.repository.html_url }}/actions/runs/${{ github.run_id }}" >> $GITHUB_ENV
   246            echo 'Detail<<EOF' >> $GITHUB_ENV
   247            cat coverage_report.txt >> $GITHUB_ENV
   248            echo 'EOF' >> $GITHUB_ENV
   249            
   250        - uses: actions/upload-artifact@v3
   251          if: ${{ always() }}
   252          continue-on-error: true
   253          with:
   254            name: code_quality_reports
   255            path: |
   256              ${{ github.workspace }}/matrixone/code_quality_reports.zip
   257            retention-days: 7
   258  
   259        - uses: actions/upload-artifact@v3
   260          if: ${{ failure() }}
   261          continue-on-error: true
   262          with:
   263            name: test_reports
   264            path: |
   265              ${{ github.workspace }}/matrixone
   266            retention-days: 7
   267  
   268        - name: WeChat Work notification
   269          id: notification
   270          uses: chf007/action-wechat-work@master
   271          env:
   272            WECHAT_WORK_BOT_WEBHOOK: ${{secrets.WECHAT_WORK_BOT_WEBHOOK}}
   273          with:
   274            msgtype: markdown
   275            mentioned_list: '["@all"]'
   276            content: "<font color=\"warning\">Nightly Code Quality - ${{ env.Today }} </font>\nNumber of files failed static checks:<font color=\"warning\">${{ env.FAILED_FILES_NUM }}</font>\nUT Coverage Summary:<font color=\"warning\">${{ env.UT_CODE_COVERAGE }}</font>\nBVT Coverage Summary:<font color=\"warning\">${{ env.BVT_CODE_COVERAGE }}</font>\nGeneral Coverage Summary:<font color=\"warning\">${{ env.GENERAL_CODE_COVERAGE }}</font>\nFor details, please visit [Action Run](${{ env.Url }})\n"
   277  
   278        - name: WeChat Work notification
   279          id: detail-notification
   280          uses: chf007/action-wechat-work@master
   281          env:
   282            WECHAT_WORK_BOT_WEBHOOK: ${{secrets.WECHAT_WORK_BOT_WEBHOOK}}
   283          with:
   284            msgtype: text
   285            mentioned_list: '["@all"]'
   286            content: ${{ env.Detail }}
   287