github.com/canonical/ubuntu-image@v0.0.0-20240430122802-2202fe98b290/tests/lib/external/snapd-testing-tools/.github/workflows/tests.yaml (about) 1 name: Jobs 2 on: 3 pull_request: 4 branches: 5 - main 6 push: 7 branches: 8 - main 9 10 jobs: 11 unit-tests: 12 runs-on: ubuntu-20.04 13 steps: 14 - name: Checkout code 15 uses: actions/checkout@v2 16 17 - name: Run shellCheck for tools 18 run: | 19 # Run shellcheck from the snap which most likely is newer than what the distro provides 20 sudo apt-get remove --purge shellcheck 21 sudo snap install shellcheck 22 find tools utils remote -type f -exec sh -c "head -n 1 {} | egrep -a 'bin/bash|bin/sh' >/dev/null" \; -print -exec shellcheck {} \; 23 24 # Run shellcheck from the distro 25 sudo snap remove shellcheck 26 sudo apt-get install -y shellcheck 27 find tools utils remote -type f -exec sh -c "head -n 1 {} | egrep -a 'bin/bash|bin/sh' >/dev/null" \; -print -exec shellcheck {} \; 28 29 - name: Run codespell tool 30 run: | 31 sudo apt install python3-pip 32 pip3 install codespell 33 codespell 34 35 test: 36 needs: [unit-tests] 37 runs-on: self-hosted 38 steps: 39 - name: Checkout code 40 uses: actions/checkout@v2 41 42 - name: Get previous attempt 43 id: get-previous-attempt 44 run: | 45 echo "previous_attempt=$(( ${{ github.run_attempt }} - 1 ))" >> $GITHUB_OUTPUT 46 shell: bash 47 48 - name: Get previous cache 49 uses: actions/cache@v3 50 with: 51 path: "${{ github.workspace }}/.test-results" 52 key: "${{ github.job }}-results-${{ github.run_id }}-${{ steps.get-previous-attempt.outputs.previous_attempt }}" 53 54 - name: Prepare test results env and vars 55 id: prepare-test-results-env 56 run: | 57 # Create test results directories and save vars 58 TEST_RESULTS_DIR="${{ github.workspace }}/.test-results" 59 echo "TEST_RESULTS_DIR=$TEST_RESULTS_DIR" >> $GITHUB_ENV 60 61 # Save the var with the failed tests file 62 echo "FAILED_TESTS_FILE=$TEST_RESULTS_DIR/failed-tests" >> $GITHUB_ENV 63 64 # Make sure the test results dirs are created 65 # This step has to be after the cache is restored 66 mkdir -p "$TEST_RESULTS_DIR" 67 68 - name: Check failed tests to run 69 if: "!contains(github.event.pull_request.labels.*.name, 'Run all')" 70 run: | 71 # Save previous failed test results in FAILED_TESTS env var 72 FAILED_TESTS="" 73 if [ -f "$FAILED_TESTS_FILE" ]; then 74 echo "Failed tests file found" 75 FAILED_TESTS="$(cat $FAILED_TESTS_FILE)" 76 if [ -n "$FAILED_TESTS" ]; then 77 echo "Failed tests to run: $FAILED_TESTS" 78 echo "FAILED_TESTS=$FAILED_TESTS" >> $GITHUB_ENV 79 fi 80 fi 81 82 - name: Run test 83 run: | 84 RUN_TESTS="google:tests/ google-nested:tests/" 85 if [ -n "$FAILED_TESTS" ]; then 86 RUN_TESTS="$FAILED_TESTS" 87 fi 88 89 (set -o pipefail; spread $RUN_TESTS | tee spread.log) 90 91 - name: Discard spread workers 92 if: always() 93 run: | 94 shopt -s nullglob; 95 for r in .spread-reuse.*.yaml; do 96 spread -discard -reuse-pid="$(echo "$r" | grep -o -E '[0-9]+')"; 97 done 98 99 - name: analyze spread test results 100 if: always() 101 run: | 102 if [ -f spread.log ]; then 103 echo "Running spread log parser" 104 ./utils/log-parser spread.log --output spread-results.json 105 106 echo "Determining which tests were executed" 107 RUN_TESTS="google:tests/ google-nested:tests/" 108 if [ -n "$FAILED_TESTS" ]; then 109 RUN_TESTS="$FAILED_TESTS" 110 fi 111 112 echo "Running spread log analyzer" 113 ./utils/log-analyzer list-reexecute-tasks "$RUN_TESTS" spread-results.json > "$FAILED_TESTS_FILE" 114 else 115 echo "No spread log found, saving empty list of failed tests" 116 touch "$FAILED_TESTS_FILE" 117 fi 118 119 - name: save spread test results to cache 120 if: always() 121 uses: actions/cache/save@v3 122 with: 123 path: "${{ github.workspace }}/.test-results" 124 key: "${{ github.job }}-results-${{ github.run_id }}-${{ github.run_attempt }}"