Skip to content

Resolve test flakiness #1879

Resolve test flakiness

Resolve test flakiness #1879

name: Build and Test Astarte Apps
on:
# Run when pushing to stable branches
push:
paths:
- 'apps/**'
- '.github/workflows/astarte-apps-build-workflow.yaml'
branches:
- 'master'
- 'release-*'
# Run on branch/tag creation
create:
# Run on pull requests matching apps
pull_request:
paths:
- 'apps/**'
- '.github/workflows/astarte-apps-build-workflow.yaml'
env:
elixir_version: "1.14.5"
otp_version: "25.3.2"
jobs:
test-dialyzer:
name: Check Dialyzer
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
app:
- astarte_appengine_api
- astarte_data_updater_plant
- astarte_housekeeping
- astarte_housekeeping_api
- astarte_pairing
- astarte_pairing_api
- astarte_realm_management
- astarte_realm_management_api
- astarte_trigger_engine
env:
MIX_ENV: ci
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v1
with:
path: apps/${{ matrix.app }}/deps
key: ${{ runner.os }}-dialyzer-mix-${{ env.otp_version }}-${{ env.elixir_version }}-${{ matrix.app }}-${{ hashFiles(format('{0}{1}{2}{3}', github.workspace, '/apps/', matrix.app, '/mix.lock')) }}
restore-keys: |
${{ runner.os }}-dialyzer-mix-${{ env.otp_version }}-${{ env.elixir_version }}-${{ matrix.app }}-
- uses: actions/cache@v1
with:
path: apps/${{ matrix.app }}/_build
key: ${{ runner.os }}-dialyzer-_build-${{ env.otp_version }}-${{ env.elixir_version }}-${{ matrix.app }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-dialyzer-_build-${{ env.otp_version }}-${{ env.elixir_version }}-${{ matrix.app }}-
- uses: actions/cache@v1
id: plt_cache
with:
path: apps/${{ matrix.app }}/dialyzer_cache
key: ${{ runner.os }}-dialyzer_cache-${{ env.otp_version }}-${{ env.elixir_version }}-${{ matrix.app }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-dialyzer_cache-${{ env.otp_version }}-${{ env.elixir_version }}-${{ matrix.app }}-
- uses: erlef/setup-beam@v1.15
with:
otp-version: ${{ env.otp_version }}
elixir-version: ${{ env.elixir_version }}
- name: Install Dependencies
working-directory: ./apps/${{ matrix.app }}
run: mix deps.get
- name: Create PLTs dir
working-directory: ./apps/${{ matrix.app }}
if: ${{ steps.plt_cache.outputs.cache-hit != 'true' }}
run: mkdir -p dialyzer_cache && mix dialyzer --plt
- name: Run dialyzer
working-directory: ./apps/${{ matrix.app }}
# FIXME: This should be set to fail when dialyzer issues are fixed
run: mix dialyzer || exit 0
test-coverage:
name: Build and Test
runs-on: ubuntu-22.04
# Wait for Dialyzer to give it a go before building
needs:
- test-dialyzer
strategy:
fail-fast: false
matrix:
app:
- astarte_appengine_api
- astarte_data_updater_plant
- astarte_housekeeping
- astarte_housekeeping_api
- astarte_pairing
- astarte_pairing_api
- astarte_realm_management
- astarte_realm_management_api
- astarte_trigger_engine
database:
- "cassandra:3.11.15"
- "scylladb/scylla:5.2.2"
rabbitmq:
- "rabbitmq:3.12.0-management"
services:
rabbitmq:
image: ${{ matrix.rabbitmq }}
ports:
- 5672:5672
- 15672:15672
database:
image: ${{ matrix.database }}
ports:
- 9042:9042
cfssl:
image: ispirata/docker-alpine-cfssl-autotest:astarte
ports:
- 8080/tcp
env:
MIX_ENV: test
CASSANDRA_NODES: localhost
RABBITMQ_HOST: localhost
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v1
with:
path: apps/${{ matrix.app }}/deps
key: ${{ runner.os }}-apps-mix-${{ env.otp_version }}-${{ env.elixir_version }}-${{ matrix.app }}-${{ hashFiles(format('{0}{1}{2}{3}', github.workspace, '/apps/', matrix.app, '/mix.lock')) }}
restore-keys: |
${{ runner.os }}-apps-mix-${{ env.otp_version }}-${{ env.elixir_version }}-${{ matrix.app }}-
# Caching _build is causing tests to fail rather unexpectedly.
# TODO try to undestand why and restore the cache step.
# - uses: actions/cache@v1
# with:
# path: apps/${{ matrix.app }}/_build
# key: ${{ runner.os }}-apps-_build-${{ env.otp_version }}-${{ env.elixir_version }}-${{ matrix.app }}-${{ github.sha }}
# restore-keys: |
# ${{ runner.os }}-apps-_build-${{ env.otp_version }}-${{ env.elixir_version }}-${{ matrix.app }}-
- uses: erlef/setup-beam@v1.15
with:
otp-version: ${{ env.otp_version }}
elixir-version: ${{ env.elixir_version }}
- name: Install Dependencies
working-directory: ./apps/${{ matrix.app }}
run: mix deps.get
- name: Check formatting
working-directory: ./apps/${{ matrix.app }}
run: mix format --check-formatted
- name: Setup Events Exchange
if: matrix.app == 'astarte_appengine_api'
run: |
wget http://guest:guest@localhost:15672/cli/rabbitmqadmin -O rabbitmqadmin
chmod +x ./rabbitmqadmin
./rabbitmqadmin declare exchange name=astarte_events type=direct
rm rabbitmqadmin
- name: Compile
working-directory: ./apps/${{ matrix.app }}
run: mix do compile
- uses: actions/setup-node@v1
with:
node-version: '10.x'
- name: Wait for Cassandra
run: |
npm install -g wait-for-cassandra
wait-for-cassandra -T 120000 -h $CASSANDRA_NODES
- name: Test and Coverage
working-directory: ./apps/${{ matrix.app }}
run: mix coveralls.json --exclude wip -o coverage_results
env:
CFSSL_API_URL: http://localhost:${{ job.services.cfssl.ports[8080] }}
- name: Upload Coverage Results to CodeCov
# Don't upload more than once per component
if: matrix.database == 'scylladb/scylla:5.2.2'
working-directory: ./apps/${{ matrix.app }}
run: bash <(curl -s https://codecov.io/bash)