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 (#13)
Browse files Browse the repository at this point in the history
This commit removes the version file generation
job step from the release workflow, removes
the version file generation utilities from the
integration tests, and modifies charmcraft.yaml
so that the version file will be automatically
generated when the slurmrestd charm is packed.

Signed-off-by: Jason C. Nucciarone <[email protected]>
  • Loading branch information
NucciTheBoss authored Aug 4, 2023
1 parent 1f34bd7 commit 96a2c6a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 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
18 changes: 18 additions & 0 deletions charmcraft.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright 2020 Omnivector Solutions, LLC.
# See LICENSE file for licensing details.

type: charm
bases:
- build-on:
Expand All @@ -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
3 changes: 1 addition & 2 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import pytest
from _pytest.config.argparsing import Parser
from helpers import ETCD, NHC, VERSION
from helpers import ETCD, NHC
from pytest_operator.plugin import OpsTest


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

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

Expand All @@ -27,17 +25,10 @@
ETCD_URL = f"https://github.com/etcd-io/etcd/releases/download/v3.5.0/{ETCD}"
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(
shlex.split("git describe --always"), stdout=subprocess.PIPE, text=True
).stdout.strip("\n")


def get_slurmctld_res() -> Dict[str, pathlib.Path]:
"""Get slurmctld 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 (etcd := pathlib.Path(ETCD)).exists():
logger.info(f"Getting resource {ETCD} from {ETCD_URL}")
request.urlretrieve(ETCD_URL, etcd)
Expand Down

0 comments on commit 96a2c6a

Please sign in to comment.