test2/.gitea/workflows/deploy.yml
openclaw ac6aa03788
All checks were successful
Deploy to dev.bl.pixeldev.eu / deploy (push) Successful in 2s
Use openclaw token; drop admin basic auth; auto-register webhook
2026-03-13 13:43:22 +00:00

84 lines
3.1 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}"
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)
PORT=$((4000 + $(echo -n "$SLUG" | cksum | cut -d' ' -f1) % 1000))
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 }}"
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" \
-d "{\"name\":\"${SLUG}\",\"slug\":\"${SLUG}\",\"type\":\"${TYPE}\",\"port\":\"${PORT}\"}"
echo "✅ Live at https://dev.bl.pixeldev.eu/${SLUG}/"
- name: Ensure webhook exists
run: |
REPO="${{ github.repository }}"
# Check if openclaw webhook already registered
EXISTS=$(curl -s -H "Authorization: token ${{ secrets.OC_TOKEN }}" \
"http://127.0.0.1:3040/api/v1/repos/${REPO}/hooks" \
| python3 -c "import sys,json; hooks=json.load(sys.stdin); print('yes' if any('3050/webhook' in str(h.get('config',{}).get('url','')) for h in hooks) else 'no')" 2>/dev/null)
if [ "$EXISTS" != "yes" ]; then
curl -s -H "Authorization: token ${{ secrets.OC_TOKEN }}" \
-X POST "http://127.0.0.1:3040/api/v1/repos/${REPO}/hooks" \
-H "Content-Type: application/json" \
-d '{"type":"gitea","config":{"url":"http://127.0.0.1:3050/webhook/gitea","content_type":"json","secret":"wh-bl-openclaw-2026"},"events":["issues","issue_comment"],"active":true}'
echo "Webhook registered"
else
echo "Webhook already present"
fi