All checks were successful
Deploy to dev.bl.pixeldev.eu / deploy (push) Successful in 2s
72 lines
2.3 KiB
YAML
72 lines
2.3 KiB
YAML
name: Deploy to dev.bl.pixeldev.eu
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
|
|
jobs:
|
|
deploy:
|
|
runs-on: self-hosted
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v3
|
|
|
|
- name: Detect project type
|
|
id: detect
|
|
run: |
|
|
if [ -f package.json ]; then
|
|
echo "type=node" >> $GITHUB_OUTPUT
|
|
else
|
|
echo "type=static" >> $GITHUB_OUTPUT
|
|
fi
|
|
|
|
- name: Sync files
|
|
run: |
|
|
SLUG="${{ github.event.repository.name }}"
|
|
mkdir -p /opt/deployed/${SLUG}
|
|
rsync -av --delete --exclude='.git' --exclude='node_modules' \
|
|
$GITHUB_WORKSPACE/ /opt/deployed/${SLUG}/
|
|
|
|
- name: Install dependencies
|
|
if: steps.detect.outputs.type == 'node'
|
|
run: |
|
|
cd /opt/deployed/${{ github.event.repository.name }}
|
|
npm install --production
|
|
|
|
- name: Start / restart Node service
|
|
if: steps.detect.outputs.type == 'node'
|
|
id: node
|
|
run: |
|
|
SLUG="${{ github.event.repository.name }}"
|
|
DIR="/opt/deployed/${SLUG}"
|
|
|
|
# Find entry point
|
|
ENTRY=""
|
|
for f in server.js index.js src/server.js src/index.js; do
|
|
[ -f "$DIR/$f" ] && ENTRY="$DIR/$f" && break
|
|
done
|
|
[ -z "$ENTRY" ] && ENTRY=$(node -e "const p=require('$DIR/package.json'); console.log('$DIR/'+p.main)" 2>/dev/null)
|
|
|
|
# Allocate port (base 4000 + hash of slug)
|
|
PORT=$((4000 + $(echo -n "$SLUG" | cksum | cut -d' ' -f1) % 1000))
|
|
|
|
# Start or restart
|
|
pm2 delete "deploy-${SLUG}" 2>/dev/null || true
|
|
PORT=$PORT pm2 start "$ENTRY" --name "deploy-${SLUG}"
|
|
|
|
echo "port=$PORT" >> $GITHUB_OUTPUT
|
|
|
|
- name: Register with dev registry
|
|
run: |
|
|
SLUG="${{ github.event.repository.name }}"
|
|
NAME="${{ github.event.repository.name }}"
|
|
TYPE="${{ steps.detect.outputs.type }}"
|
|
PORT="${{ steps.node.outputs.port }}"
|
|
|
|
curl -s -X POST https://dev.bl.pixeldev.eu/api/register \
|
|
-H "Content-Type: application/json" \
|
|
-u admin:blaetternd-helix-dribbble124 \
|
|
-d "{\"name\":\"${NAME}\",\"slug\":\"${SLUG}\",\"type\":\"${TYPE}\",\"port\":\"${PORT}\"}"
|
|
|
|
echo "✅ Live at https://dev.bl.pixeldev.eu/${SLUG}/"
|