Skip to content

Charmcraft test

Charmcraft test #2262

Workflow file for this run

# Copyright 2022 Canonical Ltd.
# See LICENSE file for licensing details.
name: Tests
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
on:
pull_request:
schedule:
- cron: '53 0 * * *' # Daily at 00:53 UTC
# Triggered on push to branch "main" by .github/workflows/release.yaml
workflow_call:
outputs:
artifact-prefix:
description: build_charm.yaml `artifact-prefix` output
value: ${{ jobs.build.outputs.artifact-prefix }}
jobs:
lint:
name: Lint
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install tox & poetry
run: |
pipx install tox
pipx install poetry
- name: Run linters
run: tox run -e lint
unit-test:
name: Unit test charm
runs-on: ubuntu-22.04 # TODO: use ubuntu-latest after fixing pathlib issue on python 3.12
timeout-minutes: 20
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install tox & poetry
run: |
pipx install tox
pipx install poetry
- name: Run tests
run: tox run -e unit
lib-check:
name: Check libraries
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- run: |
# Workaround for https://github.com/canonical/charmcraft/issues/1389#issuecomment-1880921728
touch requirements.txt
- name: Check libs
uses: canonical/charming-actions/[email protected]
with:
charmcraft-channel: latest/candidate # TODO: remove after charmcraft 3.3 stable release
credentials: "${{ secrets.CHARMHUB_TOKEN }}"
github-token: "${{ secrets.GITHUB_TOKEN }}"
use-labels: false
fail-build: ${{ github.event_name == 'pull_request' }}
build:
name: Build charm
uses: canonical/data-platform-workflows/.github/workflows/[email protected]
with:
charmcraft-snap-channel: latest/candidate # TODO: remove after charmcraft 3.3 stable release
collect-integration-tests:
name: Collect integration test spread jobs
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up environment
run: sudo snap install charmcraft --classic --channel latest/candidate
- name: Collect spread jobs
id: collect-jobs
shell: python
run: |
import json
import os
import subprocess
jobs = (
subprocess.run(
["charmcraft", "test", "--list", "github-ci"], capture_output=True, check=True, text=True
)
.stdout.strip()
.split("\n")
)
output = f"jobs={json.dumps(jobs)}"
print(output)
with open(os.environ["GITHUB_OUTPUT"], "a") as file:
file.write(output)
outputs:
jobs: ${{ steps.collect-jobs.outputs.jobs }}
integration-test:
strategy:
fail-fast: false
matrix:
spread-job: ${{ fromJSON(needs.collect-integration-tests.outputs.jobs) }}
name: Spread ${{ matrix.spread-job }}
needs:
- collect-integration-tests
runs-on: ubuntu-latest
timeout-minutes: 200 # TODO
steps:
- name: Checkout
timeout-minutes: 3
uses: actions/checkout@v4
- name: Set up environment
timeout-minutes: 5
run: sudo snap install charmcraft --classic --channel latest/candidate
- name: Run spread job
timeout-minutes: 120
run: charmcraft test '${{ matrix.spread-job }}'