Skip to content

Fix tests

Fix tests #3

name: third-party-applications
on:
push:
branches:
- master
tags:
- 'v*.*.*'
jobs:
docker-image:
strategy:
matrix:
name: [lamp, sink, doorbell, fridge, oven]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust stable
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
- name: Install cross
env:
CROSS_LINK: https://github.com/cross-rs/cross/releases/download
CROSS_VERSION: v0.2.5
CROSS_BINARY: cross-x86_64-unknown-linux-gnu.tar.gz
run: |
curl -L "$CROSS_LINK/$CROSS_VERSION/$CROSS_BINARY" |
tar xz -C $HOME/.cargo/bin
- name: Install manifest
env:
MANIFEST_LINK: https://github.com/sifis-home/manifest/releases/download
MANIFEST_VERSION: v0.2.0
MANIFEST_BINARY: manifest-0.2.0-x86_64-unknown-linux-gnu.tar.gz
run: |
curl -L "$MANIFEST_LINK/$MANIFEST_VERSION/$MANIFEST_BINARY" |
tar xz -C $HOME/.cargo/bin
- name: Install grcov
env:
GRCOV_LINK: https://github.com/mozilla/grcov/releases/download
GRCOV_VERSION: v0.8.13
run: |
curl -L "$GRCOV_LINK/$GRCOV_VERSION/grcov-x86_64-unknown-linux-musl.tar.bz2" |
tar xj -C $HOME/.cargo/bin
- name: Install llvm-tools-preview
run: |
rustup component add llvm-tools-preview
- name: Install the mock server
run:
cargo install --git https://github.com/sifis-home/sifis-api#v0.1.0
- name: Run tests
env:
RUSTFLAGS: "-Cinstrument-coverage"
LLVM_PROFILE_FILE: "${{ matrix.name }}-%p-%m.profraw"
run: |
cargo test --manifest-path ${{ matrix.name }}/Cargo.toml --verbose
- name: Get total coverage
run: |
grcov . --binary-path ./target/debug/ -s . -t covdir --branch \
--token YOUR_COVDIR_TOKEN --ignore-not-existing --ignore "/*" \
--ignore "../*" -o covdir.json
- name: Save code coverage value
id: coverage
run: |
# Retrieve code coverage associated to the repository
FLOAT_COVERAGE=$(jq '.coveragePercent' covdir.json)
# Round the float value to the nearest value
COVERAGE_OUTPUT=$(printf "%.0f" $FLOAT_COVERAGE)
# Save code coverage value in an environment variable
echo "value=$COVERAGE_OUTPUT" >> $GITHUB_OUTPUT
- name: Build x86_64
run: |
cross clean --manifest-path ${{ matrix.name }}/Cargo.toml
cross build --manifest-path ${{ matrix.name }}/Cargo.toml --release --target x86_64-unknown-linux-musl
mkdir -p x86_64-unknown-linux-musl
cp target/x86_64-unknown-linux-musl/release/${{ matrix.name }} x86_64-unknown-linux-musl/
- name: Produce manifest
id: manifest
run: |
# Produce manifest
manifest -b target/x86_64-unknown-linux-musl/release/${{ matrix.name }} -l 0.1 -o ${{ matrix.name}}.json
# Save json in a temporary variable
MANIFEST_JSON=$(jq -c '.' ${{ matrix.name}}.json)
# Save json in an environment variable
echo "value=$MANIFEST_JSON" >> $GITHUB_OUTPUT
- name: Build aarch64
run: |
# cross have problems when you change the target see
# https://github.com/cross-rs/cross/issues/724
cross clean --manifest-path ${{ matrix.name }}/Cargo.toml
cross build --manifest-path ${{ matrix.name }}/Cargo.toml --release --target aarch64-unknown-linux-musl
mkdir -p aarch64-unknown-linux-musl
cp target/aarch64-unknown-linux-musl/release/${{ matrix.name }} aarch64-unknown-linux-musl/
- name: Get tag
id: tag
run: |
if [ ${GITHUB_REF} == "refs/heads/master" ]
then
echo "value=master" >> $GITHUB_OUTPUT
else
ONLY_VERSION=$(echo $GITHUB_REF | sed -E 's/refs\/tags\/v//')
echo "value=$ONLY_VERSION" >> $GITHUB_OUTPUT
fi
- name: Login to GitHub container registry (ghcr.io)
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push amd64
uses: docker/build-push-action@v4
with:
context: x86_64-unknown-linux-musl
file: docker/Dockerfile-amd64
platforms: linux/amd64
push: true
tags: |
ghcr.io/sifis-home/${{ matrix.name }}-amd64:${{ steps.tag.outputs.value }}
ghcr.io/sifis-home/${{ matrix.name }}-amd64:latest
labels: |
org.opencontainers.image.description=A Sifis-Home ${{ matrix.name }} image for amd64.
software.quality=${{ steps.coverage.outputs.value }}
manifest=${{ steps.manifest.outputs.value }}
type=third-party-application
- name: Build and push arm64v8
uses: docker/build-push-action@v4
with:
context: aarch64-unknown-linux-musl
file: docker/Dockerfile-arm64
platforms: linux/arm64
push: true
tags: |
ghcr.io/sifis-home/${{ matrix.name }}-arm64:${{ steps.tag.outputs.value }}
ghcr.io/sifis-home/${{ matrix.name }}-arm64:latest
labels: |
org.opencontainers.image.description=A Sifis-Home ${{ matrix.name }} image for arm64.
software.quality=${{ steps.coverage.outputs.value }}
manifest=${{ steps.manifest.outputs.value }}
type=third-party-application