Skip to content

Commit

Permalink
fixup makefile more
Browse files Browse the repository at this point in the history
  • Loading branch information
gamesguru committed Mar 2, 2024
1 parent 10b209e commit fa3c02f
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 42 deletions.
65 changes: 23 additions & 42 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,50 +27,42 @@ init: ## Install requirements (w/o --frozen-lockfile)


# ---------------------------------------
# Run, lint & format
# Format
# ---------------------------------------

.PHONY: run
run:
pnpm dev

.PHONY: format
format: ## format SQL with pg_format
./sql/format.sh

.PHONY: lint
lint: ## pnpm lint && pnpm check
pnpm lint
pnpm check
# TODO: what about import.sql? It gets formatted too ugly
pg_format -L -s 2 -w 100 sql/tables.sql >sql/tables.fmt.sql
mv sql/tables.fmt.sql sql/tables.sql\



# ---------------------------------------
# Build & install
# ---------------------------------------

APP_VERSION ?= v$(shell jq -r .version package.json)
APP_BUNDLE ?= build-${APP_VERSION}.tar.xz
APP_RELEASE_DATE ?= $(shell date --iso)
DB_VERSION ?= $(shell python3 sql/latest_version.py)
DB_FILE ?= sql/dist/usda.sqlite3-${DB_VERSION}.tar.xz

.PHONY: build
build: clean
build: ## Build the release
./sql/build.sh
du -h ${APP_BUNDLE}
./sql/build.sh ${DB_VERSION}
du -h ${DB_FILE}

.PHONY: deploy/upload
deploy/upload: ## Upload to GitHub releases
test -n "${APP_VERSION}"
test -f ${APP_BUNDLE}
gh release create ${APP_VERSION} --generate-notes
gh release upload ${APP_VERSION} ${APP_BUNDLE}
test -n "${DB_VERSION}"
test -f ${DB_FILE}
gh release create v${DB_VERSION} --generate-notes
gh release upload v${DB_VERSION} ${DB_FILE}

.PHONY: deploy/delete
deploy/delete:
gh release delete ${APP_VERSION}
git push origin --delete ${APP_VERSION}
- git tag -d ${APP_VERSION}
gh release delete v${DB_VERSION}
git push origin --delete v${DB_VERSION}
- git tag -d v${DB_VERSION}


REMOTE_HEAD ?= origin/master
Expand All @@ -82,39 +74,28 @@ _check-git-up-to-date:
# Check that we are in sync with ${REMOTE_HEAD}
git diff --quiet ${REMOTE_HEAD}

PROJECT_NAME ?= web
DEPLOY_URL ?= https://nutra.tk/
PROJECT_NAME ?= usda-sqlite

.PHONY: deploy/install-prod
deploy/install-prod: _check-git-up-to-date
deploy/install-prod: ## Install (on prod VPS)
# Check the version string was extracted from package.json
test -n "${APP_VERSION}"
# Download ${APP_VERSION}
curl -sSLO https://github.com/nutratech/${PROJECT_NAME}/releases/download/${APP_VERSION}/${APP_BUNDLE}
tar xf ${APP_BUNDLE}
rm -f ${APP_BUNDLE}
# Copy in place
rm -rf /var/www/app/* && mv build/* /var/www/app/
# Test live URL
curl -fI ${DEPLOY_URL}
test -n "${DB_VERSION}"
# Download ${DB_VERSION}
curl -sSLO https://github.com/nutratech/${PROJECT_NAME}/releases/download/${DB_VERSION}/${DB_FILE}
tar xf ${DB_FILE}



# ---------------------------------------
# Clean & extras
# ---------------------------------------

CLEAN_LOCS_ROOT ?= *.tar.xz build/

.PHONY: clean
clean: ## Clean up leftover bits and stuff from build
rm -rf ${CLEAN_LOCS_ROOT}

.PHONY: purge
purge: ## Purge package-lock.json && node_modules/
rm -rf package-lock.json pnpm-lock.yaml node_modules/
rm -f sql/*.sqlite
rm -f sql/*.sqlite3

.PHONY: extras/cloc
extras/cloc:
cloc HEAD --exclude-dir=svelte.config.js,pnpm-lock.yaml,package-lock.json
cloc HEAD --exclude-dir=usda.svg
23 changes: 23 additions & 0 deletions sql/latest_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Mar 2 12:32:45 2024
@author: shane
"""

import csv
import os

SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__))

version_csv_path = os.path.join(
SCRIPT_DIR, "version.csv"
)

rows = []
with open(version_csv_path, "r", encoding="utf-8") as _r_file:
reader = csv.reader(_r_file)
rows = list(reader)

print(rows[-1][1], end="")

0 comments on commit fa3c02f

Please sign in to comment.