|  | 
| 47 | 47 |     runs-on: ubuntu-latest | 
| 48 | 48 |     outputs: | 
| 49 | 49 |       run_tests: ${{ steps.check.outputs.run_tests }} | 
|  | 50 | +      run_docs: ${{ steps.check.outputs.run_docs }} | 
| 50 | 51 |     steps: | 
| 51 | 52 |       - uses: "actions/checkout@v4" | 
| 52 | 53 |         with: | 
|  | 
| 67 | 68 |         shell: bash | 
| 68 | 69 |         id: check | 
| 69 | 70 |         run: | | 
|  | 71 | +          # We only test docs on the default branch (usually main) | 
|  | 72 | +          if [[ "${{ github.base_ref }}" == *"main" ]]; then | 
|  | 73 | +            echo "run_docs=1" >> $GITHUB_OUTPUT | 
|  | 74 | +          else | 
|  | 75 | +            echo "run_docs=0" >> $GITHUB_OUTPUT | 
|  | 76 | +          fi | 
|  | 77 | +
 | 
| 70 | 78 |           set +e | 
| 71 | 79 |           BASE_REF=${{ github.event.pull_request.base.sha }} | 
| 72 | 80 |           echo "Checking against:" | 
|  | 
| 80 | 88 |           echo "run_tests=$exit_code" >> $GITHUB_OUTPUT | 
| 81 | 89 | 
 | 
| 82 | 90 |   docs: | 
|  | 91 | +    needs: "check-changes" | 
| 83 | 92 |     uses: "./.github/workflows/docs.yml" | 
|  | 93 | +    with: | 
|  | 94 | +      run_docs: ${{ needs.check-changes.outputs.run_docs }} | 
| 84 | 95 | 
 | 
| 85 | 96 |   lint: | 
| 86 | 97 |     needs: | 
| @@ -133,13 +144,30 @@ jobs: | 
| 133 | 144 |       - name: "Collect needed jobs results" | 
| 134 | 145 |         working-directory: "." | 
| 135 | 146 |         run: | | 
| 136 |  | -          if [ ${{ needs.check-changes.outputs.run_tests }} == "1" ]; then | 
| 137 |  | -            # Full test run - check all jobs | 
| 138 |  | -            echo '${{toJson(needs)}}' | jq -r 'to_entries[]|select(.value.result!="success")|.key + ": " + .value.result' | 
| 139 |  | -            echo '${{toJson(needs)}}' | jq -e 'to_entries|map(select(.value.result!="success"))|length == 0' | 
| 140 |  | -          else | 
| 141 |  | -            # Docs-only run - check only required jobs (exclude lint and test) | 
| 142 |  | -            echo '${{toJson(needs)}}' | jq -r 'to_entries[]|select(.key != "lint" and .key != "test")|select(.value.result!="success")|.key + ": " + .value.result' | 
| 143 |  | -            echo '${{toJson(needs)}}' | jq -e 'to_entries|map(select(.key != "lint" and .key != "test"))|map(select(.value.result!="success"))|length == 0' | 
|  | 147 | +          RUN_TESTS=${{ needs.check-changes.outputs.run_tests }} | 
|  | 148 | +          RUN_DOCS=${{ needs.check-changes.outputs.run_docs }} | 
|  | 149 | +
 | 
|  | 150 | +          check_jobs() { | 
|  | 151 | +            local filter="$1" | 
|  | 152 | +            local needs_json='${{toJson(needs)}}' | 
|  | 153 | +            # output failed jobs after filter | 
|  | 154 | +            echo "$needs_json" | jq -r "to_entries[]|select($filter)|select(.value.result!=\"success\")|.key + \": \" + .value.result" | 
|  | 155 | +            # fails if not all selected jobs passed | 
|  | 156 | +            echo "$needs_json" | jq -e "to_entries|map(select($filter))|map(select(.value.result!=\"success\"))|length == 0" | 
|  | 157 | +          } | 
|  | 158 | +
 | 
|  | 159 | +          if [ "$RUN_TESTS" == "1" ] && [ "$RUN_DOCS" == "1" ]; then | 
|  | 160 | +            FILTERS="true"  # check all jobs | 
|  | 161 | +          elif [ "$RUN_TESTS" == "1" ] && [ "$RUN_DOCS" == "0" ]; then | 
|  | 162 | +            echo "Skipping docs: running on non-default branch" | 
|  | 163 | +            FILTERS='.key != "docs"' | 
|  | 164 | +          elif [ "$RUN_TESTS" == "0" ] && [ "$RUN_DOCS" == "1" ]; then | 
|  | 165 | +            echo "Skipping tests: only doc changes" | 
|  | 166 | +            FILTERS='.key != "lint" and .key != "test"' | 
|  | 167 | +          else  # RUN_TESTS=0, RUN_DOCS=0 | 
|  | 168 | +            echo "What is this PR doing??" | 
|  | 169 | +            FILTERS='.key != "lint" and .key != "test" and .key != "docs"' | 
| 144 | 170 |           fi | 
|  | 171 | +
 | 
|  | 172 | +          check_jobs "$FILTERS" | 
| 145 | 173 |           echo "CI says: Looks good!" | 
0 commit comments