diff --git a/.gitignore b/.gitignore index 004d5cab..6802f04a 100644 --- a/.gitignore +++ b/.gitignore @@ -34,6 +34,8 @@ node_modules/ **/.ruff_cache/ .pytest_cache/ **/.pytest_cache/ +# Generated by hatch-vcs at install time +brewman/brewman/_version.py # Testing & Coverage coverage/ diff --git a/Dockerfile b/Dockerfile index ba141d06..89f32419 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,6 +3,8 @@ # no need to run yarn/ng build under qemu emulation for linux/arm64 - doing # so is slow and memory hungry and can OOM the machine during multi-arch # builds (podman builds all --platform targets concurrently). +# Declare the automatic build arguments +ARG BUILDPLATFORM FROM --platform=$BUILDPLATFORM node:lts-trixie-slim AS base # Install dependencies only when needed @@ -67,6 +69,7 @@ WORKDIR /app/ # Ref: https://docs.astral.sh/uv/guides/integration/docker/#using-the-environment ENV PATH="/app/.venv/bin:$PATH" + # Install dependencies # Ref: https://docs.astral.sh/uv/guides/integration/docker/#intermediate-layers RUN --mount=type=cache,target=/root/.cache/uv \ diff --git a/Makefile b/Makefile index c27d6a45..5438efc5 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ .PHONY: build-production -build-production: ## Build the production container image. +build-production: ## Build the production container image. Usage: make build-production TAG=15.4.0 @echo "Cloning repository..." @rm -rf .tmp-brewman @git clone --depth 1 $(if $(TAG),--branch v$(TAG)) git@git.tanshu.com:tanshu/brewman.git .tmp-brewman @@ -18,7 +18,7 @@ build-production: ## Build the production container image. $(if $(TAG),@podman manifest push --all registry.tanshu.com/brewman:latest docker://registry.tanshu.com/brewman:$(TAG)) .PHONY: build-check -build-check: ## Multi-arch build without push (compile check) +build-check: ## Multi-arch build without push (compile check). Usage: make build-check TAG=15.4.0 @echo "Cloning repository..." @rm -rf .tmp-brewman @git clone --depth 1 $(if $(TAG),--branch v$(TAG)) git@git.tanshu.com:tanshu/brewman.git .tmp-brewman @@ -31,12 +31,3 @@ build-check: ## Multi-arch build without push (compile check) --pull \ .tmp-brewman || (rm -rf .tmp-brewman && exit 1) @rm -rf .tmp-brewman - -.PHONY: build-check-local -build-check-local: ## Local build without push (compile check) - @git archive --format=tar HEAD | podman build \ - --platform linux/amd64 \ - --tag brewman:test \ - --pull \ - - - diff --git a/brewman/brewman/__version__.py b/brewman/brewman/__version__.py deleted file mode 100644 index 63b4c27f..00000000 --- a/brewman/brewman/__version__.py +++ /dev/null @@ -1 +0,0 @@ -__version__ = "15.3.1" diff --git a/brewman/brewman/routers/login.py b/brewman/brewman/routers/login.py index da45a878..508646c7 100644 --- a/brewman/brewman/routers/login.py +++ b/brewman/brewman/routers/login.py @@ -18,7 +18,7 @@ from fastapi.security import OAuth2PasswordRequestForm from sqlalchemy import delete, or_, select from sqlalchemy.orm import Session -from .. import __version__ +from .._version import __version__ from ..core.config import settings from ..core.security import ( Token, @@ -120,7 +120,7 @@ async def login_for_access_token( "scopes": ["authenticated"] + perm_scopes, "userId": str(user.id), "lockedOut": user.locked_out, - "ver": __version__.__version__, + "ver": __version__, }, expires_delta=access_token_expires, ) @@ -136,7 +136,7 @@ async def refresh_token(user: UserToken = Security(get_current_active_user)) -> "scopes": user.permissions, "userId": str(user.id_), "lockedOut": user.locked_out, - "ver": __version__.__version__, + "ver": __version__, }, expires_delta=access_token_expires, ) diff --git a/brewman/pyproject.toml b/brewman/pyproject.toml index 4fa56f2d..ae676c40 100644 --- a/brewman/pyproject.toml +++ b/brewman/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "brewman" -version = "15.3.1" +dynamic = ["version"] description = "Accounting plus inventory management for a restaurant." requires-python = ">=3.14" authors = [{ name = "tanshu", email = "git@tanshu.com" }] @@ -37,9 +37,16 @@ dev = [ ] [build-system] -requires = ["hatchling"] +requires = ["hatchling", "hatch-vcs"] build-backend = "hatchling.build" +[tool.hatch.version] +source = "vcs" +raw-options = { root = "..", fallback_version = "0.0.0" } + +[tool.hatch.build.hooks.vcs] +version-file = "brewman/_version.py" + [tool.mypy] # --- Strictness --- strict = true diff --git a/brewman/uv.lock b/brewman/uv.lock index 80fea59c..a34347d6 100644 --- a/brewman/uv.lock +++ b/brewman/uv.lock @@ -211,7 +211,6 @@ wheels = [ [[package]] name = "brewman" -version = "15.3.1" source = { editable = "." } dependencies = [ { name = "alembic" }, diff --git a/deploy.sh b/deploy.sh index 22399045..153c0865 100755 --- a/deploy.sh +++ b/deploy.sh @@ -3,14 +3,41 @@ set -euo pipefail parent_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" || exit ; pwd -P ) cd "$parent_path" || exit -#./lint.sh - -if [ 1 -eq "$#" ] -then - ./version_bump.sh "$1" +if [ $# -ne 1 ]; then + echo "Usage: $0 " + exit 1 fi -current_version=$(grep -m 1 '^version = ' brewman/pyproject.toml | sed -E 's/version = "([^"]+)"/\1/') -make build-production TAG="$current_version" +if git describe --exact-match --tags HEAD >/dev/null 2>&1; then + existing_tag=$(git describe --exact-match --tags HEAD) + echo "Current commit is already tagged with $existing_tag. Skipping tag creation." + new_version=${existing_tag#v} +else + current_version=$(git describe --tags --abbrev=0 | sed 's/^v//') + IFS='.' read -r major minor patch <<< "$current_version" + + if [ "$1" == "major" ]; then + major=$((major + 1)); minor=0; patch=0 + new_version="${major}.${minor}.${patch}" + elif [ "$1" == "minor" ]; then + minor=$((minor + 1)); patch=0 + new_version="${major}.${minor}.${patch}" + elif [ "$1" == "patch" ]; then + patch=$((patch + 1)) + new_version="${major}.${minor}.${patch}" + elif [[ "$1" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + new_version="$1" + else + echo "Invalid argument: must be 'major', 'minor', 'patch', or a specific version (e.g. 1.2.3)" + exit 1 + fi + + echo "Tagging v$new_version" + git tag "v$new_version" +fi +git push +git push --tags + +make build-production TAG="$new_version" cd "$parent_path/ansible" || exit ansible-playbook --inventory=hosts playbook.yml diff --git a/overlord/package.json b/overlord/package.json index de01a2b6..f98e1e73 100644 --- a/overlord/package.json +++ b/overlord/package.json @@ -1,6 +1,6 @@ { "name": "overlord", - "version": "15.3.1", + "version": "0.0.0", "scripts": { "ng": "ng", "start": "ng serve", diff --git a/overlord/src/app/app.environment.ts b/overlord/src/app/app.environment.ts index c396a29d..95ece7f8 100644 --- a/overlord/src/app/app.environment.ts +++ b/overlord/src/app/app.environment.ts @@ -1,6 +1,5 @@ export const environment = { ACCESS_TOKEN_REFRESH_MINUTES: 10, // refresh token 10 minutes before expiry - version: '15.3.1', title: 'HnG / TGB', }; diff --git a/overlord/src/app/settings/settings.component.html b/overlord/src/app/settings/settings.component.html index a45508fa..3efec896 100644 --- a/overlord/src/app/settings/settings.component.html +++ b/overlord/src/app/settings/settings.component.html @@ -194,5 +194,5 @@ diff --git a/overlord/src/app/settings/settings.component.ts b/overlord/src/app/settings/settings.component.ts index 02b3c031..f4526fd8 100644 --- a/overlord/src/app/settings/settings.component.ts +++ b/overlord/src/app/settings/settings.component.ts @@ -14,7 +14,6 @@ import { MatTabsModule } from '@angular/material/tabs'; import { Router } from '@angular/router'; import { AccountTypeService } from '../account/account-type.service'; -import { environment } from '../app.environment'; import { AuthService } from '../auth/auth.service'; import { AccountType } from '../core/account-type'; import { endOfMonth, formatDisplayDate, formatIsoDate } from '../core/date-utils'; @@ -117,12 +116,6 @@ export class SettingsComponent { displayedColumns = ['index', 'validity', 'voucherTypes', 'accountTypes', 'lock', 'action']; - version: string; - - constructor() { - this.version = environment.version; - } - showLockInformation(info: LockInfo[]) { this.lockInformation.set(info); } diff --git a/version_bump.sh b/version_bump.sh deleted file mode 100755 index de142840..00000000 --- a/version_bump.sh +++ /dev/null @@ -1,54 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail -parent_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" || exit ; pwd -P ) -cd "$parent_path" || exit - -last_commit_subject=$(git log -1 --format=%s) -if [[ "$last_commit_subject" =~ ^Version\ Bump ]]; then - echo "Last commit is already a version bump (\"$last_commit_subject\"). Nothing to do." - exit 0 -fi - -if [ 1 -eq "$#" ] -then - current_version=$(grep -m 1 '^version = ' brewman/pyproject.toml | sed -E 's/version = "([^"]+)"/\1/') - IFS='.' read -r major minor patch <<< "$current_version" - - if [ "$1" == "major" ]; then - major=$((major + 1)) - minor=0 - patch=0 - new_version="${major}.${minor}.${patch}" - elif [ "$1" == "minor" ]; then - minor=$((minor + 1)) - patch=0 - new_version="${major}.${minor}.${patch}" - elif [ "$1" == "patch" ]; then - patch=$((patch + 1)) - new_version="${major}.${minor}.${patch}" - elif [[ "$1" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then - new_version="$1" - else - echo "Invalid argument: must be 'major', 'minor', 'patch', or a specific version (e.g. 1.2.3)" - exit 1 - fi - - echo "Version bump from $current_version to $new_version" - sed --in-place --regexp-extended 's/"([0-9]{1,2}.[0-9]+.[0-9]+)"/"'"$new_version"'"/g' brewman/brewman/__version__.py - git add brewman/brewman/__version__.py - sed --in-place --regexp-extended 's/version = "([0-9]{1,2}.[0-9]+.[0-9]+)"/version = "'"$new_version"'"/g' brewman/pyproject.toml - (cd brewman && uv lock) - git add brewman/pyproject.toml brewman/uv.lock - sed --in-place --regexp-extended 's/version: '\''([0-9]*.[0-9]+.[0-9]+)'\''/version: '\'"$new_version"\''/g' overlord/src/app/app.environment.ts - git add overlord/src/app/app.environment.ts - sed --in-place --regexp-extended 's/"version": "([0-9]{1,2}.[0-9]+.[0-9]+)"/"version": "'"$new_version"'"/g' overlord/package.json - git add overlord/package.json - git commit -m "Version Bump v$new_version" - git tag "v$new_version" -else - echo "No version bump" - echo "Usage: $0 " - exit 1 -fi -git push -git push --tags