|
| 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 | + version: |
| 29 | + description: "Release version" |
| 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 | + - uses: actions/cache@v4 |
| 39 | + with: |
| 40 | + path: | |
| 41 | + ~/.cache/bazelisk |
| 42 | + ~/.cache/bazel |
| 43 | + key: bazel-${{ hashFiles('common.bazelrc', '.bazelrc', '.bazelversion', 'WORKSPACE', 'MODULE.bazel', 'requirements.txt') }} |
| 44 | + restore-keys: bazel- |
| 45 | + - run: bazelisk test //... |
| 46 | + |
| 47 | + build-and-upload-tools: |
| 48 | + needs: [build-and-test] |
| 49 | + strategy: |
| 50 | + matrix: |
| 51 | + os: [linux, windows, darwin] |
| 52 | + arch: [amd64, arm64] |
| 53 | + |
| 54 | + runs-on: ubuntu-latest |
| 55 | + steps: |
| 56 | + - uses: actions/checkout@v4 |
| 57 | + - uses: actions/cache@v4 |
| 58 | + with: |
| 59 | + path: | |
| 60 | + ~/.cache/bazelisk |
| 61 | + ~/.cache/bazel |
| 62 | + key: bazel-${{ hashFiles('common.bazelrc', '.bazelrc', '.bazelversion', 'WORKSPACE', 'MODULE.bazel', 'requirements.txt') }} |
| 63 | + restore-keys: bazel- |
| 64 | + - run: bazel/tools/update_version_bzl.sh version.bzl |
| 65 | + - run: bazelisk build --stamp "--platforms=@rules_go//go/toolchain:${{ matrix.os }}_${{ matrix.arch }}" //agent/cmd/agent //tools/nbictl/cmd/nbictl |
| 66 | + |
| 67 | + - name: Package binary |
| 68 | + if: ${{ matrix.os != 'windows' }} |
| 69 | + run: | |
| 70 | + zip -j nbictl-${{ matrix.os }}-${{ matrix.arch }}.zip bazel-bin/tools/nbictl/cmd/nbictl/nbictl_/nbictl |
| 71 | + zip -j agent-${{ matrix.os }}-${{ matrix.arch }}.zip bazel-bin/agent/cmd/agent/agent_/agent |
| 72 | +
|
| 73 | + - name: Package binary - Windows |
| 74 | + if: ${{ matrix.os == 'windows' }} |
| 75 | + run: | |
| 76 | + zip -j nbictl-${{ matrix.os }}-${{ matrix.arch }}.zip bazel-bin/tools/nbictl/cmd/nbictl/nbictl_/nbictl.exe |
| 77 | + zip -j agent-${{ matrix.os }}-${{ matrix.arch }}.zip bazel-bin/agent/cmd/agent/agent_/agent.exe |
| 78 | +
|
| 79 | + - name: Upload binary |
| 80 | + uses: actions/upload-artifact@v4 |
| 81 | + with: |
| 82 | + name: tools-${{ matrix.os }}-${{ matrix.arch }} |
| 83 | + path: "*.zip" |
| 84 | + |
| 85 | + build-and-upload-docs: |
| 86 | + needs: [build-and-test] |
| 87 | + runs-on: ubuntu-latest |
| 88 | + steps: |
| 89 | + - uses: actions/checkout@v4 |
| 90 | + - uses: actions/cache@v4 |
| 91 | + with: |
| 92 | + path: | |
| 93 | + ~/.cache/bazelisk |
| 94 | + ~/.cache/bazel |
| 95 | + key: bazel-${{ hashFiles('common.bazelrc', '.bazelrc', '.bazelversion', 'WORKSPACE', 'MODULE.bazel', 'requirements.txt') }} |
| 96 | + restore-keys: bazel- |
| 97 | + - run: bazelisk build "//api:api.html" |
| 98 | + - name: Upload API docs |
| 99 | + uses: actions/upload-artifact@v4 |
| 100 | + with: |
| 101 | + name: api.html |
| 102 | + path: | |
| 103 | + bazel-bin/api/api.html/api.html |
| 104 | +
|
| 105 | + create-release: |
| 106 | + needs: [build-and-upload-tools] |
| 107 | + runs-on: ubuntu-latest |
| 108 | + if: | |
| 109 | + github.event_name == 'workflow_dispatch' && |
| 110 | + inputs.create_release == true && |
| 111 | + inputs.version != '' |
| 112 | +
|
| 113 | + steps: |
| 114 | + - uses: actions/checkout@v4 |
| 115 | + |
| 116 | + - name: Download all artifacts |
| 117 | + uses: actions/download-artifact@v4 |
| 118 | + with: |
| 119 | + pattern: tools-* |
| 120 | + |
| 121 | + - name: Create Release |
| 122 | + uses: softprops/action-gh-release@v2 |
| 123 | + with: |
| 124 | + tag_name: ${{ inputs.version }} |
| 125 | + name: Release ${{ inputs.version }} |
| 126 | + # TODO: Change to non-draft after testing. |
| 127 | + draft: true |
| 128 | + files: | |
| 129 | + tools-*/*.zip |
| 130 | + generate_release_notes: true |
0 commit comments