From 223727b4362e4d395c23ab7219bf0f8de7e464b9 Mon Sep 17 00:00:00 2001 From: Shane Jaroch Date: Fri, 14 Apr 2023 13:15:58 -0400 Subject: [PATCH] Prod (#3) * do a prod build, upload * add curl test after install * check for jq / gh * update package-lock --- .github/workflows/ci.yml | 24 ++++++++++++---- .gitignore | 2 ++ Makefile | 62 ++++++++++++++++++++++++++++++++++++++++ package-lock.json | 8 +++--- 4 files changed, 86 insertions(+), 10 deletions(-) create mode 100644 Makefile diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a90d86d..562f744 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,7 +7,7 @@ name: ci - '**' permissions: - contents: read + contents: write jobs: ci: @@ -23,17 +23,13 @@ jobs: run: npm ci # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - # Deploy as long as it builds + # Build [Dev] (and Deploy) # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - name: Build (prod) - if: github.ref == 'refs/heads/master' - run: npm run build - name: Build (dev) if: github.ref == 'refs/heads/dev' run: npm run build:dev - # TODO: how to copy over on prod? - name: Deploy (dev) [Copy static files over] if: github.ref == 'refs/heads/dev' run: rm -rf /var/www/app/* && mv build/* /var/www/app/ @@ -46,3 +42,19 @@ jobs: - name: Check run: npm run check + + # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + # Build [Prod] (and Upload binary) + # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + - name: Build (production release) + if: github.ref == 'refs/heads/master' + env: + GH_TOKEN: ${{ github.token }} + run: set -o pipefail; make build/prod build/compress + + - name: Upload artifacts (production release) + if: github.ref == 'refs/heads/master' + env: + GH_TOKEN: ${{ github.token }} + run: set -o pipefail; make build/upload diff --git a/.gitignore b/.gitignore index d530c76..145b8b6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ .DS_Store *.swp +*.tar.xz +*.tar.gz /.idea node_modules diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..895056d --- /dev/null +++ b/Makefile @@ -0,0 +1,62 @@ +SHELL=/bin/bash + +.DEFAULT_GOAL := _help + +# NOTE: must put a 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' + + + +# --------------------------------------- +# Build & install +# --------------------------------------- + +APP_VERSION ?= $(shell cat package.json | jq -r '.version') +APP_RELEASE_DATE ?= $(shell date --iso) + +.PHONY: build/prod +build/prod: clean +build/prod: ## Build the release + npm run build + +.PHONY: build/compress +build/compress: + tar cJf build.tar.xz build/ + +.PHONY: build/upload +build/upload: + jq --version + gh --version + if [ "${CI}" ]; then \ + gh release create ${APP_VERSION} --generate-notes; \ + fi + if [ "${CI}" ]; then \ + gh release upload ${APP_VERSION} build.tar.xz; \ + fi + +PROJECT_NAME ?= web.2023 +DEPLOY_URL ?= https://nutra.tk/ + +.PHONY: install/prod +install/prod: ## Install the release on prod (pulls latest tag) + git pull + test -n "${APP_VERSION}" + wget https://github.com/nutratech/${PROJECT_NAME}/releases/download/${APP_VERSION}/build.tar.xz + tar xf build.tar.xz + rm -f build.tar.xz + rm -rf /var/www/app/* && mv build/* /var/www/app/ + curl -fI ${DEPLOY_URL} + + + +# --------------------------------------- +# Clean +# --------------------------------------- + +CLEAN_LOCS_ROOT ?= build/ + +.PHONY: clean +clean: + rm -rf ${CLEAN_LOCS_ROOT} diff --git a/package-lock.json b/package-lock.json index c3bd1a8..1776c43 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2598,12 +2598,12 @@ } }, "node_modules/resolve": { - "version": "1.22.2", - "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.2.tgz", - "integrity": "sha512-Sb+mjNHOULsBv818T40qSPeRiuWLyaGMa5ewydRLFimneixmVy2zdivRl+AF6jaYPC8ERxGDmFSiqui6SfPd+g==", + "version": "1.22.3", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.3.tgz", + "integrity": "sha512-P8ur/gp/AmbEzjr729bZnLjXK5Z+4P0zhIJgBgzqRih7hL7BOukHGtSTA3ACMY467GRFz3duQsi0bDZdR7DKdw==", "dev": true, "dependencies": { - "is-core-module": "^2.11.0", + "is-core-module": "^2.12.0", "path-parse": "^1.0.7", "supports-preserve-symlinks-flag": "^1.0.0" },