Skip to content

Commit

Permalink
Add caching and log artifacts to GitHub actions
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Carroll <[email protected]>
  • Loading branch information
mjcarroll committed Feb 10, 2023
1 parent de960fa commit 7be81c0
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 446 deletions.
10 changes: 10 additions & 0 deletions .github/actions/bazel-ci-jammy/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
FROM ghcr.io/gazebo-tooling/gz-ubuntu:garden-jammy
ARG UID=1000

# Add a runner user and group to match github actions
# Additionally, use passwordless sudo
RUN groupadd -g 121 runner \
&& useradd -mr -d /home/runner -u 1001 -g 121 runner \
&& usermod -aG sudo runner \
&& echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers

COPY ["run.sh", "/run.sh"]
COPY ["entrypoint.sh", "/entrypoint.sh"]

USER runner

ENTRYPOINT ["/entrypoint.sh"]
2 changes: 1 addition & 1 deletion .github/actions/bazel-ci-jammy/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/sh -l

sudo bash /run.sh $@
bash /run.sh $@
71 changes: 38 additions & 33 deletions .github/actions/bazel-ci-jammy/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,61 +4,66 @@ set -x
set -e

BAZEL_ARGS=$1
WORKSPACE=~/gz
BAZEL_CACHE=$GITHUB_WORKSPACE/bazel_cache
BAZEL=$BAZEL_CACHE/bazelisk-linux-amd64

echo ::group::Install tools: apt
apt update 2>&1
apt -y install \
build-essential \
cppcheck \
curl \
git \
gnupg \
lsb-release \
python3-pip \
wget

cd "$GITHUB_WORKSPACE"
SYSTEM_VERSION=`lsb_release -cs`
SOURCE_DEPENDENCIES="`pwd`/.github/ci/dependencies.yaml"
SOURCE_DEPENDENCIES_VERSIONED="`pwd`/.github/ci-$SYSTEM_VERSION/dependencies.yaml"
echo ::endgroup::

echo ::group::Install tools: pip
pip3 install -U pip vcstool colcon-common-extensions
echo ::endgroup::
cd "$GITHUB_WORKSPACE"

# Install bazelisk
wget https://github.com/bazelbuild/bazelisk/releases/download/v1.16.0/bazelisk-linux-amd64
mv ./bazelisk-linux-amd64 /usr/bin/bazel
chmod +x /usr/bin/bazel
# Restore cache
if [ ! -d "$BAZEL_CACHE" ]; then
mkdir -p ${BAZEL_CACHE}
fi
rm -rf ~/.cache
ln -sf ${BAZEL_CACHE} ~/.cache

# Install baselisk if it is not already installed
if [ ! -f ${BAZEL} ]; then
wget https://github.com/bazelbuild/bazelisk/releases/download/v1.16.0/bazelisk-linux-amd64 -O ${BAZEL}
fi
chmod +x ${BAZEL}

# Import repos
mkdir -p /gz
cd /gz
cp -R /github/workspace /gz/bazel
vcs import . < /github/workspace/example/bazel.repos
mkdir -p ${WORKSPACE}/bazel
cd ${WORKSPACE}
shopt -s extglob
# Copy relevant bazel files into the build space
cp -R ${GITHUB_WORKSPACE}/!(gz|.git|.github|bazel_cache) ${WORKSPACE}/bazel
vcs import . < ${WORKSPACE}/bazel/example/bazel.repos

echo ::group::Install dependencies from binaries
EXCLUDE_APT="libignition|libgz|libsdformat|libogre|dart"
UBUNTU_VERSION=`lsb_release -cs`
ALL_PACKAGES=$( \
sort -u $(find . -iname 'packages-'$UBUNTU_VERSION'.apt' -o -iname 'packages.apt') | grep -Ev $EXCLUDE_APT | tr '\n' ' ')
apt-get install --no-install-recommends --quiet --yes $ALL_PACKAGES
sudo apt install --no-install-recommends --quiet --yes $ALL_PACKAGES
echo ::endgroup::

ln -sf /gz/bazel/example/WORKSPACE.example /gz/WORKSPACE
ln -sf /gz/bazel/example/BUILD.bazel.example /gz/BUILD.bazel
ln -sf /gz/bazel/example/bazelrc.example /gz/.bazelrc
ln -sf /gz/bazel/example/bazelproject.example /gz/.bazelproject
ln -sf ${WORKSPACE}/bazel/example/WORKSPACE.example ${WORKSPACE}/WORKSPACE
ln -sf ${WORKSPACE}/bazel/example/BUILD.bazel.example ${WORKSPACE}/BUILD.bazel
ln -sf ${WORKSPACE}/bazel/example/bazelrc.example ${WORKSPACE}/.bazelrc
ln -sf ${WORKSPACE}/bazel/example/bazelproject.example ${WORKSPACE}/.bazelproject

echo ::group::Bazel query
bazel query $BAZEL_ARGS
${BAZEL} query $BAZEL_ARGS
echo ::endgroup::

echo ::group::Bazel build
bazel build $BAZEL_ARGS
${BAZEL} build $BAZEL_ARGS
echo ::endgroup::

echo ::group::Bazel test
bazel test $BAZEL_ARGS
${BAZEL} test $BAZEL_ARGS
echo ::endgroup::

echo ::group::Bazel test
ls -la ${WORKSPACE}
ls -la ${WORKSPACE}/bazel-testlogs
ls -la ${BAZEL_CACHE}
echo ::endgroup::

cp -RL ${WORKSPACE}/bazel-testlogs ${GITHUB_WORKSPACE}/bazel-testlogs
29 changes: 26 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,36 @@ jobs:
runs-on: ubuntu-latest
name: Ubuntu Jammy CI
steps:

- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Login to GHCR
run: echo ${{ secrets.CR_PAT }} | docker login ghcr.io -u $GITHUB_ACTOR --password-stdin
- name: Cache bazel
uses: actions/cache@v3
env:
cache-name: bazel-cache-3
with:
path: |
${{ github.workspace }}/bazel_cache
key: cache-bazel-${{ hashFiles('example/bazel.repos') }}
restore-keys: |
cache-bazel-
- name: Compile and test
uses: ./.github/actions/bazel-ci-jammy
with:
bazel-args: //...

- name: 'Upload Test Logs'
uses: actions/upload-artifact@v3
with:
name: bazel-testlogs
path: ${{ github.workspace }}/bazel-testlogs
retention-days: 5
21 changes: 0 additions & 21 deletions workspace/pkg_config.BUILD.tpl

This file was deleted.

Loading

0 comments on commit 7be81c0

Please sign in to comment.