Skip to content

Commit

Permalink
github: Add tiobe tics job for system and unit test coverage
Browse files Browse the repository at this point in the history
Signed-off-by: Kadin Sayani <kadin.sayani@canonical.com>
  • Loading branch information
kadinsayani committed Oct 18, 2024
1 parent 556a4d7 commit 519061b
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 7 deletions.
117 changes: 112 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ on:
branches:
- main
pull_request:
workflow_dispatch:

env:
GOCOVERDIR: ${{ ( github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' ) && '/home/runner/work/microcloud/microcloud/cover' || '' }}

permissions:
contents: read
Expand Down Expand Up @@ -73,16 +77,40 @@ jobs:
- name: Run static analysis
run: make check-static

- name: Make GOCOVERDIR
run: mkdir -p "${GOCOVERDIR}"
if: env.GOCOVERDIR != ''

- name: Unit tests
run: make check-unit
run: |
set -eux
sudo --preserve-env=PATH,GOPATH,GOCOVERDIR make check-unit
- name: Upload coverage data
uses: actions/upload-artifact@v4
with:
name: coverage-unit
path: ${{env.GOCOVERDIR}}
if: env.GOCOVERDIR != ''

- name: Upload system test dependencies
uses: actions/upload-artifact@v4
with:
name: system-test-deps
path: |
/home/runner/go/bin/microcloud
/home/runner/go/bin/microcloudd
/home/runner/go/bin/dqlite
retention-days: 1

system-tests:
env:
DEBUG: "1"
SKIP_VM_LAUNCH: "1"
SNAPSHOT_RESTORE: "1"
name: System
runs-on: GitHubMicrocloud
runs-on: GitHubMicrocloud
needs: code-tests
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -166,11 +194,22 @@ jobs:
sudo apt-get update
sudo apt-get install --no-install-recommends -y libdqlite-dev pkg-config
- name: Download system test dependencies
uses: actions/download-artifact@v4
with:
name: system-test-deps
merge-multiple: true
path: /home/runner/go/bin

- name: Make GOCOVERDIR
run: mkdir -p "${GOCOVERDIR}"
if: env.GOCOVERDIR != ''

- name: Build
run: |
set -eux
make
sudo --preserve-env=PATH,GOPATH,GOCOVERDIR make
# Binaries to sideload
export MICROCLOUD_DEBUG_PATH=~/go/bin/microcloud
Expand Down Expand Up @@ -225,15 +264,83 @@ jobs:
set -eux
chmod +x ~
cd test
sudo --preserve-env=DEBUG,GITHUB_ACTIONS,MICROCLOUD_DEBUG_PATH,MICROCLOUDD_DEBUG_PATH,SKIP_VM_LAUNCH,SNAPSHOT_RESTORE,TEST_STORAGE_SOURCE,TESTBED_READY ./main.sh setup
sudo --preserve-env=PATH,GOPATH,GOCOVERDIR,DEBUG,GITHUB_ACTIONS,MICROCLOUD_DEBUG_PATH,MICROCLOUDD_DEBUG_PATH,SKIP_VM_LAUNCH,SNAPSHOT_RESTORE,TEST_STORAGE_SOURCE,TESTBED_READY ./main.sh setup
echo "TESTBED_READY=1" >> "${GITHUB_ENV}"
- name: "Run system tests (${{ matrix.go }}, ${{ matrix.suite }})"
run: |
set -eux
chmod +x ~
cd test
sudo --preserve-env=DEBUG,GITHUB_ACTIONS,MICROCLOUD_DEBUG_PATH,MICROCLOUDD_DEBUG_PATH,SKIP_VM_LAUNCH,SNAPSHOT_RESTORE,TEST_STORAGE_SOURCE,TESTBED_READY ./main.sh ${{ matrix.suite }}
sudo --preserve-env=PATH,GOPATH,GOCOVERDIR,DEBUG,GITHUB_ACTIONS,MICROCLOUD_DEBUG_PATH,MICROCLOUDD_DEBUG_PATH,SKIP_VM_LAUNCH,SNAPSHOT_RESTORE,TEST_STORAGE_SOURCE,TESTBED_READY ./main.sh ${{ matrix.suite }}
- name: Upload coverage data
uses: actions/upload-artifact@v4
with:
name: coverage-${{ matrix.go }}-${{ matrix.suite }}
path: ${{ env.GOCOVERDIR }}
if: env.GOCOVERDIR != ''

tics:
name: Tiobe TICS
runs-on: ubuntu-22.04
needs: system-tests
if: ${{ ( github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' ) && github.ref_name == 'main' && github.repository == 'canonical/microcloud' }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
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: Extract coverage data
run: |
find ${{ env.GOCOVERDIR }}/micro*/cover/ -type f -exec mv {} ${{ env.GOCOVERDIR }} \;
rm -rf ${{ env.GOCOVERDIR }}/micro*
ls -la ${{ env.GOCOVERDIR }}
- name: Download system test dependencies
uses: actions/download-artifact@v4
with:
name: system-test-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}"/extracted-coverage -o "${GOCOVERDIR}"/extracted-coverage/coverage.out
gocov convert "${GOCOVERDIR}"/extracted-coverage/coverage.out > "${GOCOVERDIR}"/extracted-coverage/coverage.json
gocov-xml < "${GOCOVERDIR}"/extracted-coverage/coverage.json > "${GOCOVERDIR}"/extracted-coverage/coverage-go.xml
go tool covdata percent -i="${GOCOVERDIR}"/extracted-coverage
- name: Run TICS
uses: tiobe/tics-github-action@v3
with:
mode: qserver
project: microcloud
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

documentation-checks:
uses: canonical/documentation-workflows/.github/workflows/documentation-checks.yaml@main
Expand Down
8 changes: 6 additions & 2 deletions test/includes/microcloud.sh
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,8 @@ set_debug_binaries() {
lxc exec "${name}" -- rm -f /var/snap/microcloud/common/microcloudd.debug
lxc exec "${name}" -- rm -f /var/snap/microcloud/common/microcloud.debug

lxc file push --quiet "${MICROCLOUDD_DEBUG_PATH}" "${name}"/var/snap/microcloud/common/microcloudd.debug
lxc file push --quiet "${MICROCLOUD_DEBUG_PATH}" "${name}"/var/snap/microcloud/common/microcloud.debug
lxc file push --quiet "${MICROCLOUDD_DEBUG_PATH}" "${name}"/var/snap/microcloud/common/microcloudd.debug --mode 0755
lxc file push --quiet "${MICROCLOUD_DEBUG_PATH}" "${name}"/var/snap/microcloud/common/microcloud.debug --mode 0755

lxc exec "${name}" -- systemctl restart snap.microcloud.daemon || true
fi
Expand Down Expand Up @@ -874,6 +874,8 @@ cluster_reset() {

# reset_systems: Concurrently or sequentially resets the specified number of systems.
reset_systems() {
collect_go_cover_files

if [ "${SNAPSHOT_RESTORE}" = 1 ]; then
# shellcheck disable=SC2048,SC2086
restore_systems ${*}
Expand Down Expand Up @@ -930,6 +932,8 @@ reset_systems() {
restore_systems() {
echo "::group::restore_systems"

collect_go_cover_files

num_vms=3
num_disks=3
num_extra_ifaces=1
Expand Down
14 changes: 14 additions & 0 deletions test/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ run_test() {
${TEST_CURRENT}
END_TIME="$(date +%s)"

collect_go_cover_files

echo "::notice::==> TEST DONE: ${TEST_CURRENT_DESCRIPTION} ($((END_TIME - START_TIME))s)"
}

Expand All @@ -208,6 +210,18 @@ testbed_setup() {
echo "::notice::==> SETUP DONE ($((END_TIME - START_TIME))s)"
}

collect_go_cover_files() {
if [ -n "${GOCOVERDIR}" ]; then
echo "==> Collecting Go coverage files"
lxc list -c n -f csv | xargs --no-run-if-empty -I {} sh -c '
container_name="{}"
timestamp=$(date +%Y%m%d_%H%M%S_%N)
destination="${GOCOVERDIR}/${container_name}_${timestamp}"
lxc file pull -r "${container_name}/var/snap/microcloud/common/data/cover" "${destination}" || true
'

Check warning

Code scanning / shellcheck

SC2016 Warning test

Expressions don't expand in single quotes, use double quotes for that.
fi
}

# test groups
run_add_tests() {
run_test test_add_interactive "add interactive"
Expand Down

0 comments on commit 519061b

Please sign in to comment.