Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2b59233af2 | |||
| f341a2aad2 | |||
| 263033adfd | |||
| 4e2920ddfc | |||
| f7ffefb719 | |||
| c7f81a301f |
@@ -4,8 +4,18 @@ on:
|
|||||||
push:
|
push:
|
||||||
branches: [main]
|
branches: [main]
|
||||||
tags: ['v*']
|
tags: ['v*']
|
||||||
|
paths:
|
||||||
|
- 'backend/**'
|
||||||
|
- 'frontend/**'
|
||||||
|
- 'docker-compose*.yml'
|
||||||
|
- '.github/workflows/docker-build.yml'
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: [main]
|
branches: [main]
|
||||||
|
paths:
|
||||||
|
- 'backend/**'
|
||||||
|
- 'frontend/**'
|
||||||
|
- 'docker-compose*.yml'
|
||||||
|
- '.github/workflows/docker-build.yml'
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
inputs:
|
inputs:
|
||||||
tag:
|
tag:
|
||||||
@@ -67,3 +77,63 @@ jobs:
|
|||||||
cache-from: type=gha
|
cache-from: type=gha
|
||||||
cache-to: type=gha,mode=max
|
cache-to: type=gha,mode=max
|
||||||
platforms: linux/amd64,linux/arm64
|
platforms: linux/amd64,linux/arm64
|
||||||
|
|
||||||
|
# =============================================================================
|
||||||
|
# Create GitHub Release (only on tag push)
|
||||||
|
# =============================================================================
|
||||||
|
create-release:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: build-and-push
|
||||||
|
if: startsWith(github.ref, 'refs/tags/v')
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0 # Fetch all history for changelog generation
|
||||||
|
|
||||||
|
- name: Get previous tag
|
||||||
|
id: prev_tag
|
||||||
|
run: |
|
||||||
|
PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
|
||||||
|
echo "tag=${PREV_TAG}" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
- name: Generate changelog
|
||||||
|
id: changelog
|
||||||
|
run: |
|
||||||
|
CURRENT_TAG=${GITHUB_REF#refs/tags/}
|
||||||
|
PREV_TAG="${{ steps.prev_tag.outputs.tag }}"
|
||||||
|
|
||||||
|
echo "## What's Changed" > changelog.md
|
||||||
|
echo "" >> changelog.md
|
||||||
|
|
||||||
|
if [ -n "$PREV_TAG" ]; then
|
||||||
|
# Get commits between tags
|
||||||
|
git log ${PREV_TAG}..${CURRENT_TAG} --pretty=format:"* %s (%h)" --no-merges >> changelog.md
|
||||||
|
else
|
||||||
|
# First release - get recent commits
|
||||||
|
git log -20 --pretty=format:"* %s (%h)" --no-merges >> changelog.md
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "" >> changelog.md
|
||||||
|
echo "" >> changelog.md
|
||||||
|
echo "## Docker Images" >> changelog.md
|
||||||
|
echo "" >> changelog.md
|
||||||
|
echo '```bash' >> changelog.md
|
||||||
|
echo "docker pull ghcr.io/${{ github.repository_owner }}/medassist-ng-backend:${CURRENT_TAG#v}" >> changelog.md
|
||||||
|
echo "docker pull ghcr.io/${{ github.repository_owner }}/medassist-ng-frontend:${CURRENT_TAG#v}" >> changelog.md
|
||||||
|
echo '```' >> changelog.md
|
||||||
|
echo "" >> changelog.md
|
||||||
|
echo "**Full Changelog**: https://github.com/${{ github.repository }}/compare/${PREV_TAG}...${CURRENT_TAG}" >> changelog.md
|
||||||
|
|
||||||
|
- name: Create GitHub Release
|
||||||
|
uses: softprops/action-gh-release@v2
|
||||||
|
with:
|
||||||
|
body_path: changelog.md
|
||||||
|
generate_release_notes: false
|
||||||
|
draft: false
|
||||||
|
prerelease: ${{ contains(github.ref, '-rc') || contains(github.ref, '-beta') || contains(github.ref, '-alpha') }}
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "medassist-ng-backend",
|
"name": "medassist-ng-backend",
|
||||||
"version": "0.1.0",
|
"version": "1.0.1",
|
||||||
"private": true,
|
"private": true,
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import { FastifyInstance } from "fastify";
|
import { FastifyInstance } from "fastify";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { db } from "../db/client.js";
|
import { db } from "../db/client.js";
|
||||||
import { medications } from "../db/schema.js";
|
import { medications, doseTracking } from "../db/schema.js";
|
||||||
import { eq, and } from "drizzle-orm";
|
import { eq, and, like, sql } from "drizzle-orm";
|
||||||
import { createWriteStream, existsSync, unlinkSync } from "fs";
|
import { createWriteStream, existsSync, unlinkSync } from "fs";
|
||||||
import { resolve, extname } from "path";
|
import { resolve, extname } from "path";
|
||||||
import { pipeline } from "stream/promises";
|
import { pipeline } from "stream/promises";
|
||||||
@@ -199,6 +199,33 @@ export async function medicationRoutes(app: FastifyInstance) {
|
|||||||
|
|
||||||
if (!result.length) return reply.notFound();
|
if (!result.length) return reply.notFound();
|
||||||
|
|
||||||
|
// Clean up dose tracking entries that are before the earliest start date
|
||||||
|
// This ensures consistency when the user changes the start date
|
||||||
|
const earliestStart = Math.min(...blisters.map(b => new Date(b.start).getTime()));
|
||||||
|
if (!Number.isNaN(earliestStart)) {
|
||||||
|
// Get all dose tracking entries for this medication and filter out invalid ones
|
||||||
|
const allDoses = await db.select().from(doseTracking)
|
||||||
|
.where(and(
|
||||||
|
eq(doseTracking.userId, userId),
|
||||||
|
like(doseTracking.doseId, `${idNum}-%`)
|
||||||
|
));
|
||||||
|
|
||||||
|
// Find doses with timestamps before the earliest start date
|
||||||
|
const dosesToDelete = allDoses.filter(dose => {
|
||||||
|
const parts = dose.doseId.split("-");
|
||||||
|
if (parts.length >= 3) {
|
||||||
|
const timestamp = parseInt(parts[2], 10);
|
||||||
|
return !Number.isNaN(timestamp) && timestamp < earliestStart;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Delete invalid doses
|
||||||
|
for (const dose of dosesToDelete) {
|
||||||
|
await db.delete(doseTracking).where(eq(doseTracking.id, dose.id));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: result[0].id,
|
id: result[0].id,
|
||||||
name: result[0].name,
|
name: result[0].name,
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 1013 KiB After Width: | Height: | Size: 6.8 MiB |
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "medassist-ng-frontend",
|
"name": "medassist-ng-frontend",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "0.1.0",
|
"version": "1.0.1",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
|
|||||||
@@ -3158,9 +3158,14 @@ function calculateCoverage(
|
|||||||
if (parts.length >= 3) {
|
if (parts.length >= 3) {
|
||||||
const medId = parseInt(parts[0], 10);
|
const medId = parseInt(parts[0], 10);
|
||||||
const blisterIdx = parseInt(parts[1], 10);
|
const blisterIdx = parseInt(parts[1], 10);
|
||||||
|
const doseTimestamp = parseInt(parts[2], 10);
|
||||||
if (medId === m.id && m.blisters[blisterIdx]) {
|
if (medId === m.id && m.blisters[blisterIdx]) {
|
||||||
// Each taken dose (regardless of person) consumes the usage amount
|
// Only count doses that are on or after the blister's start date
|
||||||
consumed += m.blisters[blisterIdx].usage;
|
const blisterStart = new Date(m.blisters[blisterIdx].start).getTime();
|
||||||
|
if (!Number.isNaN(blisterStart) && doseTimestamp >= blisterStart) {
|
||||||
|
// Each taken dose (regardless of person) consumes the usage amount
|
||||||
|
consumed += m.blisters[blisterIdx].usage;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Executable
+120
@@ -0,0 +1,120 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# =============================================================================
|
||||||
|
# MedAssist Release Script
|
||||||
|
# =============================================================================
|
||||||
|
# Usage:
|
||||||
|
# ./scripts/release.sh patch # 1.0.0 -> 1.0.1 (bugfixes)
|
||||||
|
# ./scripts/release.sh minor # 1.0.0 -> 1.1.0 (new features)
|
||||||
|
# ./scripts/release.sh major # 1.0.0 -> 2.0.0 (breaking changes)
|
||||||
|
# ./scripts/release.sh 1.2.3 # explicit version
|
||||||
|
# =============================================================================
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# Colors
|
||||||
|
RED='\033[0;31m'
|
||||||
|
GREEN='\033[0;32m'
|
||||||
|
YELLOW='\033[1;33m'
|
||||||
|
BLUE='\033[0;34m'
|
||||||
|
NC='\033[0m' # No Color
|
||||||
|
|
||||||
|
# Secondary remote (self-hosted git)
|
||||||
|
SECONDARY_REMOTE="git@git.danielvolz.org:daniel/medassist-ng.git"
|
||||||
|
|
||||||
|
# Get script directory and project root
|
||||||
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
|
||||||
|
cd "$PROJECT_ROOT"
|
||||||
|
|
||||||
|
# Check for uncommitted changes
|
||||||
|
if [[ -n $(git status --porcelain) ]]; then
|
||||||
|
echo -e "${RED}Error: You have uncommitted changes. Commit or stash them first.${NC}"
|
||||||
|
git status --short
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Get current version from backend/package.json
|
||||||
|
CURRENT_VERSION=$(grep '"version"' backend/package.json | sed 's/.*"version": "\(.*\)".*/\1/')
|
||||||
|
echo -e "${BLUE}Current version: ${YELLOW}v${CURRENT_VERSION}${NC}"
|
||||||
|
|
||||||
|
# Calculate new version
|
||||||
|
if [[ -z "$1" ]]; then
|
||||||
|
echo -e "${RED}Usage: $0 <patch|minor|major|x.y.z>${NC}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
case "$1" in
|
||||||
|
patch)
|
||||||
|
IFS='.' read -r major minor patch <<< "$CURRENT_VERSION"
|
||||||
|
NEW_VERSION="$major.$minor.$((patch + 1))"
|
||||||
|
;;
|
||||||
|
minor)
|
||||||
|
IFS='.' read -r major minor patch <<< "$CURRENT_VERSION"
|
||||||
|
NEW_VERSION="$major.$((minor + 1)).0"
|
||||||
|
;;
|
||||||
|
major)
|
||||||
|
IFS='.' read -r major minor patch <<< "$CURRENT_VERSION"
|
||||||
|
NEW_VERSION="$((major + 1)).0.0"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
# Assume explicit version (validate format)
|
||||||
|
if [[ ! "$1" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
|
||||||
|
echo -e "${RED}Invalid version format. Use: x.y.z${NC}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
NEW_VERSION="$1"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
echo -e "${GREEN}New version: ${YELLOW}v${NEW_VERSION}${NC}"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Confirm
|
||||||
|
read -p "Release v${NEW_VERSION}? (y/N) " -n 1 -r
|
||||||
|
echo ""
|
||||||
|
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
||||||
|
echo "Aborted."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Update version in package.json files
|
||||||
|
echo -e "${BLUE}Updating package.json files...${NC}"
|
||||||
|
sed -i '' "s/\"version\": \"${CURRENT_VERSION}\"/\"version\": \"${NEW_VERSION}\"/" backend/package.json
|
||||||
|
sed -i '' "s/\"version\": \"${CURRENT_VERSION}\"/\"version\": \"${NEW_VERSION}\"/" frontend/package.json 2>/dev/null || true
|
||||||
|
|
||||||
|
# Commit version bump
|
||||||
|
echo -e "${BLUE}Committing version bump...${NC}"
|
||||||
|
git add backend/package.json frontend/package.json 2>/dev/null || git add backend/package.json
|
||||||
|
git commit -m "chore: release v${NEW_VERSION}"
|
||||||
|
|
||||||
|
# Check if tag exists
|
||||||
|
if git rev-parse "v${NEW_VERSION}" >/dev/null 2>&1; then
|
||||||
|
echo -e "${YELLOW}Tag v${NEW_VERSION} already exists. Overwriting...${NC}"
|
||||||
|
git tag -d "v${NEW_VERSION}"
|
||||||
|
git push origin ":refs/tags/v${NEW_VERSION}" 2>/dev/null || true
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Create and push tag
|
||||||
|
echo -e "${BLUE}Creating tag v${NEW_VERSION}...${NC}"
|
||||||
|
git tag -a "v${NEW_VERSION}" -m "Release v${NEW_VERSION}"
|
||||||
|
|
||||||
|
# Push
|
||||||
|
echo -e "${BLUE}Pushing to origin (GitHub)...${NC}"
|
||||||
|
git push origin main
|
||||||
|
git push origin "v${NEW_VERSION}"
|
||||||
|
|
||||||
|
# Ask about secondary remote
|
||||||
|
echo ""
|
||||||
|
read -p "Also push to git.danielvolz.org? (y/N) " -n 1 -r
|
||||||
|
echo ""
|
||||||
|
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||||||
|
echo -e "${BLUE}Pushing to git.danielvolz.org...${NC}"
|
||||||
|
git push "$SECONDARY_REMOTE" main
|
||||||
|
git push "$SECONDARY_REMOTE" "v${NEW_VERSION}"
|
||||||
|
echo -e "${GREEN}✓ Pushed to git.danielvolz.org${NC}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo -e "${GREEN}✓ Released v${NEW_VERSION}${NC}"
|
||||||
|
echo -e "${BLUE}GitHub Actions will now build and publish Docker images.${NC}"
|
||||||
|
echo -e "Track progress: ${YELLOW}https://github.com/DanielVolz/medassist-ng/actions${NC}"
|
||||||
Reference in New Issue
Block a user