Skip to content
This repository has been archived by the owner on Aug 9, 2024. It is now read-only.

Commit

Permalink
refactor: Auto-generate version file at packing (#24)
Browse files Browse the repository at this point in the history
Signed-off-by: Jason C. Nucciarone <[email protected]>
  • Loading branch information
NucciTheBoss authored Aug 23, 2023
1 parent f9674c1 commit 3c8859a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
id: channel
Expand Down
14 changes: 14 additions & 0 deletions charmcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,17 @@ 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
3 changes: 1 addition & 2 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from pathlib import Path

import pytest
from helpers import NHC, VERSION
from helpers import NHC
from pytest_operator.plugin import OpsTest


Expand All @@ -43,4 +43,3 @@ async def slurmd_charm(ops_test: OpsTest):
def pytest_sessionfinish(session, exitstatus) -> None:
"""Clean up repository after test session has completed."""
Path(NHC).unlink(missing_ok=True)
Path(VERSION).unlink(missing_ok=True)
8 changes: 0 additions & 8 deletions tests/integration/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,17 @@

import logging
import pathlib
import subprocess
from typing import Dict
from urllib import request

logger = logging.getLogger(__name__)

NHC = "lbnl-nhc-1.4.3.tar.gz"
NHC_URL = f"https://github.com/mej/nhc/releases/download/1.4.3/{NHC}"
VERSION = "version"
VERSION_NUM = subprocess.run(
["git", "describe", "--always"], stdout=subprocess.PIPE, text=True
).stdout.strip("\n")


def get_slurmd_res() -> Dict[str, pathlib.Path]:
"""Get slurmd resources needed for charm deployment."""
if not (version := pathlib.Path(VERSION)).exists():
logger.info(f"Setting resource {VERSION} to value {VERSION_NUM}")
version.write_text(VERSION_NUM)
if not (nhc := pathlib.Path(NHC)).exists():
logger.info(f"Getting resource {NHC} from {NHC_URL}")
request.urlretrieve(NHC_URL, nhc)
Expand Down

0 comments on commit 3c8859a

Please sign in to comment.