Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 32 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -144,25 +144,48 @@ jobs:
if: github.event_name == 'push'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v7

- name: Get version
id: version
env:
PYTHONPATH: src
run: python -c "from version import VERSION; print(f'version={VERSION}')" >> "$GITHUB_OUTPUT"

- name: Check tag
id: tag
env:
VERSION: ${{ steps.version.outputs.version }}
run: |
if git ls-remote --exit-code --tags origin "refs/tags/${VERSION}" > /dev/null; then
echo "exists=true" >> "$GITHUB_OUTPUT"
else
status=$?
if [ "$status" -ne 2 ]; then
exit "$status"
fi
echo "exists=false" >> "$GITHUB_OUTPUT"
fi

- name: Download artifacts
if: steps.tag.outputs.exists == 'false'
uses: actions/download-artifact@v8

- name: Get date
id: date
run: echo "date=$(date +%Y.%m.%d)" >> "$GITHUB_OUTPUT"

- name: Rename artifacts
if: steps.tag.outputs.exists == 'false'
env:
VERSION: ${{ steps.date.outputs.date }}.${{ github.run_number }}
VERSION: ${{ steps.version.outputs.version }}
run: |
mv snapjaw-windows-x86_64/snapjaw-windows-x86_64.zip snapjaw-${VERSION}-windows-x86_64.zip
mv snapjaw-linux-x86_64/snapjaw-linux-x86_64.tar.gz snapjaw-${VERSION}-linux-x86_64.tar.gz

- name: Release
if: steps.tag.outputs.exists == 'false'
uses: softprops/action-gh-release@v3
with:
tag_name: ${{ steps.date.outputs.date }}.${{ github.run_number }}
name: ${{ steps.date.outputs.date }}.${{ github.run_number }}
tag_name: ${{ steps.version.outputs.version }}
name: ${{ steps.version.outputs.version }}
files: |
snapjaw-${{ steps.date.outputs.date }}.${{ github.run_number }}-windows-x86_64.zip
snapjaw-${{ steps.date.outputs.date }}.${{ github.run_number }}-linux-x86_64.tar.gz
snapjaw-${{ steps.version.outputs.version }}-windows-x86_64.zip
snapjaw-${{ steps.version.outputs.version }}-linux-x86_64.tar.gz
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ dependencies = [
"tabulate>=0.9.0",
]
name = "snapjaw"
version = "1.0"
dynamic = ["version"]
description = "Vanilla WoW AddOn Manager"

[tool.ruff]
Expand Down
2 changes: 2 additions & 0 deletions src/snapjaw.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import mygit
import signature
import toc
import version


class CliError(RuntimeError):
Expand Down Expand Up @@ -79,6 +80,7 @@ def main():

def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument("--version", action="version", version=f"snapjaw {version.VERSION}")

parser.add_argument(
"--addons-dir",
Expand Down
1 change: 1 addition & 0 deletions src/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VERSION = "1.4.0"
60 changes: 60 additions & 0 deletions tests/test_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
"""Tests for the application version and CLI version flag."""

import re

import pytest

import version
from snapjaw import parse_args


class TestVersion:
"""Tests for the single source of truth version constant."""

def test_has_three_numeric_components(self):
"""VERSION uses semantic versioning's three-component numeric form."""
assert re.fullmatch(r"\d+\.\d+\.\d+", version.VERSION)


class TestVersionFlag:
"""Tests for the top-level --version flag."""

@staticmethod
def assert_version_output(monkeypatch, capsys, argv):
monkeypatch.setattr("sys.argv", argv)

with pytest.raises(SystemExit) as error:
parse_args()

assert error.value.code == 0
captured = capsys.readouterr()
assert captured.out == f"snapjaw {version.VERSION}\n"
assert captured.err == ""

def test_prints_exact_version(self, monkeypatch, capsys, tmp_path):
"""--version prints the application name and VERSION exactly."""
self.assert_version_output(
monkeypatch,
capsys,
[
"snapjaw",
"--addons-dir",
str(tmp_path),
"--game-version",
"vanilla",
"--version",
"status",
],
)

def test_works_without_subcommand(self, monkeypatch, capsys):
"""--version exits before required subcommand validation."""
self.assert_version_output(monkeypatch, capsys, ["snapjaw", "--version"])

def test_works_outside_game_directory(self, monkeypatch, capsys, tmp_path):
"""--version exits before attempting to resolve an addons directory."""
isolated_directory = tmp_path / "isolated"
isolated_directory.mkdir()
monkeypatch.chdir(isolated_directory)

self.assert_version_output(monkeypatch, capsys, ["snapjaw", "--version"])
1 change: 0 additions & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.