]> Nutra Git (v1) - nutratech/usda-sqlite.git/commitdiff
wip makefile, github workflow
authorShane Jaroch <chown_tee@proton.me>
Sat, 2 Mar 2024 16:24:59 +0000 (11:24 -0500)
committerShane Jaroch <chown_tee@proton.me>
Sat, 2 Mar 2024 16:24:59 +0000 (11:24 -0500)
.github/workflows/test.yml [new file with mode: 0644]
Makefile [new file with mode: 0644]

diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
new file mode 100644 (file)
index 0000000..b640d9e
--- /dev/null
@@ -0,0 +1,75 @@
+---
+name: ci
+
+'on':
+  push:
+    branches:
+      - '**'
+
+permissions:
+  contents: write
+
+jobs:
+  ci:
+    runs-on: [self-hosted, dev]
+    steps:
+      - name: Checkout
+        uses: actions/checkout@v4
+
+      - name: Extras / Count Lines of Source Code
+        run: make extras/cloc
+
+      - name: Install requirements
+        run: make init
+
+      # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+      # Build [Dev] (and Deploy)
+      # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+      - name: Build (dev)
+        if: github.ref == 'refs/heads/dev'
+        run: pnpm build:dev
+
+      - name: Deploy (dev) [Copy static files over]
+        if: github.ref == 'refs/heads/dev'
+        run: rm -rf /var/www/app/* && mv build/* /var/www/app/
+
+      # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+      # Lint
+      # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+      - name: Lint
+        run: pnpm lint
+
+      - name: Check
+        run: pnpm check
+
+      # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+      # Build [Prod] (and Upload binary)
+      # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+      - name: Check release version
+        id: check-release-version
+        if: github.ref == 'refs/heads/master'
+        env:
+          GH_TOKEN: ${{ github.token }}
+        run: |
+          RELEASE_TAG=v$(jq -r .version package.json)
+          echo RELEASE_TAG=$RELEASE_TAG
+          test -n "$RELEASE_TAG"
+          # Test that github-cli is working
+          gh --version
+          gh release list -L 1
+          # TODO: enhance this to be: if release_tag > current_prod_tag, deploy
+          gh release view $RELEASE_TAG || echo "PUBLISH=1" >> "$GITHUB_OUTPUT"
+
+      # yamllint disable rule:line-length
+      - name: Build (production release)
+        if: github.ref == 'refs/heads/master' && steps.check-release-version.outputs.PUBLISH
+        env:
+          GH_TOKEN: ${{ github.token }}
+        run: set -o pipefail; make build
+
+      - name: Upload artifacts (production release)
+        if: github.ref == 'refs/heads/master' && steps.check-release-version.outputs.PUBLISH
+        env:
+          GH_TOKEN: ${{ github.token }}
+        run: set -o pipefail; make deploy/upload
diff --git a/Makefile b/Makefile
new file mode 100644 (file)
index 0000000..9edc19a
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,120 @@
+SHELL=/bin/bash
+
+.DEFAULT_GOAL := _help
+
+# NOTE: must put a <TAB> character and two pound "\t##" to show up in this list.  Keep it brief! IGNORE_ME
+.PHONY: _help
+_help:
+       @grep -h "##" $(MAKEFILE_LIST) | grep -v IGNORE_ME | sed -e 's/##//' | column -t -s $$'\t'
+
+
+
+# ---------------------------------------
+# Install requirements
+# ---------------------------------------
+
+.PHONY: init
+init:  ## Install requirements (w/o --frozen-lockfile)
+       # Check version
+       [[ "$(shell pnpm --version)" =~ "8." ]]
+       # Remove old install
+       rm -rf node_modules/
+       # Install requirements
+       pnpm install
+       # Sync svelte kit (optional)
+       pnpm svelte-kit sync
+
+
+
+# ---------------------------------------
+# Run, lint & format
+# ---------------------------------------
+
+.PHONY: run
+run:
+       pnpm dev
+
+.PHONY: format
+format:        ## pnpm format
+       pnpm format
+
+.PHONY: lint
+lint:  ## pnpm lint && pnpm check
+       pnpm lint
+       pnpm check
+
+
+
+# ---------------------------------------
+# Build & install
+# ---------------------------------------
+
+APP_VERSION ?= v$(shell jq -r .version package.json)
+APP_BUNDLE ?= build-${APP_VERSION}.tar.xz
+APP_RELEASE_DATE ?= $(shell date --iso)
+
+.PHONY: build
+build: clean
+build: ## Build the release
+       ./sql/build.sh
+       du -h ${APP_BUNDLE}
+
+.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}
+
+.PHONY: deploy/delete
+deploy/delete:
+       gh release delete ${APP_VERSION}
+       git push origin --delete ${APP_VERSION}
+       - git tag -d ${APP_VERSION}
+
+
+REMOTE_HEAD ?= origin/master
+
+.PHONY: _check-git-up-to-date
+_check-git-up-to-date:
+       git branch --show-current
+       git fetch
+       # Check that we are in sync with ${REMOTE_HEAD}
+       git diff --quiet ${REMOTE_HEAD}
+
+PROJECT_NAME ?= web
+DEPLOY_URL ?= https://nutra.tk/
+
+.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}
+
+
+
+# ---------------------------------------
+# 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/
+
+.PHONY: extras/cloc
+extras/cloc:
+       cloc HEAD --exclude-dir=svelte.config.js,pnpm-lock.yaml,package-lock.json