Skip to content

Commit

Permalink
Prod (#3)
Browse files Browse the repository at this point in the history
* do a prod build, upload

* add curl test after install

* check for jq / gh

* update package-lock
  • Loading branch information
gamesguru authored Apr 14, 2023
1 parent 43fecb9 commit 223727b
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 10 deletions.
24 changes: 18 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ name: ci
- '**'

permissions:
contents: read
contents: write

jobs:
ci:
Expand All @@ -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/
Expand All @@ -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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
.DS_Store
*.swp
*.tar.xz
*.tar.gz

/.idea
node_modules
Expand Down
62 changes: 62 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
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'



# ---------------------------------------
# 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}
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 223727b

Please sign in to comment.