Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tiobe Integration #420

Merged
merged 3 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 115 additions & 7 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,39 @@ 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
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
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 @@ -193,12 +220,21 @@ jobs:
sudo apt-get update
sudo apt-get install --no-install-recommends -y libdqlite-dev pkg-config

- name: Build
- name: Download system test dependencies
kadinsayani marked this conversation as resolved.
Show resolved Hide resolved
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: Sideload debug binaries
run: |
set -eux

make

# Binaries to sideload
export MICROCLOUD_DEBUG_PATH=~/go/bin/microcloud
export MICROCLOUDD_DEBUG_PATH=~/go/bin/microcloudd
Expand Down Expand Up @@ -259,7 +295,7 @@ jobs:
export MICROCLOUD_SNAP_CHANNEL="${{ matrix.microcloud }}"

cd test
sudo --preserve-env=DEBUG,GITHUB_ACTIONS,MICROCLOUD_DEBUG_PATH,MICROCLOUDD_DEBUG_PATH,SKIP_VM_LAUNCH,SNAPSHOT_RESTORE,TEST_STORAGE_SOURCE,TESTBED_READY,BASE_OS,LXD_SNAP_CHANNEL,MICROCEPH_SNAP_CHANNEL,MICROOVN_SNAP_CHANNEL,MICROCLOUD_SNAP_CHANNEL ./main.sh setup
sudo --preserve-env=GOCOVERDIR,DEBUG,GITHUB_ACTIONS,MICROCLOUD_DEBUG_PATH,MICROCLOUDD_DEBUG_PATH,SKIP_VM_LAUNCH,SNAPSHOT_RESTORE,TEST_STORAGE_SOURCE,TESTBED_READY,BASE_OS,LXD_SNAP_CHANNEL,MICROCEPH_SNAP_CHANNEL,MICROOVN_SNAP_CHANNEL,MICROCLOUD_SNAP_CHANNEL ./main.sh setup

echo "TESTBED_READY=1" >> "${GITHUB_ENV}"
echo "BASE_OS=${BASE_OS}" >> "${GITHUB_ENV}"
Expand All @@ -273,7 +309,79 @@ 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,BASE_OS,LXD_SNAP_CHANNEL,MICROCEPH_SNAP_CHANNEL,MICROOVN_SNAP_CHANNEL,MICROCLOUD_SNAP_CHANNEL ./main.sh ${{ matrix.suite }}
sudo --preserve-env=GOCOVERDIR,DEBUG,GITHUB_ACTIONS,MICROCLOUD_DEBUG_PATH,MICROCLOUDD_DEBUG_PATH,SKIP_VM_LAUNCH,SNAPSHOT_RESTORE,TEST_STORAGE_SOURCE,TESTBED_READY,BASE_OS,LXD_SNAP_CHANNEL,MICROCEPH_SNAP_CHANNEL,MICROOVN_SNAP_CHANNEL,MICROCLOUD_SNAP_CHANNEL ./main.sh ${{ matrix.suite }}
echo "TIMESTAMP=$(date +%Y%m%d_%H%M%S_%N)" >> "${GITHUB_ENV}"

- name: Upload coverage data
uses: actions/upload-artifact@v4
with:
name: coverage-${{ matrix.go }}-${{ matrix.suite }}-${{ env.TIMESTAMP }}
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.23.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: |
sudo add-apt-repository ppa:dqlite/dev -y --no-update
sudo apt-get update
sudo apt-get install --no-install-recommends -y libdqlite-dev pkg-config
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: 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
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
GOMIN=1.22.7
GOCOVERDIR ?= $(shell go env GOCOVERDIR)

.PHONY: default
default: build

# Build targets.
.PHONY: build
build:
ifeq "$(GOCOVERDIR)" ""
go install -tags=agent -v ./cmd/microcloud
go install -tags=agent -v ./cmd/microcloudd
else
go install -tags=agent -v -cover ./cmd/microcloud
go install -tags=agent -v -cover ./cmd/microcloudd
endif

# Testing targets.
.PHONY: check
check: check-static check-unit check-system

.PHONY: check-unit
check-unit:
ifeq "$(GOCOVERDIR)" ""
go test ./...
else
go test ./... -cover -test.gocoverdir="${GOCOVERDIR}"
endif

.PHONY: check-system
check-system:
Expand Down
3 changes: 3 additions & 0 deletions staticcheck.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Checks being ignored:
roosterfish marked this conversation as resolved.
Show resolved Hide resolved
# ST1005: error strings should not be capitalized
checks = ["inherit", "-ST1005"]
8 changes: 6 additions & 2 deletions test/includes/microcloud.sh
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,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
roosterfish marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -888,6 +888,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 @@ -944,6 +946,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
kadinsayani marked this conversation as resolved.
Show resolved Hide resolved

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
"
fi
}

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