Skip to content

Commit

Permalink
Merge branch 'task/#21677-add-github-actions' into 'integration'
Browse files Browse the repository at this point in the history
Task #21677 -  Add GitHub Actions

See merge request elektrobit/base-os/safu!20
  • Loading branch information
gehwolf committed Mar 13, 2024
2 parents df5eb75 + 0625a72 commit 7e54e7f
Show file tree
Hide file tree
Showing 5 changed files with 202 additions and 4 deletions.
50 changes: 50 additions & 0 deletions .github/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@

# CI with GitHub Actions

## Intentions in using GitHub Actions

We want to test all PRs before mergeing by:
- [x] build test
- [ ] code linting
- [ ] license check
- [x] unit-tests
- [ ] creating a test coverage report
- [ ] smoke tests
- [ ] integration tests
- [ ] running benchmarks
- [ ] automatic upload of new releases

## How to develop GitHub Actions

Find a detailed documentation [here](https://docs.github.com/de/actions)

### Adding Badges with CI status

Paste a link in the form of `![badge](https://github.com/Elektrobit/safu/actions/workflows/build-and-test.yml/badge.svg)` where you want to integrate the badge for the `build-and-test` workflow.

Find an explanation [here](https://docs.github.com/de/actions/monitoring-and-troubleshooting-workflows/adding-a-workflow-status-badge)

### Running GitHub Actions locally

To run the GitHub Actions locally [act](https://github.com/nektos/act) can be used.

The way the Actions are written right now they need an ubuntu image with passwordless sudo.
With that image build under the tag `ubuntu-sudo` the command can be run:

```bash
act -P ubuntu-latest=ubuntu-sudo --pull=false --artifact-server-path=/tmp/artifacts
```
which leaves the build artefacts under `/tmp/artifacts`


### known issues

- job artefacts lose their permissions so executables are no longer set as executable when downloaded in a different job
- a possibility to fix that ist to run `chmod` on all files needing specific permissions.
for example to make all utests in the Release build folder executable:
```bash
for test in $(find build/Release/cmake/ -name "*_utest"); do
chmod +x $test
done
```
- uploading and downloading artefacts with `actions/upload-artifact` & `actions/download-artifact` takes a very long time, especially with artefacts containing a lot of (small) files.
56 changes: 56 additions & 0 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@

name: Build and Test
on: [ push, workflow_dispatch, pull_request ]

jobs:
build-and-test:
runs-on: ubuntu-latest
strategy:
matrix:
build_type: [Debug, Release]
steps:
- uses: actions/checkout@v4
- name: Install Build Dependencies
run: |
sudo apt-get update
sudo apt-get install -y \
build-essential \
cmake \
curl \
git \
libcmocka-dev \
libcurl4-openssl-dev \
libesmtp-dev \
libjson-c-dev \
liblog4c-dev \
libmnl-dev \
libsqlite3-0 \
libsqlite3-dev \
libssl-dev \
ninja-build \
pkg-config \
python-is-python3 \
python3-pip \
python3-venv \
sqlite3
- name: checkout and build dependecies
run: ci/install_deps.py -G
- name: Build ${{ matrix.build_type }}
env:
DESTDIR: ${{ github.workspace }}/build/${{ matrix.build_type }}/dist
run: |
cmake -B ./build/${{ matrix.build_type }}/cmake . -DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
make -C ./build/${{ matrix.build_type }}/cmake all install
- name: save build artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.build_type }}-build
path: build/${{ matrix.build_type}}/dist
- name: run unit tests (${{ matrix.build_type }})
run: ci/run_utest.sh ${{ matrix.build_type }}
- name: save ${{ matrix.build_type }} unit test report
uses: actions/upload-artifact@v4
if: always()
with:
name: ${{ matrix.build_type }}-test-report
path: build/${{ matrix.build_type }}/result/unit_test/
88 changes: 88 additions & 0 deletions .github/workflows/build-documentation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@

name: Build Documentation
on: [ push, workflow_dispatch, pull_request ]

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write

# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: "pages"
cancel-in-progress: false

jobs:
documentation:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Build Dependencies
run: |
sudo apt-get update
sudo apt-get install -y \
curl \
expat \
git \
locales \
net-tools \
netcat \
nodejs \
pandoc \
plantuml \
python-is-python3 \
python3-pip \
python3-venv \
wget \
- name: setup python Virtual env
run: |
python -m venv ${{ github.workspace }}/.venv
. ${{ github.workspace }}/.venv/bin/activate
python -m pip install \
beautifulsoup4==4.12.2 \
clang==16.0.1.1 \
sphinx==7.2.6 \
sphinx-c-autodoc==1.3.0 \
sphinx-copybutton==0.5.2 \
sphinx-favicon==1.0.1 \
sphinxcontrib-programoutput==0.17
- name: install libcland 16 for sphinx c autodoc
# needet as long as libclang 16 isn't packaged in ubuntu-latest
run: |
wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | sudo tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc
echo "" | sudo tee -a /etc/apt/sources.list
echo "# for llvm 16 packages" | sudo tee -a /etc/apt/sources.list
echo "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-16 main" | sudo tee -a /etc/apt/sources.list
echo "deb-src http://apt.llvm.org/jammy/ llvm-toolchain-jammy-16 main" | sudo tee -a /etc/apt/sources.list
cat /etc/apt/sources.list
sudo apt-get update
sudo apt-get install -y libclang1-16
sudo ln -s /usr/lib/x86_64-linux-gnu/libclang-16.so.1 /usr/lib/libclang-16.so
- name: Build Documentation
run: ci/build_doc.sh
env:
SPHINX_VENV: "${{ github.workspace }}/.venv"
- name: pack documentation for GitHub pages
run: |
tar \
--dereference --hard-dereference \
--directory "${{ github.workspace }}/build/doc/" \
-cvf "$RUNNER_TEMP/artifact.tar" \
.
- name: save documentation
uses: actions/upload-artifact@v4
with:
name: github-pages
path: ${{ runner.temp }}/artifact.tar
if-no-files-found: error

publish-gh-pages:
runs-on: ubuntu-latest
if: ${{ github.ref_name == 'main' }}
needs: documentation
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
10 changes: 7 additions & 3 deletions ci/run_utest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@ if [ ! -d "$CMAKE_BUILD_DIR" ]; then
"$CMD_PATH/build.sh" "$BUILD_TYPE"
fi

cd "$CMAKE_BUILD_DIR"
ctest --output-on-failure --force-new-ctest-process --verbose --output-junit junit.xml --no-compress-output

mkdir -p "$RESULT_DIR/unit_test"
cd "$RESULT_DIR/unit_test"
ctest --output-on-failure --force-new-ctest-process --verbose \
--output-junit "$RESULT_DIR/unit_test/junit.xml" \
--no-compress-output \
--output-log "$RESULT_DIR/unit_test/Test.log" \
--test-dir "$BUILD_DIR/cmake"

TEST_LOG_FILE="$CMAKE_BUILD_DIR/Testing/Temporary/LastTest.log"
SKIPPED_TESTS=$(sed -n -e '/^# skip/p' "$TEST_LOG_FILE" | wc -l)
Expand Down
2 changes: 1 addition & 1 deletion cmake/project.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# SPDX-License-Identifier: MIT
set(SAFU_VERSION 0.52.3)
set(SAFU_VERSION 0.52.4)

# Attention: Aside from the version, as many things as possible in this file
# should be put into functions, as this solves potential issues with commands
Expand Down

0 comments on commit 7e54e7f

Please sign in to comment.