|
| 1 | +name: main |
| 2 | + |
| 3 | +concurrency: |
| 4 | + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} |
| 5 | + cancel-in-progress: true |
| 6 | + |
| 7 | +on: |
| 8 | + pull_request: |
| 9 | + workflow_dispatch: |
| 10 | + inputs: |
| 11 | + test_targets: |
| 12 | + default: "" |
| 13 | + description: "Comma separated list to run pytest on, e.g.: `lib/dl_api_lib,lib/dl_core`. " |
| 14 | + run_mypy_only: |
| 15 | + type: boolean |
| 16 | + default: false |
| 17 | + description: "Check to only run mypy" |
| 18 | + pytest_timeout_minutes: |
| 19 | + type: number |
| 20 | + default: 10 |
| 21 | + description: "Timeout for pytest JOB in minutes" |
| 22 | + |
| 23 | +jobs: |
| 24 | + gh_build_image: |
| 25 | + runs-on: [ self-hosted, linux ] |
| 26 | + permissions: |
| 27 | + packages: write |
| 28 | + contents: read |
| 29 | + container: |
| 30 | + image: "ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}/debian_docker:latest" |
| 31 | + options: -v /var/run/docker.sock:/var/run/docker.sock |
| 32 | + credentials: |
| 33 | + username: ${{ github.actor }} |
| 34 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 35 | + env: |
| 36 | + REPO_OWNER: ${{ github.repository_owner }} |
| 37 | + REPO_NAME: ${{ github.event.repository.name }} |
| 38 | + GIT_SHA: "${{ github.sha }}" |
| 39 | + steps: |
| 40 | + - name: Log in to the Container registry |
| 41 | + uses: docker/login-action@v2 |
| 42 | + with: |
| 43 | + registry: "ghcr.io" |
| 44 | + username: ${{ github.actor }} |
| 45 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 46 | + - name: 'Cleanup build folder' |
| 47 | + run: | |
| 48 | + rm -rf ./* || true |
| 49 | + rm -rf ./.??* || true |
| 50 | + - name: Checkout code |
| 51 | + uses: actions/checkout@v4 |
| 52 | + - run: git config --global --add safe.directory /__w/${{ github.event.repository.name }}/${{ github.event.repository.name }} |
| 53 | + - run: | |
| 54 | + export ROOT_DIR="$(realpath .)" |
| 55 | + /bin/bash ci/build_naive.sh |
| 56 | +
|
| 57 | + router: |
| 58 | + runs-on: [self-hosted, linux, light] |
| 59 | + needs: gh_build_image |
| 60 | + container: |
| 61 | + image: "ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}/datalens_ci_with_code:${{ github.sha }}" |
| 62 | + credentials: |
| 63 | + username: ${{ github.actor }} |
| 64 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 65 | + outputs: |
| 66 | + affected: ${{ steps.get_affected.outputs.affected }} |
| 67 | + steps: |
| 68 | + - name: 'Cleanup build folder' |
| 69 | + run: | |
| 70 | + rm -rf ./* || true |
| 71 | + rm -rf ./.??* || true |
| 72 | + - name: Checkout code |
| 73 | + uses: actions/checkout@v4 |
| 74 | + with: |
| 75 | + fetch-depth: 0 |
| 76 | + - run: git config --global --add safe.directory . |
| 77 | + - run: git config --global --add safe.directory /__w/${{ github.event.repository.name }}/${{ github.event.repository.name }} |
| 78 | + - run: git fetch origin main |
| 79 | + - name: Get packages affected by changes in the current commit |
| 80 | + id: get_affected |
| 81 | + run: | |
| 82 | + TARGET_DATA=$(bash /src/ci/gh_list_changes.sh ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }}) |
| 83 | + echo "$TARGET_DATA" > /tmp/targets.json |
| 84 | + cat /tmp/targets.json |
| 85 | + . /venv/bin/activate && detect-affected-packages \ |
| 86 | + --repo=/src \ |
| 87 | + --changes_file="/tmp/targets.json" \ |
| 88 | + --root_pkgs="lib,app,terrarium" \ |
| 89 | + --fallback_pkg="terrarium/bi_ci" | tee -a >> "$GITHUB_OUTPUT" |
| 90 | + env: |
| 91 | + TEST_TARGET_OVERRIDE: ${{ github.event.inputs.test_targets }} |
| 92 | + |
| 93 | + pytest_split: |
| 94 | + runs-on: [ self-hosted, linux ] |
| 95 | + needs: router |
| 96 | + # if: ${{ github.event.inputs.run_mypy_only != 'true' }} |
| 97 | + container: |
| 98 | + image: "ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}/datalens_ci_with_code:${{ github.sha }}" |
| 99 | + credentials: |
| 100 | + username: ${{ github.actor }} |
| 101 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 102 | + outputs: |
| 103 | + split_base: ${{ steps.get_split.outputs.split_base }} |
| 104 | + split_fat: ${{ steps.get_split.outputs.split_fat }} |
| 105 | + steps: |
| 106 | + - name: 'Cleanup build folder' |
| 107 | + run: | |
| 108 | + rm -rf ./* || true |
| 109 | + rm -rf ./.??* || true |
| 110 | + - name: Checkout code |
| 111 | + uses: actions/checkout@v4 |
| 112 | + with: |
| 113 | + fetch-depth: 1 |
| 114 | + - run: git config --global --add safe.directory /__w/${{ github.event.repository.name }}/${{ github.event.repository.name }} |
| 115 | + - name: Run python script to split job for general and fat runners |
| 116 | + id: get_split |
| 117 | + run: | |
| 118 | + . /venv/bin/activate && echo '${{ needs.router.outputs.affected }}' >> /tmp/dl_test_targets.json |
| 119 | + split-pytest-tasks base /src /tmp/dl_test_targets.json | tee -a >> "$GITHUB_OUTPUT" |
| 120 | + split-pytest-tasks fat /src /tmp/dl_test_targets.json | tee -a >> "$GITHUB_OUTPUT" |
| 121 | +
|
| 122 | + run_tests_base: |
| 123 | + runs-on: [ self-hosted, linux, light ] |
| 124 | + name: "🐍[pytest]${{ matrix.value }}" |
| 125 | + needs: pytest_split |
| 126 | + if: ${{ needs.pytest_split.outputs.split_base != '[]' }} |
| 127 | + permissions: |
| 128 | + packages: write |
| 129 | + contents: read |
| 130 | + container: |
| 131 | + image: "ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}/datalens_ci_with_code:${{ github.sha }}" |
| 132 | + options: -v /var/run/docker.sock:/var/run/docker.sock |
| 133 | + credentials: |
| 134 | + username: ${{ github.actor }} |
| 135 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 136 | + volumes: |
| 137 | + - /var/run/docker.sock:/var/run/docker.sock |
| 138 | + strategy: |
| 139 | + fail-fast: false |
| 140 | + matrix: |
| 141 | + value: ${{fromJson(needs.pytest_split.outputs.split_base)}} |
| 142 | + steps: |
| 143 | + - run: echo "Going to run tests for ${{ matrix.value }}" |
| 144 | + - run: mkdir /report |
| 145 | + - run: echo "Running py tests for ${{ matrix.value }}" |
| 146 | + - name: Log in to the Container registry |
| 147 | + uses: docker/login-action@v2 |
| 148 | + with: |
| 149 | + registry: "ghcr.io" |
| 150 | + username: ${{ github.actor }} |
| 151 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 152 | + - run: echo compose_path="/src/$(echo ${{ matrix.value }} | cut -d ":" -f1)/" >> "$GITHUB_ENV" |
| 153 | + - run: cd "${{ env.compose_path }}" && echo compose_prj="$(basename "$PWD")_$(shuf -i 1000000-1000000000 -n 1)" >> "$GITHUB_ENV" |
| 154 | + # We need to set custom compose project name to ensure "unique" container names in the host docker env |
| 155 | + - name: run bash script with all logic for starting compose and running tests |
| 156 | + run: | |
| 157 | + bash /src/ci/execute_test_with_docker_compose.sh "${{ matrix.value }}" "${{ job.container.network }}" "${{ env.compose_prj }}" \ |
| 158 | + WE_ARE_IN_CI=1 |
| 159 | + - name: Stop compose if provided |
| 160 | + # We could not put this into bash script, since job could be cancelled by user request |
| 161 | + if: always() # yes! always |
| 162 | + run: bash /src/ci/stop_compose.sh "${{ matrix.value }}" "${{ job.container.network }}" "${{ env.compose_prj }}" |
| 163 | + - uses: actions/upload-artifact@v3 |
| 164 | + if: "!cancelled()" |
| 165 | + with: |
| 166 | + name: "pytest_reports_${{ env.compose_prj }}" |
| 167 | + path: /report/ |
| 168 | + retention-days: 1 |
| 169 | + |
| 170 | + mypy: |
| 171 | + runs-on: [ self-hosted, linux, light ] |
| 172 | + needs: router |
| 173 | + container: |
| 174 | + # until https://github.com/github/docs/issues/25520 is resolved, using vars |
| 175 | + image: "ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}/datalens_ci_with_code:${{ github.sha }}" |
| 176 | + credentials: |
| 177 | + username: ${{ github.actor }} |
| 178 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 179 | + volumes: |
| 180 | + - /var/run/docker.sock:/var/run/docker.sock |
| 181 | + name: "🐲 mypy" |
| 182 | + timeout-minutes: ${{ inputs.pytest_timeout_minutes && fromJSON(inputs.pytest_timeout_minutes ) || 10 }} |
| 183 | + steps: |
| 184 | + - name: "Cleanup folder" |
| 185 | + run: | |
| 186 | + rm -rf ./* || true |
| 187 | + rm -rf ./.??* || true |
| 188 | + - name: Checkout code, just to get access to .github/execute_mypy... |
| 189 | + uses: actions/checkout@v4 |
| 190 | + with: |
| 191 | + fetch-depth: 1 |
| 192 | + - run: echo '${{ needs.router.outputs.affected }}' >> /tmp/dl_test_targets.json |
| 193 | + - name: run mypy |
| 194 | + run: | |
| 195 | + . /venv/bin/activate |
| 196 | + execute-mypy-multi /src /tmp/dl_test_targets.json |
| 197 | + env: |
| 198 | + PYTHONUNBUFFERED: "1" |
| 199 | + |
| 200 | + publish-result: |
| 201 | + runs-on: [self-hosted, linux ] |
| 202 | + needs: [ "run_tests_base" ] # , "run_tests_fat" ] |
| 203 | + if: "!cancelled() && ${{ github.event.inputs.run_mypy_only != 'true' }}" |
| 204 | + permissions: |
| 205 | + contents: read |
| 206 | + issues: read |
| 207 | + checks: write |
| 208 | + pull-requests: write |
| 209 | + container: docker:latest |
| 210 | + steps: |
| 211 | + - uses: actions/download-artifact@v3 |
| 212 | + with: |
| 213 | + path: ./report/ |
| 214 | + - run: ls -lah ./report |
| 215 | + - name: Publish Test Results |
| 216 | + uses: datalens-tech/publish-unit-test-result-action@55478522536e0c60b0a4ff0c2bb8ab110d7a0f33 |
| 217 | + with: |
| 218 | + files: | |
| 219 | + ./report/**/*.xml |
| 220 | + event_name: ${{ github.event.workflow_run.event }} |
| 221 | + report_individual_runs: "true" |
0 commit comments