|
| 1 | +# Copyright 2025 Google LLC |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +name: 'CI: build & test library and apps' |
| 16 | +run-name: Build the library on different platforms and run tests |
| 17 | + |
| 18 | +on: |
| 19 | + push: |
| 20 | + branches: |
| 21 | + - master |
| 22 | + - main |
| 23 | + |
| 24 | + pull_request: |
| 25 | + types: [opened, synchronize] |
| 26 | + |
| 27 | + merge_group: |
| 28 | + types: |
| 29 | + - checks_requested |
| 30 | + |
| 31 | + workflow_dispatch: |
| 32 | + inputs: |
| 33 | + debug: |
| 34 | + description: 'Run with debugging options' |
| 35 | + type: boolean |
| 36 | + default: true |
| 37 | + |
| 38 | +permissions: read-all |
| 39 | + |
| 40 | +concurrency: |
| 41 | + # Cancel any previously-started but still active runs on the same branch. |
| 42 | + cancel-in-progress: true |
| 43 | + group: ${{github.workflow}}-${{github.event.pull_request.number||github.ref}} |
| 44 | + |
| 45 | +jobs: |
| 46 | + find-changes: |
| 47 | + name: Find changed files |
| 48 | + uses: ./.github/workflows/reusable_find_changes.yaml |
| 49 | + secrets: inherit |
| 50 | + |
| 51 | + build-wheels: |
| 52 | + # For efficiency, skip this workflow if there were no code file changes. |
| 53 | + if: needs.find-changes.outputs.code || github.event_name == 'workflow_dispatch' |
| 54 | + name: ${{matrix.conf.os}}/${{matrix.conf.pyarch}}/py3${{matrix.conf.py}} |
| 55 | + needs: find-changes |
| 56 | + runs-on: ${{matrix.conf.os}} |
| 57 | + timeout-minutes: 30 |
| 58 | + strategy: |
| 59 | + fail-fast: false |
| 60 | + matrix: |
| 61 | + conf: [ |
| 62 | + {os: ubuntu-24.04, pyarch: x64, py: 10}, |
| 63 | + {os: ubuntu-24.04, pyarch: x64, py: 11}, |
| 64 | + {os: ubuntu-24.04, pyarch: x64, py: 12}, |
| 65 | + {os: ubuntu-24.04, pyarch: x64, py: 13}, |
| 66 | + |
| 67 | + {os: macos-13, pyarch: x64, py: 10}, |
| 68 | + {os: macos-13, pyarch: x64, py: 11}, |
| 69 | + {os: macos-13, pyarch: x64, py: 12}, |
| 70 | + {os: macos-13, pyarch: x64, py: 13}, |
| 71 | + |
| 72 | + {os: macos-14, pyarch: arm64, py: 10}, |
| 73 | + {os: macos-14, pyarch: arm64, py: 11}, |
| 74 | + {os: macos-14, pyarch: arm64, py: 12}, |
| 75 | + {os: macos-14, pyarch: arm64, py: 13}, |
| 76 | + |
| 77 | + {os: macos-15, pyarch: arm64, py: 10}, |
| 78 | + {os: macos-15, pyarch: arm64, py: 11}, |
| 79 | + {os: macos-15, pyarch: arm64, py: 12}, |
| 80 | + {os: macos-15, pyarch: arm64, py: 13}, |
| 81 | + |
| 82 | + {os: windows-2022, pyarch: x64, py: 10}, |
| 83 | + {os: windows-2022, pyarch: x64, py: 11}, |
| 84 | + {os: windows-2022, pyarch: x64, py: 12}, |
| 85 | + {os: windows-2022, pyarch: x64, py: 13}, |
| 86 | + ] |
| 87 | + steps: |
| 88 | + - name: Check out a copy of the git repository |
| 89 | + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 |
| 90 | + with: |
| 91 | + fetch-depth: 1 |
| 92 | + submodules: recursive |
| 93 | + |
| 94 | + - name: Set up Python with caching of pip dependencies |
| 95 | + uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5 |
| 96 | + id: setup |
| 97 | + with: |
| 98 | + python-version: '3.${{matrix.conf.py}}' |
| 99 | + architecture: ${{matrix.conf.pyarch}} |
| 100 | + cache: pip |
| 101 | + cache-dependency-path: | |
| 102 | + requirements.txt |
| 103 | + dev-requirements.txt |
| 104 | +
|
| 105 | + - name: Set up Bazel with caching |
| 106 | + uses: bazel-contrib/setup-bazel@8d2cb86a3680a820c3e219597279ce3f80d17a47 # 0.15.0 |
| 107 | + with: |
| 108 | + disk-cache: ${{github.workflow}} |
| 109 | + bazelisk-cache: true |
| 110 | + external-cache: true |
| 111 | + repository-cache: true |
| 112 | + |
| 113 | + - name: Install qsim development dependencies |
| 114 | + run: | |
| 115 | + pip install -r requirements.txt |
| 116 | + pip install -r dev-requirements.txt |
| 117 | +
|
| 118 | + - if: matrix.conf.os != 'windows-2022' |
| 119 | + name: Run the build and test script (non-Windows case) |
| 120 | + env: |
| 121 | + # SHELLOPTS is used by Bash. Add xtrace when doing manual debug runs. |
| 122 | + SHELLOPTS: ${{inputs.debug && 'xtrace' || '' }} |
| 123 | + run: dev_tools/test_libs.sh --config=verbose |
| 124 | + |
| 125 | + - if: matrix.conf.os == 'windows-2022' |
| 126 | + name: Run the build and test script (Windows case) |
| 127 | + # On GitHub Windows runners, Bazel ends up finding a different |
| 128 | + # "python3" binary than what's installed by setup-python unless we tell |
| 129 | + # Bazel what to use. Here we do that by setting PYTHON_BIN_PATH. |
| 130 | + env: |
| 131 | + pyroot: 'C:\\hostedtoolcache\\windows\\Python' |
| 132 | + pyexe: '${{steps.setup.outputs.python-version}}\\${{matrix.conf.pyarch}}\\python3.exe' |
| 133 | + SHELLOPTS: ${{inputs.debug && 'xtrace' || '' }} |
| 134 | + shell: cmd |
| 135 | + run: >- |
| 136 | + bash -x dev_tools/test_libs.sh --config=verbose |
| 137 | + --action_env PYTHON_BIN_PATH=${{env.pyroot}}\\${{env.pyexe}} |
0 commit comments