File: tests.yaml

package info (click to toggle)
snapd 2.72-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 80,412 kB
  • sloc: sh: 16,506; ansic: 16,211; python: 11,213; makefile: 1,919; exp: 190; awk: 58; xml: 22
file content (135 lines) | stat: -rw-r--r-- 4,754 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
name: Jobs
on:
  pull_request:
    branches:
      - main
  push:
    branches:
      - main

jobs:
  unit-tests:
    runs-on: ubuntu-latest
    steps:
    - name: Checkout code
      uses: actions/checkout@v2

    - name: Run shellCheck for tools
      run: |
          # Run shellcheck from the snap which most likely is newer than what the distro provides
          sudo apt-get remove --purge shellcheck
          sudo snap install shellcheck
          find tools utils remote -type f -exec sh -c "head -n 1 {} | egrep -a 'bin/bash|bin/sh' >/dev/null" \; -print -exec shellcheck {} \;

          # Run shellcheck from the distro
          sudo snap remove shellcheck
          sudo apt-get install -y shellcheck
          find tools utils remote -type f -exec sh -c "head -n 1 {} | egrep -a 'bin/bash|bin/sh' >/dev/null" \; -print -exec shellcheck {} \;

    - name: Run codespell tool
      run: |
          sudo apt install python3-pip
          pip3 install codespell
          codespell

    - name: Run Python unit tests
      run: |
          python3 -m unittest discover -s utils

  test:
    needs: [unit-tests]
    runs-on: [self-hosted, spread-enabled]
    steps:
    - name: Checkout code
      uses: actions/checkout@v2

    - name: Get previous attempt
      id: get-previous-attempt
      run: |
        echo "previous_attempt=$(( ${{ github.run_attempt }} - 1 ))" >> $GITHUB_OUTPUT
      shell: bash

    - name: Get previous cache
      uses: actions/cache@v3
      with:
        path: "${{ github.workspace }}/.test-results"
        key: "${{ github.job }}-results-${{ github.run_id }}-${{ steps.get-previous-attempt.outputs.previous_attempt }}"

    - name: Prepare test results env and vars
      id: prepare-test-results-env
      run: |
          # Create test results directories and save vars
          TEST_RESULTS_DIR="${{ github.workspace }}/.test-results"
          echo "TEST_RESULTS_DIR=$TEST_RESULTS_DIR" >> $GITHUB_ENV

          # Save the var with the failed tests file
          echo "FAILED_TESTS_FILE=$TEST_RESULTS_DIR/failed-tests" >> $GITHUB_ENV

          # Make sure the test results dirs are created
          # This step has to be after the cache is restored
          mkdir -p "$TEST_RESULTS_DIR"

    - name: Check failed tests to run
      if: "!contains(github.event.pull_request.labels.*.name, 'Run all')"
      run: |
          # Save previous failed test results in FAILED_TESTS env var
          FAILED_TESTS=""
          if [ -f "$FAILED_TESTS_FILE" ]; then
              echo "Failed tests file found"
              FAILED_TESTS="$(cat $FAILED_TESTS_FILE)"
              if [ -n "$FAILED_TESTS" ]; then
                  echo "Failed tests to run: $FAILED_TESTS"
                  echo "FAILED_TESTS=$FAILED_TESTS" >> $GITHUB_ENV
              fi
          fi

    - name: Run test
      run: |
          RUN_TESTS="google:tests/ google-nested:tests/ openstack:tests/"
          if [ -n "$FAILED_TESTS" ]; then
              RUN_TESTS="$FAILED_TESTS"
          fi
          CHANGE_ID="${{ github.event.number }}"
          if [ -z "$PR_ID" ]; then
            CHANGE_ID="main"
          fi
          CHANGE_ID="${CHANGE_ID}_n${{ github.run_attempt }}"
          # The log-filter tool is used to filter the spread logs to be stored
          FILTER_PARAMS="-o spread_$CHANGE_ID.filtered.log -e Debug -e WARNING: -f Failed=NO_LINES -f Error=NO_LINES"

          (set -o pipefail; spread $RUN_TESTS | ./utils/log-filter $FILTER_PARAMS | tee spread.log)

    - name: Discard spread workers
      if: always()
      run: |
        shopt -s nullglob;
        for r in .spread-reuse.*.yaml; do
          spread -discard -reuse-pid="$(echo "$r" | grep -o -E '[0-9]+')";
        done

    - name: analyze spread test results
      if: always()
      run: |
          if [ -f spread.log ]; then
              echo "Running spread log parser"
              ./utils/log-parser spread.log --output spread-results.json
    
              echo "Determining which tests were executed"
              RUN_TESTS="google:tests/ google-nested:tests/"
              if [ -n "$FAILED_TESTS" ]; then
                  RUN_TESTS="$FAILED_TESTS"
              fi

              echo "Running spread log analyzer"
              ./utils/log-analyzer list-reexecute-tasks "$RUN_TESTS" spread-results.json > "$FAILED_TESTS_FILE"
          else
              echo "No spread log found, saving empty list of failed tests"
              touch "$FAILED_TESTS_FILE"
          fi

    - name: save spread test results to cache
      if: always()
      uses: actions/cache/save@v3
      with:
        path: "${{ github.workspace }}/.test-results"
        key: "${{ github.job }}-results-${{ github.run_id }}-${{ github.run_attempt }}"