Skip to content

Commit ee39da0

Browse files
authored
ci: add build and test workflows (#4)
Signed-off-by: Ryohsuke Mitsudome <ryohsuke.mitsudome@tier4.jp>
1 parent 38ec9e1 commit ee39da0

6 files changed

Lines changed: 458 additions & 0 deletions
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: build-and-test-daily
2+
3+
on:
4+
schedule:
5+
- cron: 0 0 * * * # every day at midnight UTC
6+
workflow_dispatch:
7+
8+
jobs:
9+
build-and-test-daily:
10+
uses: ./.github/workflows/build-and-test-reusable.yaml
11+
with:
12+
container: ghcr.io/autowarefoundation/autoware:core-devel
13+
container-suffix: ""
14+
pull-ccache: true
15+
concurrency-group: build-and-test-daily-${{ github.ref }}-${{ github.run_id }}
16+
codecov-flag: daily
17+
secrets:
18+
codecov-token: ${{ secrets.CODECOV_TOKEN }}
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
name: build-and-test-differential
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
container:
7+
required: true
8+
type: string
9+
runner:
10+
default: ubuntu-24.04
11+
required: false
12+
type: string
13+
rosdistro:
14+
default: humble
15+
required: false
16+
type: string
17+
run-condition:
18+
default: true
19+
required: false
20+
type: boolean
21+
container-suffix:
22+
required: false
23+
default: ""
24+
type: string
25+
build-pre-command:
26+
required: false
27+
default: ""
28+
type: string
29+
secrets:
30+
codecov-token:
31+
required: true
32+
33+
env:
34+
CC: /usr/lib/ccache/gcc
35+
CXX: /usr/lib/ccache/g++
36+
37+
jobs:
38+
build-and-test-differential:
39+
if: ${{ inputs.run-condition }}
40+
runs-on: ${{ inputs.runner }}
41+
container: ${{ inputs.container }}${{ inputs.container-suffix }}
42+
steps:
43+
- name: Set PR fetch depth
44+
run: echo "PR_FETCH_DEPTH=$(( ${{ github.event.pull_request.commits }} + 1 ))" >> "${GITHUB_ENV}"
45+
shell: bash
46+
47+
- name: Checkout PR branch and all PR commits
48+
uses: actions/checkout@v4
49+
with:
50+
ref: ${{ github.event.pull_request.head.sha }}
51+
fetch-depth: ${{ env.PR_FETCH_DEPTH }}
52+
53+
- name: Show disk space before the tasks
54+
run: df -h
55+
shell: bash
56+
57+
- name: Show machine specs
58+
run: lscpu && free -h
59+
shell: bash
60+
61+
- name: Remove exec_depend
62+
uses: autowarefoundation/autoware-github-actions/remove-exec-depend@v1
63+
64+
- name: Get modified packages
65+
id: get-modified-packages
66+
uses: autowarefoundation/autoware-github-actions/get-modified-packages@v1
67+
68+
- name: Create ccache directory
69+
run: |
70+
mkdir -p ${CCACHE_DIR}
71+
du -sh ${CCACHE_DIR} && ccache -s
72+
shell: bash
73+
74+
- name: Attempt to restore ccache
75+
uses: actions/cache/restore@v4
76+
with:
77+
path: |
78+
/root/.ccache
79+
key: ccache-main-${{ runner.arch }}-${{ inputs.rosdistro }}-${{ github.event.pull_request.base.sha }}
80+
restore-keys: |
81+
ccache-main-${{ runner.arch }}-${{ inputs.rosdistro }}-
82+
83+
- name: Show ccache stats before build and reset stats
84+
run: |
85+
du -sh ${CCACHE_DIR} && ccache -s
86+
ccache --zero-stats
87+
shell: bash
88+
89+
- name: Export CUDA state as a variable for adding to cache key
90+
run: |
91+
build_type_cuda_state=nocuda
92+
if [[ "${{ inputs.container-suffix }}" == "-cuda" ]]; then
93+
build_type_cuda_state=cuda
94+
fi
95+
echo "BUILD_TYPE_CUDA_STATE=$build_type_cuda_state" >> "${GITHUB_ENV}"
96+
echo "::notice::BUILD_TYPE_CUDA_STATE=$build_type_cuda_state"
97+
shell: bash
98+
99+
- name: Build
100+
if: ${{ steps.get-modified-packages.outputs.modified-packages != '' }}
101+
uses: autowarefoundation/autoware-github-actions/colcon-build@v1
102+
with:
103+
rosdistro: ${{ inputs.rosdistro }}
104+
target-packages: ${{ steps.get-modified-packages.outputs.modified-packages }}
105+
cache-key-element: ${{ env.BUILD_TYPE_CUDA_STATE }}
106+
build-pre-command: ${{ inputs.build-pre-command }}
107+
underlay-workspace: /opt/autoware
108+
- name: Show ccache stats after build
109+
run: du -sh ${CCACHE_DIR} && ccache -s
110+
shell: bash
111+
112+
- name: Test
113+
id: test
114+
if: ${{ steps.get-modified-packages.outputs.modified-packages != '' }}
115+
uses: autowarefoundation/autoware-github-actions/colcon-test@v1
116+
with:
117+
rosdistro: ${{ inputs.rosdistro }}
118+
target-packages: ${{ steps.get-modified-packages.outputs.modified-packages }}
119+
underlay-workspace: /opt/autoware
120+
121+
- name: Upload coverage to CodeCov
122+
if: ${{ steps.test.outputs.coverage-report-files != '' }}
123+
uses: codecov/codecov-action@v4
124+
with:
125+
files: ${{ steps.test.outputs.coverage-report-files }}
126+
fail_ci_if_error: false
127+
verbose: true
128+
flags: differential${{ inputs.container-suffix }}
129+
token: ${{ secrets.codecov-token }}
130+
131+
- name: Show disk space after the tasks
132+
run: df -h
133+
shell: bash
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
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
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: build-and-test
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
build-and-test:
10+
uses: ./.github/workflows/build-and-test-reusable.yaml
11+
with:
12+
runner: "['self-hosted', 'Linux', 'X64']"
13+
container: ghcr.io/autowarefoundation/autoware:universe-devel
14+
concurrency-group: ${{ github.workflow }}-${{ github.ref }}
15+
cancel-in-progress: false
16+
pull-ccache: true
17+
push-ccache: true
18+
codecov-flag: total
19+
secrets:
20+
codecov-token: ${{ secrets.CODECOV_TOKEN }}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: build-test-tidy-pr
2+
3+
on:
4+
pull_request:
5+
types:
6+
- opened
7+
- synchronize
8+
- reopened
9+
- labeled
10+
11+
concurrency:
12+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }}
13+
cancel-in-progress: true
14+
15+
jobs:
16+
require-label:
17+
uses: autowarefoundation/autoware-github-actions/.github/workflows/require-label.yaml@v1
18+
with:
19+
label: run:build-and-test-differential
20+
21+
build-and-test-differential:
22+
if: ${{ always() }}
23+
needs:
24+
- require-label
25+
uses: ./.github/workflows/build-and-test-differential.yaml
26+
with:
27+
container: ghcr.io/autowarefoundation/autoware:core-devel
28+
run-condition: ${{ needs.require-label.outputs.result == 'true' }}
29+
secrets:
30+
codecov-token: ${{ secrets.CODECOV_TOKEN }}
31+
32+
clang-tidy-differential:
33+
if: ${{ always() }} # always run to provide report for status check
34+
needs:
35+
- build-and-test-differential
36+
uses: ./.github/workflows/clang-tidy-differential.yaml
37+
with:
38+
container: ghcr.io/autowarefoundation/autoware:core-devel
39+
run-condition: true

0 commit comments

Comments
 (0)