|
| 1 | +name: Test Version Management |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main, develop ] |
| 6 | + tags: |
| 7 | + - 'v*' |
| 8 | + pull_request: |
| 9 | + branches: [ main ] |
| 10 | + |
| 11 | +jobs: |
| 12 | + test-version: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + strategy: |
| 15 | + matrix: |
| 16 | + python-version: ['3.10', '3.11', '3.12', '3.13'] |
| 17 | + |
| 18 | + steps: |
| 19 | + - name: Checkout repository |
| 20 | + uses: actions/checkout@v4 |
| 21 | + with: |
| 22 | + fetch-depth: 0 # Full history for version tools that use git |
| 23 | + |
| 24 | + - name: Set up Python ${{ matrix.python-version }} |
| 25 | + uses: actions/setup-python@v5 |
| 26 | + with: |
| 27 | + python-version: ${{ matrix.python-version }} |
| 28 | + |
| 29 | + - name: Install package and dev dependencies |
| 30 | + run: | |
| 31 | + python -m pip install --upgrade pip |
| 32 | + pip install -e .[dev] |
| 33 | +
|
| 34 | + - name: Test version can be imported |
| 35 | + run: | |
| 36 | + python -c "import cli; print(f'Package version: {cli.__version__}')" |
| 37 | +
|
| 38 | + - name: Test importlib.metadata version access |
| 39 | + run: | |
| 40 | + python -c "import importlib.metadata; version = importlib.metadata.version('cli'); print(f'Metadata version: {version}')" |
| 41 | +
|
| 42 | + - name: Verify version consistency |
| 43 | + run: | |
| 44 | + # Get version from package import |
| 45 | + IMPORT_VERSION=$(python -c "import cli; print(cli.__version__)") |
| 46 | + # Get version from metadata |
| 47 | + METADATA_VERSION=$(python -c "import importlib.metadata; print(importlib.metadata.version('cli'))") |
| 48 | +
|
| 49 | + echo "Import version: $IMPORT_VERSION" |
| 50 | + echo "Metadata version: $METADATA_VERSION" |
| 51 | +
|
| 52 | + if [ "$IMPORT_VERSION" != "$METADATA_VERSION" ]; then |
| 53 | + echo "ERROR: Version mismatch between import and metadata!" |
| 54 | + exit 1 |
| 55 | + fi |
| 56 | +
|
| 57 | + echo "SUCCESS: Version consistency verified" |
| 58 | +
|
| 59 | +
|
| 60 | + - name: Run type checking and formatting |
| 61 | + run: | |
| 62 | + mypy cli |
| 63 | + black --check cli |
| 64 | +
|
| 65 | + # Only run on tag pushes to verify git tag matches version |
| 66 | + - name: Verify version matches git tag |
| 67 | + if: startsWith(github.ref, 'refs/tags/v') |
| 68 | + run: | |
| 69 | + # Extract version from git tag (e.g., 'v1.2.3' -> '1.2.3') |
| 70 | + TAG_VERSION=${GITHUB_REF#refs/tags/v} |
| 71 | + # Get version from installed package |
| 72 | + INSTALLED_VERSION=$(python -c "import importlib.metadata; print(importlib.metadata.version('cli'))") |
| 73 | +
|
| 74 | + echo "Git tag version: $TAG_VERSION" |
| 75 | + echo "Installed version: $INSTALLED_VERSION" |
| 76 | +
|
| 77 | + if [ "$TAG_VERSION" != "$INSTALLED_VERSION" ]; then |
| 78 | + echo "ERROR: Git tag version doesn't match installed version!" |
| 79 | + exit 1 |
| 80 | + fi |
| 81 | +
|
| 82 | + echo "SUCCESS: Git tag and installed versions match" |
0 commit comments