-
Notifications
You must be signed in to change notification settings - Fork 700
155 lines (141 loc) · 7.81 KB
/
build.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# Main Contiki-NG CI workflow
# Comprises a matrix-generated set of jobs that execute our CI test suite
name: CI
# Run the workflow on:
# * Any PR against master, develop or candidate release branch
# * Any push (or merge) on master and develop
on:
push:
branches: [ master, develop ]
pull_request:
branches: [ master, develop, release-* ]
# We use a single job with a matrix with elements corresponding to our tests
# The job will be replicated as many times as there are elements in the matrix
jobs:
Contiki-NG:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Longest test in July 2022 takes 15 minutes. Building the docker image
# takes 10 minutes.
timeout-minutes: 45
# Common environment variables
env:
OUT_OF_TREE_TEST_PATH: out-of-tree-tests
OUT_OF_TREE_TEST_VER: 2869ae7
DOCKER_BASE_IMG: contiker/contiki-ng
strategy:
# Always run all jobs in the matrix, even if one fails
fail-fast: false
matrix:
test: [ documentation, compile-base, compile-arm-ports, compile-tools, out-of-tree-build, rpl-lite, rpl-classic, simulation-base, ipv6, ieee802154, tun-rpl-br, script-base, native-runs, ipv6-nbr, coap-lwm2m, packet-parsing ]
# Checks-out the contiki-ng $GITHUB_WORKSPACE, so your job can access it
steps:
# Checks out the repo with full history
- name: Checkout github repo (+ download lfs dependencies)
uses: actions/checkout@v3
with:
fetch-depth: 2
submodules: 'recursive'
persist-credentials: false
lfs: true
- name: Checkout LFS objects
run: git lfs checkout
# Construct the correct docker container image tag corresponding to this build
- name: Figure out correct docker image tag
run: |
tools/docker/print-dockerhash.sh >> $GITHUB_ENV
echo COOJA_COMMIT=$(git -C tools/cooja log -1 --oneline | cut -d" " -f1) >> $GITHUB_ENV
echo SOURCE_DATE_EPOCH=$(git log -1 --pretty=%ct) >> $GITHUB_ENV
# Try to download the image from dockerhub. If it works, use it.
#
# If however it fails then we are most likely looking at a branch or pull
# that touched tools/docker. In this case, build the image.
#
# Any build error will count as a job failure.
#
# If the test was triggered by a branch update (e.g. a PR merge) then push
# the new image to dockerhub. This will only happen for builds against
# contiki-ng/contiki-ng, not for builds on forks.
- name: Try to download image from dockerhub
run: |
echo "Using $DOCKER_IMG for this run"
echo "Pulling image $DOCKER_IMG from dockerhub";
docker pull $DOCKER_IMG || echo DOCKER_NEED_BUILD=1 >> $GITHUB_ENV
- name: Build docker image if required
if: env.DOCKER_NEED_BUILD == '1'
run: |
echo $DOCKER_IMG does not exist on dockerhub or pull failed
echo This is normal for PR builds and for builds on forks
echo Building from dockerfile
docker build tools/docker -t $DOCKER_IMG --no-cache --pull
# If i) the previous step built an image and ii) we are on the main
# contiki-ng repo and iii) this is a push (merge commit) to one of the
# branches of interest then push the image to dockerhub
- name: Push images to dockerhub
if: env.DOCKER_NEED_BUILD == '1' && github.repository == 'contiki-ng/contiki-ng' && github.event_name == 'push'
run: |
# Extract the branch name from github.ref. For example, from
# 'refs/heads/master' we want to keep 'master'
MERGE_BRANCH_REF=$(echo ${{ github.ref }} | sed -e 's|refs/heads/||g')
echo This is a build for branch $MERGE_BRANCH_REF and it updates the docker container
echo Push images to Dockerhub
echo ${{ secrets.DOCKERHUB_PASSWD }} | docker login --username contiker --password-stdin
docker push $DOCKER_IMG
docker tag $DOCKER_IMG $DOCKER_BASE_IMG:$MERGE_BRANCH_REF
docker push $DOCKER_BASE_IMG:$MERGE_BRANCH_REF
if [ $MERGE_BRANCH_REF == develop ]; then
# When develop is updated, also push docker image with tag 'latest'
docker tag $DOCKER_IMG $DOCKER_BASE_IMG:latest
docker push $DOCKER_BASE_IMG:latest
fi
# Clone the repo used for out-of-tree builds if required
- name: Clone the repo used for out-of-tree builds if required
if: matrix.test == 'out-of-tree-build'
run: |
mkdir -p $OUT_OF_TREE_TEST_PATH
git clone --depth 1 https://github.com/contiki-ng/out-of-tree-tests $OUT_OF_TREE_TEST_PATH
# Check out desired hash
(cd $OUT_OF_TREE_TEST_PATH && git checkout $OUT_OF_TREE_TEST_VER)
# Set up docker mount
echo DOCKER_ARGS=-v `pwd`/$OUT_OF_TREE_TEST_PATH:/home/user/out-of-tree-tests >> $GITHUB_ENV
# The docker image contains ccache, but the ccache action uses the ccache
# outside docker for statistics, so install the same ccache version.
# Install in /usr/bin so the ccache action gets the expected environment.
- name: install ccache
run: |
wget -nv https://github.com/ccache/ccache/releases/download/v4.8.2/ccache-4.8.2-linux-x86_64.tar.xz
sudo tar xf ccache-4.8.2-linux-x86_64.tar.xz -C /usr/bin --strip-components=1 --no-same-owner ccache-4.8.2-linux-x86_64/ccache
rm -f ccache-*-linux-x86_64.tar.xz
# Set the max-size according to the output from "ccache -v -s" after
# running the largest test in a newly started docker container.
# The largest test is 02-compile-arm-ports in July 2023.
#
# IMPORTANT: cache size must also be updated in the "Execute tests" section.
- name: ccache
uses: hendrikmuhs/ccache-action@v1.2.10
with:
key: compilation-${{ matrix.test }}
max-size: 160M
# Keep a cache of the Cooja build files and gradle files. Keyed on Cooja
# repo commit to ensure clean rebuild when updating Cooja submodule.
- name: Cache Cooja Artifacts
uses: actions/cache@v3
with:
path: |
tools/cooja/build
tools/cooja/.gradle
tools/cooja/.gradle_home
key: cooja-${{ runner.os }}-gradle-deps-${{ env.COOJA_COMMIT }}
# Fire up the container and run corresponding tests
- name: Execute tests
run: |
# Cache restores write-time timestamps, update timestamps to be more
# recent than the files that were just checked out. Ensure the command
# is successful with empty cache.
find tools/cooja/build tools/cooja/.gradle -exec touch {} \; 2>/dev/null || true
# Run test
# FIXME: (2023) Remove "ccache -c", workaround for cache growing
# too large from ccache CI/ccache configuration mismatch.
docker run --privileged --sysctl net.ipv6.conf.all.disable_ipv6=0 -e GITHUB_JOB -e GITHUB_REF -e GITHUB_SHA -e GITHUB_REPOSITORY -e GITHUB_REPOSITORY_OWNER -e GITHUB_RUN_ID -e GITHUB_RUN_NUMBER -e GITHUB_RETENTION_DAYS -e GITHUB_ACTOR -e GITHUB_WORKFLOW -e GITHUB_HEAD_REF -e GITHUB_BASE_REF -e GITHUB_EVENT_NAME -e GITHUB_SERVER_URL -e GITHUB_API_URL -e GITHUB_GRAPHQL_URL -e GITHUB_WORKSPACE -e GITHUB_ACTION -e GITHUB_EVENT_PATH -e GITHUB_ACTION_REPOSITORY -e GITHUB_ACTION_REF -e GITHUB_PATH -e GITHUB_ENV -e RUNNER_OS -e RUNNER_TOOL_CACHE -e RUNNER_TEMP -e RUNNER_WORKSPACE -e ACTIONS_RUNTIME_URL -e ACTIONS_RUNTIME_TOKEN -e ACTIONS_CACHE_URL -e GITHUB_ACTIONS=true -e CI=true -e GRADLE_USER_HOME=/home/user/contiki-ng/tools/cooja/.gradle_home -e LOCAL_UID=$(id -u $USER) -e LOCAL_GID=$(id -g $USER) -e SOURCE_DATE_EPOCH $DOCKER_ARGS -v `pwd`:/home/user/contiki-ng -v $GITHUB_WORKSPACE/.ccache:/home/user/.ccache $DOCKER_IMG bash --login -c "source ../.bash_aliases && ccache --set-config=max_size='160M' && cimake -C tests/??-${{ matrix.test }}; ccache -c"
# Check outcome of the test
./tests/check-test.sh `pwd`/tests/??-${{ matrix.test }}