Skip to content

Tests

Tests #883

Workflow file for this run

name: Tests
on:
pull_request:
push:
workflow_dispatch:
schedule:
- cron: '0 0 * * *' # Test TICS daily
env:
GOCOVERDIR: ${{ ( github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' ) && '/home/runner/work/microcluster/microcluster/cover' || '' }}
permissions:
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
code-tests:
env:
CGO_CFLAGS: -I/home/runner/go/deps/dqlite/include/
CGO_LDFLAGS: -L/home/runner/go/deps/dqlite/.libs/
LD_LIBRARY_PATH: /home/runner/go/deps/dqlite/.libs/
CGO_LDFLAGS_ALLOW: (-Wl,-wrap,pthread_create)|(-Wl,-z,now)
name: Code
runs-on: ubuntu-22.04
strategy:
matrix:
go: ["1.22.x"]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Dependency Review
uses: actions/dependency-review-action@v4
if: github.event_name == 'pull_request'
- name: Install Go (${{ matrix.go }})
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go }}
- name: Check compatibility with min Go version (${{ matrix.go }})
run: |
set -eux
GOMIN="$(sed -n 's/^GOMIN=\([0-9.]\+\)$/\1/p' Makefile)"
go mod tidy -go="${GOMIN}"
- name: Install dependencies
run: |
set -eux
sudo apt-get update
sudo apt-get install --no-install-recommends -y \
shellcheck pkg-config autoconf automake libtool make libuv1-dev libsqlite3-dev liblz4-dev
- name: Build dependencies
run: |
set -eux
make deps
- name: Run static analysis
run: |
set -eux
make check-static
make -C example check-static
- name: Make GOCOVERDIR
run: mkdir -p "${GOCOVERDIR}"
if: env.GOCOVERDIR != ''
- name: Unit tests (all)
run: |
set -eux
make check-unit
make -C example check-unit
- name: Upload coverage data
uses: actions/upload-artifact@v4
with:
name: coverage-unit
path: ${{env.GOCOVERDIR}}
if: env.GOCOVERDIR != ''
- name: Example system tests
run: |
set -eux
make -C example
cd example/test
CLUSTER_VERBOSE=1 ./main.sh
- name: Upload coverage data
uses: actions/upload-artifact@v4
with:
name: coverage-example-system
path: ${{env.GOCOVERDIR}}
if: env.GOCOVERDIR != ''
- name: Upload TIOBE TICS dependencies
uses: actions/upload-artifact@v4
with:
name: system-tiobe-tics-deps
path: |
/home/runner/go/bin/microd
/home/runner/go/bin/microctl
/home/runner/go/bin/dqlite
retention-days: 1
tics:
name: Tiobe TICS
runs-on: ubuntu-22.04
needs: code-tests
if: ${{ ( github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' ) && github.ref_name == 'v3' && github.repository == 'canonical/microcluster' }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
# A non-shallow clone is needed for the Differential ShellCheck
fetch-depth: 0
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: 1.22.x
- name: Download coverage data
uses: actions/download-artifact@v4
with:
pattern: coverage-*
path: ${{env.GOCOVERDIR}}
merge-multiple: true
- name: Download TIOBE TICS dependencies
uses: actions/download-artifact@v4
with:
name: system-tiobe-tics-deps
merge-multiple: true
path: /home/runner/go/bin
- name: Install dependencies
run: |
go install github.com/axw/gocov/gocov@latest
go install github.com/AlekSi/gocov-xml@latest
go install honnef.co/go/tools/cmd/staticcheck@latest
- name: Convert coverage files
run: |
go tool covdata textfmt -i="${GOCOVERDIR}" -o "${GOCOVERDIR}"/coverage.out
gocov convert "${GOCOVERDIR}"/coverage.out > "${GOCOVERDIR}"/coverage.json
gocov-xml < "${GOCOVERDIR}"/coverage.json > "${GOCOVERDIR}"/coverage-go.xml
go tool covdata percent -i="${GOCOVERDIR}"
- name: Run TICS
uses: tiobe/tics-github-action@v3
with:
mode: qserver
project: microcluster
viewerUrl: https://canonical.tiobe.com/tiobeweb/TICS/api/cfg?name=default
branchdir: ${{ github.workspace }}
ticsAuthToken: ${{ secrets.TICS_AUTH_TOKEN }}
installTics: true
calc: ALL
tmpdir: /tmp/tics