Skip to content

Commit

Permalink
CI speedup (commaai#1108)
Browse files Browse the repository at this point in the history
* use docker buildkit

* enable push

* try this caching

* no regressions

* don't copy into the image

* move that

* getting there

* debug

* little smaller

* debug

* configure safe dir

* no sudo

* cleanup

* another timeout
  • Loading branch information
adeebshihadeh authored and mlocoteta committed Apr 29, 2023
1 parent 23d185a commit f593e40
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 37 deletions.
64 changes: 37 additions & 27 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
name: tests
on: [push, pull_request]

concurrency:
group: ${{ github.workflow }}-${{ github.ref != 'refs/heads/master' && github.ref || github.run_id }}-${{ github.event_name }}
cancel-in-progress: true

env:
RUN: docker run --rm panda /bin/bash -c
PERSIST: docker run --name panda panda /bin/sh -c
RUN: docker run -v $GITHUB_WORKSPACE:/tmp/openpilot/panda -w /tmp/openpilot/panda --rm panda /bin/bash -c
PERSIST: docker run -v $GITHUB_WORKSPACE:/tmp/openpilot/panda -w /tmp/openpilot/panda --name panda panda /bin/bash -c
BUILD: |
docker pull $(grep -ioP '(?<=^from)\s+\S+' Dockerfile.panda) || true
docker pull ghcr.io/commaai/panda:latest || true
docker build --cache-from ghcr.io/commaai/panda:latest -t panda -f Dockerfile.panda .
export DOCKER_BUILDKIT=1
docker build --pull --build-arg BUILDKIT_INLINE_CACHE=1 --cache-from ghcr.io/commaai/panda:latest -t panda -f Dockerfile.panda .
jobs:
docker_push:
name: docker push
runs-on: ubuntu-20.04
timeout-minutes: 45
timeout-minutes: 20
if: github.ref == 'refs/heads/master' && github.event_name != 'pull_request' && github.repository == 'commaai/panda'
steps:
- uses: actions/checkout@v2
- name: Build Docker image
timeout-minutes: 11
run: eval "$BUILD"
- name: Login to dockerhub
run: docker login ghcr.io -u ${{ github.actor }} -p ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -29,69 +33,71 @@ jobs:
build:
name: build
runs-on: ubuntu-20.04
timeout-minutes: 45
timeout-minutes: 20
steps:
- uses: actions/checkout@v2
- name: Build Docker image
run: eval "$BUILD"
- name: Test python package installer
run: $RUN "cd /tmp/openpilot/panda && python setup.py install"
run: ${{ env.RUN }} "cd /tmp/openpilot/panda && python setup.py install"
- name: Build panda STM image and bootstub
run: $RUN "cd /tmp/openpilot/panda && scons"
run: ${{ env.RUN }} "cd /tmp/openpilot/panda && scons"
- name: Build pedal STM image and bootstub
run: $RUN "cd /tmp/openpilot/panda && PEDAL=1 scons"
run: ${{ env.RUN }} "cd /tmp/openpilot/panda && PEDAL=1 scons"

unit_tests:
name: unit tests
runs-on: ubuntu-20.04
timeout-minutes: 45
timeout-minutes: 20
steps:
- uses: actions/checkout@v2
- name: Build Docker image
run: eval "$BUILD"
- name: Test pack/unpack for USB protocol
run: $RUN "cd /tmp/openpilot/panda/tests/usbprotocol &&
run: ${{ env.RUN }} "cd /tmp/openpilot/panda/tests/usbprotocol &&
python -m unittest discover ."

safety:
name: safety
runs-on: ubuntu-20.04
timeout-minutes: 45
timeout-minutes: 20
steps:
- uses: actions/checkout@v2
- name: Build Docker image
run: eval "$BUILD"
- name: Run safety tests
timeout-minutes: 3
run: |
$RUN "cd /tmp/openpilot && \
scons -c && \
scons -j$(nproc) opendbc/ cereal/ && \
cd panda/tests/safety && \
./test.sh"
${{ env.RUN }} "cd /tmp/openpilot && \
scons -c && \
scons -j$(nproc) opendbc/ cereal/ && \
cd panda/tests/safety && \
./test.sh"
safety_replay:
name: safety replay
runs-on: ubuntu-20.04
timeout-minutes: 45
timeout-minutes: 20
steps:
- uses: actions/checkout@v2
- name: Build Docker image
run: eval "$BUILD"
- name: Run safety replay
run: $RUN "cd /tmp/openpilot/panda/tests/safety_replay &&
scons -u --test .. &&
./test_safety_replay.py"
run: ${{ env.RUN }} "cd tests/safety_replay &&
scons -u --test .. &&
./test_safety_replay.py"

misra:
name: misra c2012
runs-on: ubuntu-20.04
timeout-minutes: 45
timeout-minutes: 20
steps:
- uses: actions/checkout@v2
- name: Build Docker image
run: eval "$BUILD"
- name: Run Misra C 2012 analysis
run: $PERSIST "cd /tmp/openpilot/panda/tests/misra && ./test_misra.sh"
timeout-minutes: 4
run: ${{ env.PERSIST }} "cd tests/misra && ./test_misra.sh"
- name: Copy analysis outputs
run: docker cp panda:/tmp/misra /tmp
- uses: actions/upload-artifact@v2
Expand All @@ -104,15 +110,19 @@ jobs:
with:
name: misra_output
path: /tmp/misra/misra_*_output.txt
- run: docker rm panda
if: always()

python_linter:
name: python linter
runs-on: ubuntu-20.04
timeout-minutes: 45
timeout-minutes: 20
steps:
- uses: actions/checkout@v2
- name: Build Docker image
run: eval "$BUILD"
- name: Run static analysis
run: |
$RUN "cd /tmp/openpilot/panda && git init && git add -A && pre-commit run --all"
timeout-minutes: 3
run: ${{ env.RUN }} "pre-commit run --all"


14 changes: 8 additions & 6 deletions Dockerfile.panda
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
unzip \
wget \
zlib1g-dev \
&& rm -rf /var/lib/apt/lists/*
&& rm -rf /var/lib/apt/lists/* && \
cd /usr/lib/gcc/arm-none-eabi/9.2.1 && \
rm -rf arm/ && \
rm -rf thumb/nofp thumb/v6* thumb/v8* thumb/v7+fp thumb/v7-r+fp.sp

RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && locale-gen
ENV LANG en_US.UTF-8
Expand All @@ -56,13 +59,15 @@ RUN pyenv install 3.8.10 && \
pyenv rehash && \
pip install --no-cache-dir -r /tmp/requirements.txt

ENV CPPCHECK_DIR=/tmp/cppcheck
COPY tests/misra/install.sh /tmp/
RUN /tmp/install.sh

RUN git config --global --add safe.directory /tmp/openpilot/panda
RUN cd /tmp && \
git clone https://github.com/commaai/openpilot.git tmppilot || true && \
cd /tmp/tmppilot && \
git fetch && \
git fetch origin $OPENPILOT_REF && \
git checkout $OPENPILOT_REF && \
git submodule update --init cereal opendbc rednose_repo && \
git -C opendbc fetch && \
Expand All @@ -71,12 +76,9 @@ RUN cd /tmp && \
git -C opendbc clean -xfd && \
mkdir /tmp/openpilot && \
cp -pR SConstruct site_scons/ tools/ selfdrive/ system/ common/ cereal/ opendbc/ rednose/ third_party/ /tmp/openpilot && \
rm -rf /tmp/openpilot/panda && \
rm -rf /tmp/tmppilot

RUN cd /tmp/openpilot && \
pip install --no-cache-dir -r opendbc/requirements.txt && \
pip install --no-cache-dir --upgrade aenum lru-dict pycurl tenacity atomicwrites serial smbus2 scons

COPY . /tmp/openpilot/panda
RUN mv /tmp/cppcheck /tmp/openpilot/panda/tests/misra && \
rm -rf /tmp/openpilot/panda/.git
8 changes: 4 additions & 4 deletions tests/misra/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
set -e

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
: "${CPPCHECK_DIR:=$DIR/cppcheck/}"

cd $DIR
if [ ! -d cppcheck/ ]; then
git clone https://github.com/danmar/cppcheck.git
if [ ! -d "$CPPCHECK_DIR" ]; then
git clone https://github.com/danmar/cppcheck.git $CPPCHECK_DIR
fi

cd cppcheck
cd $CPPCHECK_DIR
git fetch
git checkout e1cff1d1ef92f6a1c6962e0e4153b7353ccad04c
git -c user.name=a -c user.email="a@b.c" cherry-pick 7199dde1618b5166735f07619dcdb9f4eafdb557
Expand Down

0 comments on commit f593e40

Please sign in to comment.