microsoft/qdk
Publicmirrored fromhttps://github.com/microsoft/qdkAvailable
.github/workflows/ci.yml
231lines · modecode
| 1 | name: CI Build and Test |
| 2 | |
| 3 | on: |
| 4 | pull_request: |
| 5 | branches: |
| 6 | - main |
| 7 | - 'feature/**' |
| 8 | - 'release/**' |
| 9 | merge_group: |
| 10 | workflow_dispatch: |
| 11 | |
| 12 | # Cancel in-progress run when a pull request is updated |
| 13 | # Code taken from: |
| 14 | # https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#example-using-a-fallback-value |
| 15 | concurrency: |
| 16 | group: ${{ github.head_ref || github.run_id }} |
| 17 | cancel-in-progress: true |
| 18 | |
| 19 | env: |
| 20 | CARGO_TERM_COLOR: always |
| 21 | NODE_VERSION: "18.17.1" |
| 22 | PYTHON_VERSION: "3.11" |
| 23 | RUST_TOOLCHAIN_VERSION: "1.78" |
| 24 | RUST_TOOLCHAIN_COMPONENTS: rustfmt clippy |
| 25 | |
| 26 | jobs: |
| 27 | format: |
| 28 | name: Format |
| 29 | runs-on: ubuntu-latest |
| 30 | steps: |
| 31 | - uses: actions/checkout@v3 |
| 32 | with: |
| 33 | submodules: "true" |
| 34 | - name: Setup rust toolchain |
| 35 | uses: ./.github/actions/toolchains/rust |
| 36 | with: |
| 37 | toolchain: ${{ env.RUST_TOOLCHAIN_VERSION }} |
| 38 | components: ${{ env.RUST_TOOLCHAIN_COMPONENTS }} |
| 39 | - name: Check Formatting |
| 40 | run: cargo fmt --all -- --check |
| 41 | |
| 42 | clippy: |
| 43 | name: Clippy |
| 44 | runs-on: ubuntu-latest |
| 45 | steps: |
| 46 | - uses: actions/checkout@v3 |
| 47 | with: |
| 48 | submodules: "true" |
| 49 | - name: Setup rust toolchain |
| 50 | uses: ./.github/actions/toolchains/rust |
| 51 | with: |
| 52 | toolchain: ${{ env.RUST_TOOLCHAIN_VERSION }} |
| 53 | components: ${{ env.RUST_TOOLCHAIN_COMPONENTS }} |
| 54 | - uses: Swatinem/rust-cache@v2 |
| 55 | - name: Clippy Lints |
| 56 | run: cargo clippy --all-targets --all-features -- -D warnings |
| 57 | |
| 58 | format-qsc: |
| 59 | name: Format Q# Files |
| 60 | runs-on: ubuntu-latest |
| 61 | steps: |
| 62 | - uses: actions/checkout@v3 |
| 63 | with: |
| 64 | submodules: "true" |
| 65 | - name: Setup rust toolchain |
| 66 | uses: ./.github/actions/toolchains/rust |
| 67 | with: |
| 68 | toolchain: ${{ env.RUST_TOOLCHAIN_VERSION }} |
| 69 | components: ${{ env.RUST_TOOLCHAIN_COMPONENTS }} |
| 70 | - name: Check Formatting for Libraries and Samples |
| 71 | run: cargo run --release --bin qsc_formatter -- ./library/ ./samples/ -r |
| 72 | |
| 73 | web-check: |
| 74 | name: Check web files |
| 75 | runs-on: ubuntu-latest |
| 76 | steps: |
| 77 | - uses: actions/checkout@v3 |
| 78 | with: |
| 79 | submodules: "true" |
| 80 | - uses: actions/setup-node@v3 |
| 81 | with: |
| 82 | node-version: ${{ env.NODE_VERSION }} |
| 83 | - name: npm install |
| 84 | run: npm install |
| 85 | - name: npm check |
| 86 | run: npm run check |
| 87 | |
| 88 | build: |
| 89 | name: Build and test |
| 90 | strategy: |
| 91 | matrix: |
| 92 | os: [windows-latest, ubuntu-latest, macos-14] |
| 93 | |
| 94 | runs-on: ${{matrix.os}} |
| 95 | |
| 96 | steps: |
| 97 | - uses: actions/checkout@v3 |
| 98 | with: |
| 99 | submodules: "true" |
| 100 | - name: Setup rust toolchain |
| 101 | uses: ./.github/actions/toolchains/rust |
| 102 | with: |
| 103 | toolchain: ${{ env.RUST_TOOLCHAIN_VERSION }} |
| 104 | components: ${{ env.RUST_TOOLCHAIN_COMPONENTS }} |
| 105 | - name: Add additional Rust targets |
| 106 | run: | |
| 107 | rustup target add x86_64-apple-darwin |
| 108 | if: matrix.os == 'macos-14' |
| 109 | - uses: actions/setup-python@v4 |
| 110 | with: |
| 111 | python-version: ${{ env.PYTHON_VERSION }} |
| 112 | - uses: actions/setup-node@v3 |
| 113 | with: |
| 114 | node-version: ${{ env.NODE_VERSION }} |
| 115 | - uses: Swatinem/rust-cache@v2 |
| 116 | - name: Prereqs |
| 117 | run: python ./prereqs.py --install |
| 118 | - name: Build and Test |
| 119 | run: python ./build.py --no-check |
| 120 | |
| 121 | integration-tests: |
| 122 | name: Integration tests |
| 123 | timeout-minutes: 15 |
| 124 | strategy: |
| 125 | matrix: |
| 126 | os: [windows-latest, ubuntu-latest, macos-14] |
| 127 | |
| 128 | runs-on: ${{matrix.os}} |
| 129 | |
| 130 | steps: |
| 131 | - uses: actions/checkout@v3 |
| 132 | with: |
| 133 | submodules: "true" |
| 134 | - name: Setup rust toolchain |
| 135 | uses: ./.github/actions/toolchains/rust |
| 136 | with: |
| 137 | toolchain: ${{ env.RUST_TOOLCHAIN_VERSION }} |
| 138 | components: ${{ env.RUST_TOOLCHAIN_COMPONENTS }} |
| 139 | - name: Add additional Rust targets |
| 140 | run: | |
| 141 | rustup target add x86_64-apple-darwin |
| 142 | if: matrix.os == 'macos-14' |
| 143 | - uses: actions/setup-python@v4 |
| 144 | with: |
| 145 | python-version: ${{ env.PYTHON_VERSION }} |
| 146 | - uses: actions/setup-node@v3 |
| 147 | with: |
| 148 | node-version: ${{ env.NODE_VERSION }} |
| 149 | - uses: Swatinem/rust-cache@v2 |
| 150 | - name: Prereqs |
| 151 | run: python ./prereqs.py --install |
| 152 | - name: Run integration tests |
| 153 | run: python ./build.py --no-check --no-test --wasm --npm --vscode --pip --widgets --integration-tests |
| 154 | |
| 155 | runBenchmark: |
| 156 | name: run benchmark |
| 157 | runs-on: ubuntu-latest |
| 158 | permissions: |
| 159 | contents: read |
| 160 | pull-requests: write |
| 161 | steps: |
| 162 | - uses: actions/checkout@v3 |
| 163 | - uses: boa-dev/criterion-compare-action@v3 |
| 164 | with: |
| 165 | branchName: ${{ github.base_ref }} |
| 166 | cwd: "compiler/qsc" |
| 167 | if: ${{ github.base_ref != null }} |
| 168 | |
| 169 | runMemoryProfile: |
| 170 | name: run memory profile |
| 171 | runs-on: ubuntu-latest |
| 172 | permissions: |
| 173 | contents: read |
| 174 | pull-requests: write |
| 175 | steps: |
| 176 | - uses: actions/checkout@v2 |
| 177 | with: |
| 178 | ref: main |
| 179 | - uses: Swatinem/rust-cache@v2 |
| 180 | - run: | |
| 181 | MAIN_MEASUREMENT=$(cargo run --bin memtest) |
| 182 | echo "MAIN_MEASUREMENT<<EOF" >> $GITHUB_ENV |
| 183 | echo "$MAIN_MEASUREMENT" >> $GITHUB_ENV |
| 184 | echo "EOF" >> $GITHUB_ENV |
| 185 | - run: | |
| 186 | echo "${{env.MAIN_MEASUREMENT}}" |
| 187 | echo $MAIN_MEASUREMENT |
| 188 | |
| 189 | - uses: actions/checkout@v2 |
| 190 | - run: | |
| 191 | BRANCH_MEASUREMENT=$(cargo run --bin memtest) |
| 192 | echo "BRANCH_MEASUREMENT<<EOF" >> $GITHUB_ENV |
| 193 | echo "$BRANCH_MEASUREMENT" >> $GITHUB_ENV |
| 194 | echo "EOF" >> $GITHUB_ENV |
| 195 | - run: | |
| 196 | echo "${{env.BRANCH_MEASUREMENT}}" |
| 197 | echo $BRANCH_MEASUREMENT |
| 198 | - uses: actions/github-script@v6 |
| 199 | with: |
| 200 | script: | |
| 201 | if (${{ env.BRANCH_MEASUREMENT }} !== ${{ env.MAIN_MEASUREMENT }}) { |
| 202 | const difference = ${{ env.BRANCH_MEASUREMENT }} - ${{ env.MAIN_MEASUREMENT }}; |
| 203 | try { |
| 204 | await github.rest.issues.createComment({ |
| 205 | issue_number: context.issue.number, |
| 206 | owner: context.repo.owner, |
| 207 | repo: context.repo.repo, |
| 208 | body: `_Change in memory usage detected by benchmark._ |
| 209 | ## Memory Report for ${{ github.sha }} |
| 210 | |
| 211 | | Test | This Branch | On Main | Difference | |
| 212 | |-----------------------------|-------------|----------| ---------- | |
| 213 | | compile core + standard lib | ${{ env.BRANCH_MEASUREMENT }} bytes | ${{ env.MAIN_MEASUREMENT }} bytes | ${difference} bytes` |
| 214 | }) |
| 215 | } catch (err) { |
| 216 | core.warning(`Failed writing comment on GitHub issue: ${err}`) |
| 217 | } |
| 218 | } else { |
| 219 | console.log("no change in memory usage detected by benchmark"); |
| 220 | } |
| 221 | if: ${{ github.base_ref != null }} |
| 222 | |
| 223 | status-check: |
| 224 | name: Status Check |
| 225 | needs: [format, clippy, web-check, build, format-qsc, integration-tests, runBenchmark, runMemoryProfile] |
| 226 | runs-on: ubuntu-latest |
| 227 | if: failure() |
| 228 | steps: |
| 229 | - run: | |
| 230 | echo "::error Build failed" |
| 231 | exit 1 |