|
| 1 | +name: Build Ubuntu |
| 2 | + |
| 3 | +description: | |
| 4 | + This is a reusable workflow to build BlazingMQ on Ubuntu. |
| 5 | + Optionally run unit tests if the target is "all.t". |
| 6 | + Given a ref and a target, this workflow will build the project and will save the build results both as artifact and in cache. |
| 7 | + The cache key is generated based on the ref and the target, and is returned via workflow output. |
| 8 | +
|
| 9 | +on: |
| 10 | + workflow_call: |
| 11 | + inputs: |
| 12 | + ref: |
| 13 | + description: "Branch name, tag, or commit SHA to build" |
| 14 | + required: true |
| 15 | + type: string |
| 16 | + target: |
| 17 | + description: "Build targets, space-delimited" |
| 18 | + required: true |
| 19 | + type: string |
| 20 | + save_build_as_artifacts: |
| 21 | + description: "Whether to save the build as artifacts" |
| 22 | + required: true |
| 23 | + type: boolean |
| 24 | + default: true |
| 25 | + run_unit_tests: |
| 26 | + description: "Whether to run unit tests. Can only be set to true if `all.t` is one of the build targets" |
| 27 | + required: true |
| 28 | + type: boolean |
| 29 | + default: false |
| 30 | + name: |
| 31 | + description: "Name of the workflow run, used for artifacts" |
| 32 | + required: false |
| 33 | + type: string |
| 34 | + default: "build-ubuntu" |
| 35 | + outputs: |
| 36 | + artifact_key: |
| 37 | + description: "GH Actions Cache key associated with the built dependencies" |
| 38 | + value: ${{ jobs.build_ubuntu.outputs.artifact_key }} |
| 39 | + |
| 40 | +jobs: |
| 41 | + get_dependencies: |
| 42 | + name: "Dependencies" |
| 43 | + uses: ./.github/workflows/dependencies.yaml |
| 44 | + |
| 45 | + build_ubuntu: |
| 46 | + name: Build [ubuntu] ${{ inputs.ref }} ${{ inputs.target }} |
| 47 | + runs-on: ubuntu-latest |
| 48 | + needs: get_dependencies |
| 49 | + outputs: |
| 50 | + artifact_key: ${{ steps.get_cache_key.outputs.artifact_key }} |
| 51 | + steps: |
| 52 | + - name: Checkout code |
| 53 | + uses: actions/checkout@v4 |
| 54 | + with: |
| 55 | + ref: ${{ inputs.ref }} |
| 56 | + fetch-depth: 0 |
| 57 | + |
| 58 | + # Since input.ref can be a branch, tag or commit SHA, |
| 59 | + # we need to get the commit SHA to use it in the cache key. |
| 60 | + - name: Generate cache key from commit SHA |
| 61 | + id: get_cache_key |
| 62 | + if: inputs.save_build_as_artifacts == true # Variable type is boolean, thus no quotes |
| 63 | + # When restoring from cache fails, it searches for other keys to fall back to. |
| 64 | + # If the given key is a prefix of another key, it will be used. |
| 65 | + # E.g. "...-all" can fallback to "...-all.t" |
| 66 | + # Thus do not put the target at the end of the key. |
| 67 | + run: | |
| 68 | + COMMIT_SHA=$(git rev-parse HEAD) |
| 69 | + echo "cache_key=cache-${{ inputs.target }}-${COMMIT_SHA}" >> $GITHUB_OUTPUT |
| 70 | + echo "artifact_key=${{ inputs.name }}-${{ inputs.target }}-${COMMIT_SHA}" >> $GITHUB_OUTPUT |
| 71 | + - uses: actions/cache/restore@v4 |
| 72 | + id: build-cache-restore-step |
| 73 | + if: inputs.save_build_as_artifacts == true # Variable type is boolean, thus no quotes |
| 74 | + with: |
| 75 | + path: | |
| 76 | + build/blazingmq |
| 77 | + deps |
| 78 | + key: ${{ steps.get_cache_key.outputs.cache_key }} |
| 79 | + |
| 80 | + # The following steps restore cached deps |
| 81 | + # If the cache is not hit, it will build and install the dependencies |
| 82 | + # If the cache is hit, building deps is skipped, only make install is run |
| 83 | + - uses: actions/cache/restore@v4 |
| 84 | + if: steps.build-cache-restore-step.outputs.cache-hit != 'true' # Variable type is string, thus using quotes |
| 85 | + with: |
| 86 | + path: deps |
| 87 | + key: ${{ needs.get_dependencies.outputs.cache_key }} |
| 88 | + - name: Set up dependencies |
| 89 | + if: steps.build-cache-restore-step.outputs.cache-hit != 'true' # Variable type is string, thus using quotes |
| 90 | + run: | |
| 91 | + sudo apt-get update |
| 92 | + sudo apt-get install -qy build-essential \ |
| 93 | + gdb \ |
| 94 | + curl \ |
| 95 | + python3.10 \ |
| 96 | + python3-pip \ |
| 97 | + cmake \ |
| 98 | + ninja-build \ |
| 99 | + pkg-config \ |
| 100 | + bison \ |
| 101 | + libfl-dev \ |
| 102 | + libbenchmark-dev \ |
| 103 | + libgmock-dev \ |
| 104 | + libz-dev |
| 105 | + - name: Install cached non packaged dependencies |
| 106 | + if: steps.build-cache-restore-step.outputs.cache-hit != 'true' # Variable type is string, thus using quotes |
| 107 | + working-directory: deps |
| 108 | + run: ../docker/build_deps.sh |
| 109 | + |
| 110 | + # Build BlazingMQ |
| 111 | + - name: Build BlazingMQ |
| 112 | + if: steps.build-cache-restore-step.outputs.cache-hit != 'true' # Variable type is string, thus using quotes |
| 113 | + env: |
| 114 | + PKG_CONFIG_PATH: /usr/lib/x86_64-linux-gnu/pkgconfig:/opt/bb/lib64/pkgconfig |
| 115 | + run: | |
| 116 | + cmake -S . -B build/blazingmq -G Ninja \ |
| 117 | + -DCMAKE_TOOLCHAIN_FILE=${{ github.workspace }}/deps/srcs/bde-tools/BdeBuildSystem/toolchains/linux/gcc-default.cmake \ |
| 118 | + -DCMAKE_BUILD_TYPE=Debug \ |
| 119 | + -DBDE_BUILD_TARGET_SAFE=ON \ |
| 120 | + -DBDE_BUILD_TARGET_64=ON \ |
| 121 | + -DBDE_BUILD_TARGET_CPP17=ON \ |
| 122 | + -DCMAKE_PREFIX_PATH=${{ github.workspace }}/deps/srcs/bde-tools/BdeBuildSystem \ |
| 123 | + -DCMAKE_INSTALL_LIBDIR=lib64 |
| 124 | + cmake --build build/blazingmq --parallel 8 --target ${{ inputs.target }} |
| 125 | +
|
| 126 | + - name: Clean-up build directories before caching |
| 127 | + if: steps.build-cache-restore-step.outputs.cache-hit != 'true' # Variable type is string, thus using quotes |
| 128 | + run: | |
| 129 | + find . -name "*.o" -type f -delete |
| 130 | + find . -name "*.a" -type f -delete |
| 131 | +
|
| 132 | + - name: Run UT [c++] |
| 133 | + if: contains(inputs.target, 'all.t') && inputs.run_unit_tests == true # Variable type is boolean, thus no quotes |
| 134 | + run: | |
| 135 | + cd ${{ github.workspace }}/build/blazingmq |
| 136 | + ctest --output-on-failure -L \^unit\$ |
| 137 | +
|
| 138 | + - name: Fail if requrested to run UTs, they were not built |
| 139 | + if: contains(inputs.target, 'all.t') == false && inputs.run_unit_tests == true # Variable type is boolean, thus no quotes |
| 140 | + run: | |
| 141 | + echo "Unit tests were requested to run, but the target does not include 'all.t'." |
| 142 | + echo "Please set the target to include 'all.t' to build unit tests." |
| 143 | + exit 1 |
| 144 | +
|
| 145 | + - uses: actions/upload-artifact@v4 |
| 146 | + if: inputs.save_build_as_artifacts == true # Variable type is boolean, thus no quotes |
| 147 | + with: |
| 148 | + path: | |
| 149 | + build/blazingmq |
| 150 | + deps |
| 151 | + name: ${{ steps.get_cache_key.outputs.artifact_key }} |
| 152 | + retention-days: 1 |
| 153 | + |
| 154 | + - name: Build Cache Save |
| 155 | + # Type of "save_build_as_artifacts" variable is boolean, thus no quotes |
| 156 | + # Type of "cache-hit" variable is string, thus using quotes |
| 157 | + if: inputs.save_build_as_artifacts == true && steps.build-cache-restore-step.outputs.cache-hit != 'true' |
| 158 | + uses: actions/cache/save@v4 |
| 159 | + with: |
| 160 | + path: | |
| 161 | + build/blazingmq |
| 162 | + deps |
| 163 | + key: ${{ steps.get_cache_key.outputs.cache_key }} |
0 commit comments