Skip to content

Commit

Permalink
fix: update functions
Browse files Browse the repository at this point in the history
  • Loading branch information
tanhongit committed Nov 9, 2024
1 parent ededc5b commit 06b181a
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 47 deletions.
4 changes: 2 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#SOURCE_DIR=~/source
SOURCE_DIR=/home/user/cslant.com/home
SOURCE_DIR=/home/user/cslant.com/blog

GIT_SSH_URL=[email protected]:cslant

# The name of the runner
WORKER_NAME="CSlant Home"
WORKER_NAME="CSlant Blog"

# add the env to choose "npm" or "yarn" as the installer
INSTALLER=yarn
Expand Down
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# CSlant Home Runner
# CSlant Blog Runner

```text
██╗ ██╗ ██████╗ ██╗ ██████████ ██████╗ ██╗ ██╗███╗ ██╗███╗ ██╗███████╗██████╗
██║ ██║██╔══██╗████╗ ████║██╔════╝ ██╔══██╗██║ ██║████╗ ██║████╗ ██║██╔════╝██╔══██╗
███████║██║ ██║██╔████╔██║█████╗ ██████╔╝██║ ██║██╔██╗ ██║██╔██╗ ██║█████╗ ██████╔╝
██╔══████║ ██║██║╚██╔╝██║██╔══╝ ██╔══██╗██║ ██║██║╚██╗██║██║╚██╗██║██╔══╝ ██╔══██╗
██║ ██║╚██████╔╝██║ ╚═╝ ██║███████ ██║ ██║╚██████╔╝██║ ╚████║██║ ╚████║███████╗██║ ██║
╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══╝╚═╝ ╚═══╝╚══════╝╚═╝ ╚═╝
██████╗ ██╗ ████████████╗ ██████╗ ██╗ ██╗███╗ ██╗███╗ ██╗███████╗██████╗
██╔══██╗██║ ██╔═══██╗██╔════╝ ██╔══██╗██║ ██║████╗ ██║████╗ ██║██╔════╝██╔══██╗
██████╔╝██║ ██║ ██║█████ ██████╔╝██║ ██║██╔██╗ ██║██╔██╗ ██║█████╗ ██████╔╝
██╔══████║ ██║ ██║██║ ██║ ██╔══██╗██║ ██║██║╚██╗██║██║╚██╗██║██╔══╝ ██╔══██╗
██████╔╝███████╗╚██████╔╝╚██████╔╝ ██║ ██║╚██████╔╝██║ ╚████║██║ ╚████║███████╗██║ ██║
╚═════╝ ╚═════╝ ╚═════╚═════ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══╝╚═╝ ╚═══╝╚══════╝╚═╝ ╚═╝
```

This repo is to set up the runner for updating the homepage at https://cslant.com
This repo is to set up the runner for updating the homepage at https://cslant.com/blog

We can use this runner to update the Home automatically with CI/CD pipelines.
We can use this runner to update the Blog automatically with CI/CD pipelines.

## Installation

Expand All @@ -27,12 +27,12 @@ In the `.env` file, update the values to match your environment.
# .env

#SOURCE_DIR=~/source
SOURCE_DIR=/home/user/cslant.com/home
SOURCE_DIR=/home/user/cslant.com/blog

[email protected]:cslant

# The name of the runner
WORKER_NAME="CSlant Home"
WORKER_NAME="CSlant Blog"

# add the env to choose "npm" or "yarn" as the installer
INSTALLER=yarn
Expand Down Expand Up @@ -63,6 +63,6 @@ The runner has the following commands:
| Command | Description |
|----------------|------------------------------|
| `help`, `tips` | Shows the help message |
| `build`, `b` | Builds the Home |
| `build`, `b` | Builds the Blog |
| `worker`, `w` | Create or restart the worker |
| `all`, `a` | Runs all the commands |
12 changes: 6 additions & 6 deletions runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ case "$1" in
usage
;;

home_sync)
home_sync "$2"
blog_sync)
blog_sync "$2"
;;

build | build_home | b)
build | build_blog | b)
build_fe "${2:-install}"
;;

