name: Reusable build on: workflow_call: inputs: runs_on: description: Runner to run the job on required: true type: string container: description: "The container object as a JSON string (leave empty to run natively)" required: true type: string compiler: description: 'Compiler to build with ("gcc", "clang" or "apple-clang")' required: true type: string sanitizers: description: 'Sanitizers to enable ("address", "thread", "undefinedbehavior" or empty)' required: false type: string default: "" build_type: description: Build type required: true type: string download_ccache: description: Whether to download ccache from the cache required: false type: boolean default: true upload_ccache: description: Whether to upload ccache to the cache required: false type: boolean default: false code_coverage: description: Whether to enable code coverage required: true type: boolean upload_clio_server: description: Whether to upload clio_server required: true type: boolean targets: description: Space-separated build target names required: true type: string analyze_build_time: description: Whether to enable build time analysis required: true type: boolean package: description: Whether to generate Debian package required: false type: boolean version: description: Version of the clio_server binary required: false type: string default: "" secrets: CODECOV_TOKEN: required: false defaults: run: shell: bash jobs: build: name: Build runs-on: ${{ inputs.runs_on }} container: ${{ inputs.container != '' && fromJson(inputs.container) || null }} steps: - name: Cleanup workspace if: ${{ runner.os == 'macOS' }} uses: XRPLF/actions/cleanup-workspace@c7d9ce5ebb03c752a354889ecd870cadfc2b1cd4 - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: fetch-depth: 0 - name: Prepare runner uses: XRPLF/actions/prepare-runner@7bf7ceca5932114abdd0d43493c3c30c5a654e13 with: enable_ccache: ${{ inputs.download_ccache }} - name: Print build environment uses: XRPLF/actions/print-build-env@59dec886e4afb05a1724443af08baccbc045b574 - name: Set compiler environment if: ${{ runner.os == 'Linux' }} uses: ./.github/actions/set-compiler-env with: compiler: ${{ inputs.compiler }} - name: Setup conan run: conan/init.sh - name: Generate build identifier uses: ./.github/actions/build-identifier id: build_identifier with: build_type: ${{ inputs.build_type }} compiler: ${{ inputs.compiler }} code_coverage: ${{ inputs.code_coverage }} sanitizers: ${{ inputs.sanitizers }} - name: Restore ccache cache if: ${{ inputs.download_ccache && github.ref != 'refs/heads/develop' }} uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 with: path: ${{ env.CCACHE_DIR }} key: ${{ steps.build_identifier.outputs.cache_key }} restore-keys: | ${{ steps.build_identifier.outputs.build_identifier }} - name: Run conan uses: ./.github/actions/conan with: build_type: ${{ inputs.build_type }} sanitizers: ${{ inputs.sanitizers }} - name: Run CMake uses: ./.github/actions/cmake with: build_type: ${{ inputs.build_type }} code_coverage: ${{ inputs.code_coverage }} time_trace: ${{ inputs.analyze_build_time }} package: ${{ inputs.package }} version: ${{ inputs.version }} - name: Build Clio uses: ./.github/actions/build-clio with: targets: ${{ inputs.targets }} - name: Show build time analyze report if: ${{ inputs.analyze_build_time }} run: | ClangBuildAnalyzer --all build/ build_time_report.bin ClangBuildAnalyzer --analyze build_time_report.bin >build_time_report.txt cat build_time_report.txt - name: Upload build time analyze report if: ${{ inputs.analyze_build_time }} uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 with: name: build_time_report_${{ steps.build_identifier.outputs.build_identifier }} path: build_time_report.txt - name: Show ccache's statistics and zero it if: ${{ inputs.download_ccache }} run: | ccache --show-stats -vv ccache --zero-stats - name: Save ccache cache if: ${{ inputs.upload_ccache && github.ref == 'refs/heads/develop' }} uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 with: path: ${{ env.CCACHE_DIR }} key: ${{ steps.build_identifier.outputs.cache_key }} - name: Strip unit_tests if: ${{ inputs.sanitizers == '' && !inputs.code_coverage && !inputs.analyze_build_time }} run: strip build/clio_tests - name: Strip integration_tests if: ${{ inputs.sanitizers == '' && !inputs.code_coverage && !inputs.analyze_build_time }} run: strip build/clio_integration_tests - name: Upload clio_server if: ${{ inputs.upload_clio_server && !inputs.code_coverage && !inputs.analyze_build_time }} uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 with: name: clio_server_${{ steps.build_identifier.outputs.build_identifier }} path: build/clio_server - name: Upload clio_tests if: ${{ !inputs.code_coverage && !inputs.analyze_build_time && !inputs.package }} uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 with: name: clio_tests_${{ steps.build_identifier.outputs.build_identifier }} path: build/clio_tests - name: Upload clio_integration_tests if: ${{ !inputs.code_coverage && !inputs.analyze_build_time && !inputs.package }} uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 with: name: clio_integration_tests_${{ steps.build_identifier.outputs.build_identifier }} path: build/clio_integration_tests - name: Upload Clio Linux package if: ${{ inputs.package }} uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 with: name: clio_deb_package_${{ steps.build_identifier.outputs.build_identifier }} path: build/*.deb # This is run as part of the build job, because it requires the following: # - source code # - conan packages # - .gcno files in build directory # # It's all available in the build job, but not in the test job - name: Run code coverage if: ${{ inputs.code_coverage }} uses: ./.github/actions/code-coverage - name: Verify version is expected if: ${{ inputs.version != '' }} env: INPUT_VERSION: ${{ inputs.version }} BUILD_TYPE: ${{ inputs.build_type }} run: | set -e EXPECTED_VERSION="clio-${INPUT_VERSION}" if [[ "${BUILD_TYPE}" == "Debug" ]]; then EXPECTED_VERSION="${EXPECTED_VERSION}+DEBUG" fi actual_version=$(./build/clio_server --version | head -n 1) if [[ "${actual_version}" != "${EXPECTED_VERSION}" ]]; then echo "Expected version '${EXPECTED_VERSION}', but got '${actual_version}'" exit 1 fi # `codecov/codecov-action` will rerun `gcov` if it's available and build directory is present # To prevent this from happening, we run this action in a separate workflow # # More info: https://github.com/XRPLF/clio/pull/2066 upload_coverage_report: if: ${{ inputs.code_coverage }} name: Codecov needs: build uses: ./.github/workflows/reusable-upload-coverage-report.yml secrets: CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}