|
| 1 | +name: build-and-test-reusable |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + # Why is it a JSON string? |
| 7 | + # https://github.com/orgs/community/discussions/11692#discussioncomment-3541856 |
| 8 | + runner: |
| 9 | + type: string |
| 10 | + default: "['ubuntu-latest']" |
| 11 | + required: false |
| 12 | + container: |
| 13 | + type: string |
| 14 | + default: ghcr.io/autowarefoundation/autoware:universe-devel |
| 15 | + required: false |
| 16 | + container-suffix: |
| 17 | + type: string |
| 18 | + default: "" |
| 19 | + required: false |
| 20 | + rosdistro: |
| 21 | + type: string |
| 22 | + default: humble |
| 23 | + required: false |
| 24 | + build-pre-command: |
| 25 | + type: string |
| 26 | + default: "" |
| 27 | + required: false |
| 28 | + push-ccache: |
| 29 | + type: boolean |
| 30 | + default: false |
| 31 | + required: false |
| 32 | + pull-ccache: |
| 33 | + type: boolean |
| 34 | + default: false |
| 35 | + required: false |
| 36 | + concurrency-group: |
| 37 | + type: string |
| 38 | + default: ${{ github.workflow }}-${{ github.ref }}-${{ github.run_id }} # unique per run |
| 39 | + required: false |
| 40 | + cancel-in-progress: |
| 41 | + type: boolean |
| 42 | + default: false |
| 43 | + required: false |
| 44 | + codecov-flag: |
| 45 | + type: string |
| 46 | + default: temp |
| 47 | + required: false |
| 48 | + secrets: |
| 49 | + codecov-token: |
| 50 | + required: true |
| 51 | + |
| 52 | +concurrency: |
| 53 | + group: ${{ inputs.concurrency-group }} |
| 54 | + cancel-in-progress: ${{ inputs.cancel-in-progress }} |
| 55 | + |
| 56 | +env: |
| 57 | + CC: /usr/lib/ccache/gcc |
| 58 | + CXX: /usr/lib/ccache/g++ |
| 59 | + |
| 60 | +jobs: |
| 61 | + build-and-test: |
| 62 | + runs-on: ${{ fromJson(inputs.runner) }} |
| 63 | + container: ${{ inputs.container }}${{ inputs.container-suffix }} |
| 64 | + steps: |
| 65 | + - name: Check out repository |
| 66 | + uses: actions/checkout@v4 |
| 67 | + with: |
| 68 | + fetch-depth: 1 |
| 69 | + |
| 70 | + - name: Show disk space before the tasks |
| 71 | + run: df -h |
| 72 | + |
| 73 | + - name: Show machine specs |
| 74 | + run: lscpu && free -h |
| 75 | + |
| 76 | + - name: Remove exec_depend |
| 77 | + uses: autowarefoundation/autoware-github-actions/remove-exec-depend@v1 |
| 78 | + |
| 79 | + - name: Get self packages |
| 80 | + id: get-self-packages |
| 81 | + uses: autowarefoundation/autoware-github-actions/get-self-packages@v1 |
| 82 | + |
| 83 | + - name: Create ccache directory |
| 84 | + if: ${{ inputs.pull-ccache || inputs.push-ccache }} |
| 85 | + run: | |
| 86 | + mkdir -p ${CCACHE_DIR} |
| 87 | + du -sh ${CCACHE_DIR} && ccache -s |
| 88 | + shell: bash |
| 89 | + |
| 90 | + - name: Attempt to restore ccache |
| 91 | + if: ${{ inputs.pull-ccache }} |
| 92 | + uses: actions/cache/restore@v4 |
| 93 | + with: |
| 94 | + path: | |
| 95 | + /root/.ccache |
| 96 | + key: ccache-main-${{ runner.arch }}-${{ inputs.rosdistro }}-${{ github.sha }} |
| 97 | + restore-keys: | |
| 98 | + ccache-main-${{ runner.arch }}-${{ inputs.rosdistro }}- |
| 99 | +
|
| 100 | + - name: Limit ccache size |
| 101 | + if: ${{ inputs.pull-ccache || inputs.push-ccache }} |
| 102 | + run: | |
| 103 | + rm -f "${CCACHE_DIR}/ccache.conf" |
| 104 | + echo -e "# Set maximum cache size\nmax_size = 600MB" >> "${CCACHE_DIR}/ccache.conf" |
| 105 | + shell: bash |
| 106 | + |
| 107 | + - name: Show ccache stats before build and reset stats |
| 108 | + if: ${{ inputs.pull-ccache || inputs.push-ccache }} |
| 109 | + run: | |
| 110 | + du -sh ${CCACHE_DIR} && ccache -s |
| 111 | + ccache --zero-stats |
| 112 | + shell: bash |
| 113 | + |
| 114 | + - name: Export CUDA state as a variable for adding to cache key |
| 115 | + run: | |
| 116 | + build_type_cuda_state=nocuda |
| 117 | + if [[ "${{ inputs.container-suffix }}" == "-cuda" ]]; then |
| 118 | + build_type_cuda_state=cuda |
| 119 | + fi |
| 120 | + echo "BUILD_TYPE_CUDA_STATE=$build_type_cuda_state" >> "${GITHUB_ENV}" |
| 121 | + echo "::notice::BUILD_TYPE_CUDA_STATE=$build_type_cuda_state" |
| 122 | + shell: bash |
| 123 | + |
| 124 | + - name: Build |
| 125 | + if: ${{ steps.get-self-packages.outputs.self-packages != '' }} |
| 126 | + uses: autowarefoundation/autoware-github-actions/colcon-build@v1 |
| 127 | + with: |
| 128 | + rosdistro: ${{ inputs.rosdistro }} |
| 129 | + target-packages: ${{ steps.get-self-packages.outputs.self-packages }} |
| 130 | + cache-key-element: ${{ env.BUILD_TYPE_CUDA_STATE }} |
| 131 | + build-pre-command: ${{ inputs.build-pre-command }} |
| 132 | + underlay-workspace: /opt/autoware |
| 133 | + |
| 134 | + - name: Show ccache stats after build |
| 135 | + if: ${{ inputs.pull-ccache || inputs.push-ccache }} |
| 136 | + run: du -sh ${CCACHE_DIR} && ccache -s |
| 137 | + shell: bash |
| 138 | + |
| 139 | + # Only keep save the -cuda version because cuda packages covers non-cuda packages too |
| 140 | + - name: Push the ccache cache (if inputs.container-suffix == '-cuda' AND inputs.push-ccache) |
| 141 | + if: ${{ inputs.push-ccache }} |
| 142 | + uses: actions/cache/save@v4 |
| 143 | + with: |
| 144 | + path: | |
| 145 | + /root/.ccache |
| 146 | + key: ccache-main-${{ runner.arch }}-${{ inputs.rosdistro }}-${{ github.sha }} |
| 147 | + |
| 148 | + - name: Test |
| 149 | + if: ${{ steps.get-self-packages.outputs.self-packages != '' }} |
| 150 | + id: test |
| 151 | + uses: autowarefoundation/autoware-github-actions/colcon-test@v1 |
| 152 | + with: |
| 153 | + rosdistro: ${{ inputs.rosdistro }} |
| 154 | + target-packages: ${{ steps.get-self-packages.outputs.self-packages }} |
| 155 | + underlay-workspace: /opt/autoware |
| 156 | + |
| 157 | + - name: Upload coverage to CodeCov |
| 158 | + if: ${{ steps.test.outputs.coverage-report-files != '' }} |
| 159 | + uses: codecov/codecov-action@v4 |
| 160 | + with: |
| 161 | + files: ${{ steps.test.outputs.coverage-report-files }} |
| 162 | + fail_ci_if_error: false |
| 163 | + verbose: true |
| 164 | + flags: ${{ inputs.codecov-flag }} |
| 165 | + token: ${{ secrets.CODECOV_TOKEN }} |
| 166 | + |
| 167 | + - name: Show disk space after the tasks |
| 168 | + run: df -h |
0 commit comments