Expand All @@ -34,10 +34,10 @@ case "$1" in
;;

all | a)
home_sync all
build_fe install
blog_sync all
# build_fe install
build_api install
worker
# worker
;;

*)
Expand Down
34 changes: 17 additions & 17 deletions setup/functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ build_fe() {

BUILD_TYPE="$1"

cd "$HOME_FE_DIR" || exit
cd "$BLOG_FE_DIR" || exit

if [ ! -f "$HOME_FE_DIR/.env" ]; then
if [ ! -f "$BLOG_FE_DIR/.env" ]; then
echo ' ∟ .env file missing, copying from .env.example...'
cp "$HOME_FE_DIR/.env.example" "$HOME_FE_DIR/.env"
cp "$BLOG_FE_DIR/.env.example" "$BLOG_FE_DIR/.env"
fi

home_resource_env
blog_resource_env

if ! command -v nvm &> /dev/null; then
# shellcheck disable=SC2155
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
export NVM_DIR="$([ -z "${XDG_CONFIG_BLOG-}" ] && printf %s "${BLOG}/.nvm" || printf %s "${XDG_CONFIG_BLOG}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
fi
nvm use "$NODE_VERSION"
Expand All @@ -26,7 +26,7 @@ build_fe() {
npm install -g yarn
fi

if [ ! -d "$HOME_FE_DIR/node_modules" ] || [ "$BUILD_TYPE" = "install" ]; then
if [ ! -d "$BLOG_FE_DIR/node_modules" ] || [ "$BUILD_TYPE" = "install" ]; then
echo ' ∟ Installing dependencies...'
if [ "$INSTALLER" = "yarn" ]; then
yarn install
Expand Down Expand Up @@ -54,7 +54,7 @@ build_fe() {
worker() {
echo '📽 Starting worker...'

cd "$HOME_FE_DIR" || exit
cd "$BLOG_FE_DIR" || exit

if pm2 show "$WORKER_NAME" > /dev/null; then
echo " ∟ Restarting $WORKER_NAME..."
Expand All @@ -71,7 +71,7 @@ worker() {
node_runner() {
echo '🏃‍♂️ Running node...'

cd "$HOME_FE_DIR" || exit
cd "$BLOG_FE_DIR" || exit

if [ "$INSTALLER" = "yarn" ]; then
yarn "$@"
Expand All @@ -92,11 +92,11 @@ build_api() {
COMPOSER_COMMAND="update"
fi

cd "$HOME_API_DIR" || exit
cd "$BLOG_ADMIN_DIR" || exit

if [ ! -f "$HOME_API_DIR/.env" ]; then
if [ ! -f "$BLOG_ADMIN_DIR/.env" ]; then
echo ' ∟ .env file missing, copying from .env.example...'
cp "$HOME_API_DIR/.env.example" "$HOME_API_DIR/.env"
cp "$BLOG_ADMIN_DIR/.env.example" "$BLOG_ADMIN_DIR/.env"
composer $COMPOSER_COMMAND
php artisan key:generate
else
Expand All @@ -106,17 +106,17 @@ build_api() {
echo ''
}

home_resource_env() {
blog_resource_env() {
echo '🔧 Setting up home resource environment...'

cd "$HOME_FE_DIR" || exit
cd "$BLOG_FE_DIR" || exit

HOME_RESOURCE_DIR="$HOME_DIR/home-resource"
BLOG_RESOURCE_DIR="$BLOG_DIR/blog-resource"

# check and replace "PUBLIC_DIR=/Users/tanhongit/Data/CSlant/home-resource/public" to "PUBLIC_DIR=$HOME_RESOURCE_DIR/public"
if [ -f "$HOME_FE_DIR/.env" ] && ! grep -q "PUBLIC_DIR=$HOME_RESOURCE_DIR/public" "$HOME_FE_DIR/.env"; then
# check and replace "PUBLIC_DIR=/Users/tanhongit/Data/CSlant/blog-resource/public" to "PUBLIC_DIR=$BLOG_RESOURCE_DIR/public"
if [ -f "$BLOG_FE_DIR/.env" ] && ! grep -q "PUBLIC_DIR=$BLOG_RESOURCE_DIR/public" "$BLOG_FE_DIR/.env"; then
echo ' ∟ Setting up PUBLIC_DIR...'
awk -v HOME_RESOURCE_DIR="$HOME_RESOURCE_DIR" '/PUBLIC_DIR=/{gsub(/PUBLIC_DIR=.*/, "PUBLIC_DIR="HOME_RESOURCE_DIR"/public")}1' "$HOME_FE_DIR/.env" >"$HOME_FE_DIR/.env.tmp" && mv "$HOME_FE_DIR/.env.tmp" "$HOME_FE_DIR/.env"
awk -v BLOG_RESOURCE_DIR="$BLOG_RESOURCE_DIR" '/PUBLIC_DIR=/{gsub(/PUBLIC_DIR=.*/, "PUBLIC_DIR="BLOG_RESOURCE_DIR"/public")}1' "$BLOG_FE_DIR/.env" >"$BLOG_FE_DIR/.env.tmp" && mv "$BLOG_FE_DIR/.env.tmp" "$BLOG_FE_DIR/.env"
else
echo ' ∟ PUBLIC_DIR already set up...'
fi
Expand Down
24 changes: 14 additions & 10 deletions setup/tips.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

welcome() {
echo '
██╗ ██╗ ██████╗ ██╗ ██████████ ██████╗ ██╗ ██╗███╗ ██╗███╗ ██╗███████╗██████╗
██║ ██║██╔══██╗████╗ ████║██╔════╝ ██╔══██╗██║ ██║████╗ ██║████╗ ██║██╔════╝██╔══██╗
███████║██║ ██║██╔████╔██║█████╗ ██████╔╝██║ ██║██╔██╗ ██║██╔██╗ ██║█████╗ ██████╔╝
██╔══████║ ██║██║╚██╔╝██║██╔══╝ ██╔══██╗██║ ██║██║╚██╗██║██║╚██╗██║██╔══╝ ██╔══██╗
██║ ██║╚██████╔╝██║ ╚═╝ ██║███████ ██║ ██║╚██████╔╝██║ ╚████║██║ ╚████║███████╗██║ ██║
╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══╝╚═╝ ╚═══╝╚══════╝╚═╝ ╚═╝
'
██████╗ ██╗ ████████████╗ ██████╗ ██╗ ██╗███╗ ██╗███╗ ██╗███████╗██████╗
██╔══██╗██║ ██╔═══██╗██╔════╝ ██╔══██╗██║ ██║████╗ ██║████╗ ██║██╔════╝██╔══██╗
██████╔╝██║ ██║ ██║█████ ██████╔╝██║ ██║██╔██╗ ██║██╔██╗ ██║█████╗ ██████╔╝
██╔══████║ ██║ ██║██║ ██║ ██╔══██╗██║ ██║██║╚██╗██║██║╚██╗██║██╔══╝ ██╔══██╗
██████╔╝███████╗╚██████╔╝╚██████╔╝ ██║ ██║╚██████╔╝██║ ╚████║██║ ╚████║███████╗██║ ██║
╚═════╝ ╚═════╝ ╚═════╚═════ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══╝╚═╝ ╚═══╝╚══════╝╚═╝ ╚═╝
'
echo ''
echo '⚡ Welcome to the blog runner!'
echo ''
Expand All @@ -31,9 +31,13 @@ usage() {
echo ' all Sync git and blog repository, build blog'
echo ''
echo 'Args for blog_sync:'
echo ' fe Sync frontend blog repository'
echo ' api Sync backend API blog repository'
echo ' all Sync all blog repository'
echo ' resources Sync resources blog repository'
echo ' fe Sync frontend blog repository'
echo ' admin Sync backend admin blog repository'
echo ' private_modules Sync private modules blog repository'
echo ' core_package Sync core package blog repository'
echo ' api_package Sync api package blog repository'
echo ' all Sync all blog repository'
echo ''
echo 'Args for build:'
echo ' install Install dependencies and build (default, if not set)'
Expand Down

0 comments on commit 06b181a

Please sign in to comment.