|
| 1 | +# Copyright 2023 Aalyria Technologies, Inc., and its affiliates. |
| 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 | +# http://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: Bazel |
| 16 | + |
| 17 | +on: |
| 18 | + pull_request: {} |
| 19 | + push: {} |
| 20 | + release: |
| 21 | + types: [published] |
| 22 | + workflow_dispatch: |
| 23 | + inputs: |
| 24 | + create_release: |
| 25 | + description: "Create GitHub release" |
| 26 | + type: boolean |
| 27 | + default: false |
| 28 | + ref: |
| 29 | + description: "Release version ref" |
| 30 | + required: false |
| 31 | + type: string |
| 32 | + |
| 33 | +jobs: |
| 34 | + build-and-test: |
| 35 | + runs-on: ubuntu-22.04 |
| 36 | + steps: |
| 37 | + - uses: actions/checkout@v4 |
| 38 | + with: |
| 39 | + ref: ${{ github.event.inputs.ref || github.ref }} |
| 40 | + - uses: actions/cache@v4 |
| 41 | + with: |
| 42 | + path: | |
| 43 | + ~/.cache/bazelisk |
| 44 | + ~/.cache/bazel |
| 45 | + key: bazel-${{ hashFiles('common.bazelrc', '.bazelrc', '.bazelversion', 'WORKSPACE', 'MODULE.bazel', 'requirements.txt') }} |
| 46 | + restore-keys: bazel- |
| 47 | + - run: bazelisk test //... |
| 48 | + |
| 49 | + build-and-upload-tools: |
| 50 | + needs: [build-and-test] |
| 51 | + strategy: |
| 52 | + matrix: |
| 53 | + os: [linux, windows, darwin] |
| 54 | + arch: [amd64, arm64] |
| 55 | + |
| 56 | + runs-on: ubuntu-latest |
| 57 | + steps: |
| 58 | + - uses: actions/checkout@v4 |
| 59 | + with: |
| 60 | + ref: ${{ github.event.inputs.ref || github.ref }} |
| 61 | + - uses: actions/cache@v4 |
| 62 | + with: |
| 63 | + path: | |
| 64 | + ~/.cache/bazelisk |
| 65 | + ~/.cache/bazel |
| 66 | + key: bazel-${{ hashFiles('common.bazelrc', '.bazelrc', '.bazelversion', 'WORKSPACE', 'MODULE.bazel', 'requirements.txt') }} |
| 67 | + restore-keys: bazel- |
| 68 | + - run: bazel/tools/update_version_bzl.sh version.bzl |
| 69 | + |
| 70 | + - name: Build artifacts |
| 71 | + if: ${{ matrix.os != 'windows' }} |
| 72 | + run: | |
| 73 | + bazelisk build --stamp "--platforms=@rules_go//go/toolchain:${{ matrix.os }}_${{ matrix.arch }}" //tools/nbictl/cmd/nbictl |
| 74 | + zip -j nbictl-${{ matrix.os }}-${{ matrix.arch }}.zip bazel-bin/tools/nbictl/cmd/nbictl/nbictl_/nbictl |
| 75 | + bazelisk build --stamp "--platforms=@rules_go//go/toolchain:${{ matrix.os }}_${{ matrix.arch }}" //agent/cmd/agent |
| 76 | + zip -j agent-${{ matrix.os }}-${{ matrix.arch }}.zip bazel-bin/agent/cmd/agent/agent_/agent |
| 77 | +
|
| 78 | + - name: Build artifacts - Windows |
| 79 | + if: ${{ matrix.os == 'windows' }} |
| 80 | + run: | |
| 81 | + bazelisk build --stamp "--platforms=@rules_go//go/toolchain:${{ matrix.os }}_${{ matrix.arch }}" //tools/nbictl/cmd/nbictl |
| 82 | + zip -j nbictl-${{ matrix.os }}-${{ matrix.arch }}.zip bazel-bin/tools/nbictl/cmd/nbictl/nbictl_/nbictl.exe |
| 83 | + bazelisk build --stamp "--platforms=@rules_go//go/toolchain:${{ matrix.os }}_${{ matrix.arch }}" //agent/cmd/agent |
| 84 | + zip -j agent-${{ matrix.os }}-${{ matrix.arch }}.zip bazel-bin/agent/cmd/agent/agent_/agent.exe |
| 85 | +
|
| 86 | + - name: Upload binary |
| 87 | + uses: actions/upload-artifact@v4 |
| 88 | + with: |
| 89 | + name: tools-${{ matrix.os }}-${{ matrix.arch }} |
| 90 | + path: "*.zip" |
| 91 | + |
| 92 | + build-and-upload-docs: |
| 93 | + needs: [build-and-test] |
| 94 | + runs-on: ubuntu-latest |
| 95 | + steps: |
| 96 | + - uses: actions/checkout@v4 |
| 97 | + with: |
| 98 | + ref: ${{ github.event.inputs.ref || github.ref }} |
| 99 | + - uses: actions/cache@v4 |
| 100 | + with: |
| 101 | + path: | |
| 102 | + ~/.cache/bazelisk |
| 103 | + ~/.cache/bazel |
| 104 | + key: bazel-${{ hashFiles('common.bazelrc', '.bazelrc', '.bazelversion', 'WORKSPACE', 'MODULE.bazel', 'requirements.txt') }} |
| 105 | + restore-keys: bazel- |
| 106 | + - run: bazelisk build "//api:api.html" |
| 107 | + - name: Upload API docs |
| 108 | + uses: actions/upload-artifact@v4 |
| 109 | + with: |
| 110 | + name: api.html |
| 111 | + path: | |
| 112 | + bazel-bin/api/api.html/api.html |
| 113 | +
|
| 114 | + create-release: |
| 115 | + needs: [build-and-upload-tools] |
| 116 | + runs-on: ubuntu-latest |
| 117 | + if: | |
| 118 | + startsWith( github.ref, 'refs/heads/release-' ) || |
| 119 | + (github.event_name == 'workflow_dispatch' && inputs.create_release == true && inputs.ref != '') |
| 120 | + steps: |
| 121 | + - uses: actions/checkout@v4 |
| 122 | + with: |
| 123 | + ref: ${{ github.event.inputs.ref || github.ref }} |
| 124 | + - name: Download all artifacts |
| 125 | + uses: actions/download-artifact@v4 |
| 126 | + with: |
| 127 | + pattern: tools-* |
| 128 | + |
| 129 | + - run: bazel/tools/update_version_bzl.sh version.bzl |
| 130 | + - name: Read version |
| 131 | + id: version |
| 132 | + run: echo "value=$(bazelisk run //:version)" >> $GITHUB_OUTPUT |
| 133 | + - name: Create Release |
| 134 | + uses: softprops/action-gh-release@v2 |
| 135 | + with: |
| 136 | + tag_name: v${{ steps.version.outputs.value }} |
| 137 | + name: Release v${{ steps.version.outputs.value }} |
| 138 | + target_commitish: ${{ github.event.inputs.ref || github.ref }} |
| 139 | + make_latest: legacy # determined based on the release creation date and higher semantic version |
| 140 | + draft: false |
| 141 | + files: | |
| 142 | + tools-*/*.zip |
| 143 | + generate_release_notes: true |
0 commit comments