Refactor Dappbundle push workflow for SSH commands
Some checks failed
Workflow push to Dappbundle / Build (push) Has been cancelled

This commit is contained in:
Aniruddha 2026-01-12 18:28:31 +05:30 committed by GitHub
parent 377bc781f9
commit 98f25e59b9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,58 +1,32 @@
- name: Install OpenSSH client (if needed) name: Workflow push to Dappbundle
run: | on: [push]
if ! command -v ssh >/dev/null 2>&1; then jobs:
sudo apt-get update build:
sudo apt-get install -y openssh-client name: Build
fi runs-on: self-hosted
steps:
- name: Executing remote command
uses: appleboy/ssh-action@v1.0.0
with:
host: ${{ secrets.R_HOST }}
username: ${{ secrets.P_USERNAME }}
password: ${{ secrets.P_PASSWORD }}
port: ${{ secrets.SSH_PORT }}
script: |
if [ -d "${{ secrets.DEPLOYMENT_LOCATION}}/dappbundle" ]; then
echo "Folder exists. Skipping Git clone."
else
echo "Folder does not exist. Cloning repository..."
cd ${{ secrets.DEPLOYMENT_LOCATION}}/ && git clone https://github.com/ranchimall/dappbundle.git
fi
- name: Run remote script over SSH if [ -d "${{ secrets.DEPLOYMENT_LOCATION}}/dappbundle/${{ github.event.repository.name }}" ]; then
env: echo "Repository exists. Remove folder "
R_HOST: ${{ secrets.R_HOST }} rm -r "${{ secrets.DEPLOYMENT_LOCATION}}/dappbundle/${{ github.event.repository.name }}"
P_USERNAME: ${{ secrets.P_USERNAME }} fi
P_PASSWORD: ${{ secrets.P_PASSWORD }}
SSH_PORT: ${{ secrets.SSH_PORT }}
run: |
# If you must use password auth, install sshpass (prefer SSH keys in the long run)
if ! command -v sshpass >/dev/null 2>&1; then
sudo apt-get update
sudo apt-get install -y sshpass
fi
sshpass -p "$P_PASSWORD" ssh \ echo "Cloning repository..."
-o StrictHostKeyChecking=no \ cd ${{ secrets.DEPLOYMENT_LOCATION}}/dappbundle && git clone https://github.com/ranchimall/${{ github.event.repository.name }}
-o UserKnownHostsFile=/dev/null \
-p "$SSH_PORT" "$P_USERNAME@$R_HOST" bash -s <<'REMOTE'
set -euo pipefail
if [ -d "${{ secrets.DEPLOYMENT_LOCATION }}/dappbundle" ]; then cd "${{ secrets.DEPLOYMENT_LOCATION}}/dappbundle/${{ github.event.repository.name }}" && rm -rf .gitattributes .git .github .gitignore
echo "Folder exists. Skipping Git clone." cd ${{ secrets.DEPLOYMENT_LOCATION}}/dappbundle/ && git add . && git commit -m "Workflow updating files of ${{ github.event.repository.name }}" && git push "https://saketongit:${{ secrets.RM_ACCESS_TOKEN }}@github.com/ranchimall/dappbundle.git"
else
echo "Folder does not exist. Cloning repository..."
cd "${{ secrets.DEPLOYMENT_LOCATION }}/" && git clone https://github.com/ranchimall/dappbundle.git
fi
cd "${{ secrets.DEPLOYMENT_LOCATION }}/dappbundle"
git config user.name "ranchimall-bot" || true
git config user.email "bot@ranchimall.net" || true
if [ -d "${{ secrets.DEPLOYMENT_LOCATION }}/dappbundle/${{ github.event.repository.name }}" ]; then
echo "Repository exists. Remove folder"
rm -rf "${{ secrets.DEPLOYMENT_LOCATION }}/dappbundle/${{ github.event.repository.name }}"
fi
echo "Cloning repository..."
cd "${{ secrets.DEPLOYMENT_LOCATION }}/dappbundle" && \
git clone --depth=1 "https://github.com/ranchimall/${{ github.event.repository.name }}"
cd "${{ secrets.DEPLOYMENT_LOCATION }}/dappbundle/${{ github.event.repository.name }}" && \
rm -rf .gitattributes .git .github .gitignore
cd "${{ secrets.DEPLOYMENT_LOCATION }}/dappbundle"
git add -A .
if git diff --cached --quiet; then
echo "No changes detected. Skipping commit and push."
else
git commit -m "Workflow updating files of ${{ github.event.repository.name }}"
git push "https://ranchimalldev:${{ secrets.RM_ACCESS_TOKEN }}@github.com/ranchimall/dappbundle.git"
fi
REMOTE