Skip to content

Commit abebfc4

Browse files
initial commit
0 parents  commit abebfc4

File tree

6 files changed

+172
-0
lines changed

6 files changed

+172
-0
lines changed

.github/workflows/lint-files.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
name: Lint Action file
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- main
8+
pull_request:
9+
branches:
10+
- main
11+
12+
jobs:
13+
lint-yaml:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v4
18+
19+
- name: Set up Python
20+
uses: actions/setup-python@v4
21+
with:
22+
python-version: '3.x'
23+
24+
- name: Install yamllint
25+
run: pip install yamllint
26+
27+
- name: Lint YAML files
28+
run: yamllint . --strict

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.idea

.yamllint

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
rules:
3+
line-length:
4+
max: 200
5+
truthy: {check-keys: false}

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# git-deploy-poc
2+
Deploy code to remote server

action.yml

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
---
2+
name: 'Deploy Repository via rsync'
3+
description: 'A custom action to deploy a repository to a remote server using rsync.'
4+
5+
inputs:
6+
remote_host:
7+
description: 'The remote host (IP or domain)'
8+
required: true
9+
ssh_user:
10+
description: 'The SSH username'
11+
required: true
12+
ssh_private_key:
13+
description: 'SSH Server private key'
14+
required: true
15+
16+
runs:
17+
using: 'composite'
18+
steps:
19+
- name: Config action
20+
id: config
21+
shell: bash
22+
run: |
23+
sudo apt-get update -q && sudo apt-get install -y rsync sshpass
24+
25+
mkdir -p ~/.ssh output
26+
ssh-keyscan -H "${{ inputs.remote_host }}" >> ~/.ssh/known_hosts
27+
28+
ACTION_PATH="${{ github.action_path }}"
29+
TAG_NAME=$(basename "$ACTION_PATH")
30+
echo "ACTION_TAG=$TAG_NAME" >> $GITHUB_ENV
31+
echo "Tag name: $TAG_NAME"
32+
33+
echo "::set-output name=ACTION_TAG::$TAG_NAME"
34+
echo "CHECKOUT_DIR=git_checkout" >> $GITHUB_ENV
35+
echo "ACTION_DIR=action_dir" >> $GITHUB_ENV
36+
echo "IGNORE_FILE=action_dir/ignore_files.txt" >> $GITHUB_ENV
37+
echo "OUTPUT_DIR=output" >> $GITHUB_ENV
38+
echo "SYNC_FILE_LIST=output/files_to_sync.txt" >> $GITHUB_ENV
39+
echo "REMOTE_DIR=/html/deployer" >> $GITHUB_ENV
40+
echo "SSH_USER=${{ inputs.ssh_user }}" >> $GITHUB_ENV
41+
echo "SSH_HOST=${{ inputs.remote_host }}" >> $GITHUB_ENV
42+
43+
TAR_NAME="repository_$(openssl rand -hex 4).tar.gz"
44+
echo "TAR_NAME=$TAR_NAME" >> $GITHUB_ENV
45+
echo "TAR_FILE=output/$TAR_NAME" >> $GITHUB_ENV
46+
47+
TEMP_KEY_FILE="private_key"
48+
echo "${{ inputs.ssh_private_key }}" > "$TEMP_KEY_FILE"
49+
chmod 600 "$TEMP_KEY_FILE"
50+
echo "TEMP_KEY_FILE=$TEMP_KEY_FILE" >> $GITHUB_ENV
51+
52+
- name: Checkout repository
53+
with:
54+
path: git_checkout
55+
uses: actions/checkout@v3
56+
57+
- name: Checkout Action
58+
with:
59+
path: action_dir
60+
repository: narethiya-godaddy/git-deploy-poc
61+
ref: ${{ steps.config.outputs.ACTION_TAG }}
62+
uses: actions/checkout@v3
63+
64+
- name: Create tar file
65+
shell: bash
66+
run: |
67+
EXCLUDE_ARGS=""
68+
while IFS= read -r line; do
69+
EXCLUDE_ARGS+="--exclude=$line "
70+
done < "$IGNORE_FILE"
71+
72+
echo "Preparing a changed file list..."
73+
rsync -av --dry-run --checksum -e "ssh -i $TEMP_KEY_FILE -o StrictHostKeyChecking=no" $EXCLUDE_ARGS $CHECKOUT_DIR/ "$SSH_USER@$SSH_HOST:/html/" | grep -v '/$' > $SYNC_FILE_LIST
74+
sed -i '1d;N;$!P;$!D;$d;$d' "$SYNC_FILE_LIST"
75+
76+
echo "Files to be synchronized:"
77+
cat "$SYNC_FILE_LIST"
78+
echo "End of list."
79+
80+
cd $CHECKOUT_DIR
81+
echo "Creating tar file: $TAR_FILE"
82+
tar -czvf "../$TAR_FILE" -T "../$SYNC_FILE_LIST"
83+
cd ../
84+
echo "Tar file created successfully."
85+
86+
- name: Upload tar file to server
87+
shell: bash
88+
run: |
89+
echo "Creating remote directory: $REMOTE_DIR"
90+
ssh -i $TEMP_KEY_FILE -o StrictHostKeyChecking=no "$SSH_USER@$SSH_HOST" "mkdir -p '$REMOTE_DIR' || exit 1"
91+
echo "Uploading tar file to $REMOTE_DIR"
92+
93+
rsync -avz --delete -e "ssh -i $TEMP_KEY_FILE -o StrictHostKeyChecking=no" $TAR_FILE "$SSH_USER@$SSH_HOST:$REMOTE_DIR/"
94+
echo "Tar file uploaded successfully."
95+
96+
- name: Clean up
97+
shell: bash
98+
run: |
99+
echo "Cleaning up temporary files..."
100+
rm -rf $OUTPUT_DIR $CHECKOUT_DIR $ACTION_DIR
101+
echo "Temporary files cleaned up successfully."
102+
103+
- name: Run Deployer
104+
shell: bash
105+
run: |
106+
echo "Run Server deployer"
107+
ssh -i $TEMP_KEY_FILE -o StrictHostKeyChecking=no "$SSH_USER@$SSH_HOST" "/html/deployer.sh $TAR_NAME || exit 1"
108+
rm -f $TEMP_KEY_FILE

ignore_files.txt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
.git
2+
.github
3+
Thumbs.db
4+
.gitignore
5+
.htaccess
6+
readme.md
7+
.gitignore
8+
index.php
9+
plat-cron.php
10+
wp-activate.php
11+
wp-blog-header.php
12+
wp-comments-post.php
13+
wp-cron.php
14+
wp-links-opml.php
15+
wp-load.php
16+
wp-login.php
17+
wp-mail.php
18+
wp-settings.php
19+
wp-signup.php
20+
wp-trackback.php
21+
xmlrpc.php
22+
platform/
23+
wp-admin/
24+
wp-includes/
25+
wp-content/mu-plugins/
26+
wp-content/object-cache.php
27+
wp-content/uploads/
28+
*.log

0 commit comments

Comments
 (0)