Update push-dappbundle.yml

This commit is contained in:
tripathyr 2025-07-31 10:05:22 +05:30 committed by GitHub
parent 1e49d276fd
commit 0ace7c250a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,68 +1,58 @@
name: Workflow push to Dappbundle - name: Install OpenSSH client (if needed)
on: [push] run: |
if ! command -v ssh >/dev/null 2>&1; then
sudo apt-get update
sudo apt-get install -y openssh-client
fi
jobs: - name: Run remote script over SSH
build: env:
name: Build R_HOST: ${{ secrets.R_HOST }}
runs-on: self-hosted P_USERNAME: ${{ secrets.P_USERNAME }}
steps: P_PASSWORD: ${{ secrets.P_PASSWORD }}
# Optional diagnostics — helps confirm which runner ran and whether Docker perms are OK SSH_PORT: ${{ secrets.SSH_PORT }}
- name: Print runner info run: |
run: | # If you must use password auth, install sshpass (prefer SSH keys in the long run)
echo "Runner name: $RUNNER_NAME" if ! command -v sshpass >/dev/null 2>&1; then
echo "Runner OS: $RUNNER_OS" sudo apt-get update
echo "Runner arch: $RUNNER_ARCH" sudo apt-get install -y sshpass
echo "Runner user: $(whoami)" fi
echo "Runner groups: $(id -nG)"
docker --version || echo "Docker not found"
ls -l /var/run/docker.sock || true
docker ps >/dev/null 2>&1 && echo "docker ps OK" || echo "docker ps failed (permission?)"
- name: Executing remote command sshpass -p "$P_PASSWORD" ssh \
uses: appleboy/ssh-action@v1.0.0 -o StrictHostKeyChecking=no \
with: -o UserKnownHostsFile=/dev/null \
host: ${{ secrets.R_HOST }} -p "$SSH_PORT" "$P_USERNAME@$R_HOST" bash -s <<'REMOTE'
username: ${{ secrets.P_USERNAME }} set -euo pipefail
password: ${{ secrets.P_PASSWORD }}
port: ${{ secrets.SSH_PORT }}
script: |
set -euo pipefail
# 1) Ensure dappbundle exists if [ -d "${{ secrets.DEPLOYMENT_LOCATION }}/dappbundle" ]; then
if [ -d "${{ secrets.DEPLOYMENT_LOCATION }}/dappbundle" ]; then echo "Folder exists. Skipping Git clone."
echo "Folder exists. Skipping Git clone." else
else echo "Folder does not exist. Cloning repository..."
echo "Folder does not exist. Cloning repository..." cd "${{ secrets.DEPLOYMENT_LOCATION }}/" && git clone https://github.com/ranchimall/dappbundle.git
cd "${{ secrets.DEPLOYMENT_LOCATION }}/" && git clone https://github.com/ranchimall/dappbundle.git fi
fi
# Optional: ensure identity is set once, avoids commit failures if not configured cd "${{ secrets.DEPLOYMENT_LOCATION }}/dappbundle"
cd "${{ secrets.DEPLOYMENT_LOCATION }}/dappbundle" git config user.name "ranchimall-bot" || true
git config user.name "ranchimall-bot" || true git config user.email "bot@ranchimall.net" || true
git config user.email "bot@ranchimall.net" || true
# 2) Remove old copy of target repo folder if [ -d "${{ secrets.DEPLOYMENT_LOCATION }}/dappbundle/${{ github.event.repository.name }}" ]; then
if [ -d "${{ secrets.DEPLOYMENT_LOCATION }}/dappbundle/${{ github.event.repository.name }}" ]; then echo "Repository exists. Remove folder"
echo "Repository exists. Remove folder" rm -rf "${{ secrets.DEPLOYMENT_LOCATION }}/dappbundle/${{ github.event.repository.name }}"
rm -rf "${{ secrets.DEPLOYMENT_LOCATION }}/dappbundle/${{ github.event.repository.name }}" fi
fi
# 3) Clone fresh copy of the source repo into dappbundle echo "Cloning repository..."
echo "Cloning repository..." cd "${{ secrets.DEPLOYMENT_LOCATION }}/dappbundle" && \
cd "${{ secrets.DEPLOYMENT_LOCATION }}/dappbundle" && \ git clone --depth=1 "https://github.com/ranchimall/${{ github.event.repository.name }}"
git clone --depth=1 "https://github.com/ranchimall/${{ github.event.repository.name }}"
# 4) Strip Git metadata from the inner repo (kept exactly as in your script) cd "${{ secrets.DEPLOYMENT_LOCATION }}/dappbundle/${{ github.event.repository.name }}" && \
cd "${{ secrets.DEPLOYMENT_LOCATION }}/dappbundle/${{ github.event.repository.name }}" && \ rm -rf .gitattributes .git .github .gitignore
rm -rf .gitattributes .git .github .gitignore
# 5) Stage everything, commit iff there are changes, then push cd "${{ secrets.DEPLOYMENT_LOCATION }}/dappbundle"
cd "${{ secrets.DEPLOYMENT_LOCATION }}/dappbundle" git add -A .
git add -A . if git diff --cached --quiet; then
echo "No changes detected. Skipping commit and push."
if git diff --cached --quiet; then else
echo "No changes detected. Skipping commit and push." git commit -m "Workflow updating files of ${{ github.event.repository.name }}"
else git push "https://ranchimalldev:${{ secrets.RM_ACCESS_TOKEN }}@github.com/ranchimall/dappbundle.git"
git commit -m "Workflow updating files of ${{ github.event.repository.name }}" fi
git push "https://ranchimalldev:${{ secrets.RM_ACCESS_TOKEN }}@github.com/ranchimall/dappbundle.git" REMOTE
fi