diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 828124a..dc0a8a2 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -31,8 +31,6 @@ jobs: steps: - name: Checkout uses: actions/checkout@v3 - - name: Create version file - run: git describe --tags --always --dirty > version - name: Select charmhub channel uses: canonical/charming-actions/channel@2.2.0 id: channel diff --git a/charmcraft.yaml b/charmcraft.yaml index c279920..b88501a 100644 --- a/charmcraft.yaml +++ b/charmcraft.yaml @@ -1,3 +1,6 @@ +# Copyright 2020 Omnivector Solutions, LLC. +# See LICENSE file for licensing details. + type: charm bases: - build-on: @@ -13,7 +16,22 @@ bases: - name: centos channel: "7" architectures: [amd64] + parts: charm: build-packages: [git] charm-python-packages: [setuptools] + + # Create a version file and pack it into the charm. This is dynamically generated + # as part of the build process for a charm to ensure that the git revision of the + # charm is always recorded in this version file. + version-file: + plugin: nil + build-packages: + - git + override-build: | + VERSION=$(git -C $CRAFT_PART_SRC/../../charm/src describe --dirty --always) + echo "Setting version to $VERSION" + echo $VERSION > $CRAFT_PART_INSTALL/version + stage: + - version diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index 5184a28..bc80d00 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -19,7 +19,7 @@ import pytest from _pytest.config.argparsing import Parser -from helpers import ETCD, VERSION +from helpers import ETCD from pytest_operator.plugin import OpsTest @@ -45,4 +45,3 @@ async def slurmdbd_charm(ops_test: OpsTest): def pytest_sessionfinish(session, exitstatus) -> None: """Clean up repository after test session has completed.""" pathlib.Path(ETCD).unlink(missing_ok=True) - pathlib.Path(VERSION).unlink(missing_ok=True) diff --git a/tests/integration/helpers.py b/tests/integration/helpers.py index d7938a1..e9f2e3a 100644 --- a/tests/integration/helpers.py +++ b/tests/integration/helpers.py @@ -16,8 +16,6 @@ import logging import pathlib -import shlex -import subprocess from typing import Dict from urllib import request @@ -25,10 +23,6 @@ ETCD = "etcd-v3.5.0-linux-amd64.tar.gz" ETCD_URL = f"https://github.com/etcd-io/etcd/releases/download/v3.5.0/{ETCD}" -VERSION = "version" -VERSION_NUM = subprocess.run( - shlex.split("git describe --always"), stdout=subprocess.PIPE, text=True -).stdout.strip("\n") def get_slurmctld_res() -> Dict[str, pathlib.Path]: @@ -38,10 +32,3 @@ def get_slurmctld_res() -> Dict[str, pathlib.Path]: request.urlretrieve(ETCD_URL, etcd) return {"etcd": etcd} - - -def get_slurmdbd_res() -> None: - """Get slurmdbd charm resources needed for deployment.""" - if not (version := pathlib.Path(VERSION)).exists(): - logger.info(f"Setting resource {VERSION} to value {VERSION_NUM}") - version.write_text(VERSION_NUM) diff --git a/tests/integration/test_charm.py b/tests/integration/test_charm.py index a1c80ec..4929c9b 100644 --- a/tests/integration/test_charm.py +++ b/tests/integration/test_charm.py @@ -22,7 +22,7 @@ import pytest import tenacity -from helpers import get_slurmctld_res, get_slurmdbd_res +from helpers import get_slurmctld_res from pytest_operator.plugin import OpsTest logger = logging.getLogger(__name__) @@ -42,7 +42,6 @@ async def test_build_and_deploy_against_edge( """Test that the slurmdbd charm can stabilize against slurmctld and MySQL.""" logger.info(f"Deploying {SLURMDBD} against {SLURMCTLD} and {DATABASE}") slurmctld_res = get_slurmctld_res() - get_slurmdbd_res() await asyncio.gather( ops_test.model.deploy( str(await slurmdbd_charm),