Skip to content

Commit

Permalink
Merge pull request #1 from setoelkahfi/development
Browse files Browse the repository at this point in the history
v1
  • Loading branch information
setoelkahfi authored Apr 29, 2023
2 parents 4b5cd63 + 8018f7e commit 6a5d6e1
Show file tree
Hide file tree
Showing 3 changed files with 159 additions and 0 deletions.
58 changes: 58 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# garust-debian

GitHub Action to running Rust binary on Debian Bulls Eye using SSH `rsync`.

## Supported runner

`ubuntu-20.04`

[What is my Debian in my Ubuntu?](https://askubuntu.com/a/445496/513710).

## Input

```yaml
working-directory:
description: "Working directory for the build."
required: true
binary-name:
description: "Name of the binary to run. Usually the [[bin]] value in the Cargo.toml."
required: true
ssh-user:
description: "SSH user."
required: true
ssh-host:
description: "SSH host."
required: true
ssh-private-key:
description: "SSH private key."
required: true
ssh-known-hosts:
description: "SSH known hosts."
required: true
```
## Example
```yaml
name: "Build and release"

on:
push:
branches:
- main

jobs:
build-and-release:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- uses: setoelkahfi/garust-debian@v1
with: Install Rust stable
ssh-key: ${{ secrets.SSH_PRIVATE_KEY }}
ssh-known-hosts: ${{ secrets.SSH_KNOWN_HOSTS }}
ssh-user: ${{ secrets.SSH_USER }}
ssh-host: ${{ secrets.SSH_HOST }}
project-directory: ${{ secrets.PROJECT_DIRECTORY }}
project-name: ${{ secrets.PROJECT_NAME }}

```
41 changes: 41 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: "GitHub Action Rust-on-Debian"
description: "GitHub Action to running Rust binary on Debian Bulls Eye."
inputs:
project-directory:
description: "Working directory for the build."
required: true
project-name:
description: "Name of the binary to run."
required: true
ssh-user:
description: "SSH user."
required: true
ssh-host:
description: "SSH host."
required: true
ssh-private-key:
description: "SSH private key."
required: true
ssh-known-hosts:
description: "SSH known hosts."
required: true

runs:
using: "composite"
steps:
- name: Install Rust stable
uses: dtolnay/rust-toolchain@stable
- name: Build for release
run: cargo build --release
shell: bash
- name: Install SSH key
uses: shimataro/ssh-key-action@v2
with:
key: ${{ inputs.ssh-private-key }}
known_hosts: ${{ inputs.ssh-known-hosts }}
- name: rsync over SSH
run: rsync -r ./target/release/ ${{ inputs.ssh-user }}@${{ inputs.ssh-host }}:${{ inputs.project-directory }}
shell: bash
- name: Start process
run: ssh ${{ inputs.ssh-user }}@${{ inputs.ssh-host }} 'bash -s' < start.sh ./${{ inputs.project-directory }} ${{ inputs.project-name }}
shell: bash
60 changes: 60 additions & 0 deletions start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/bin/bash

echo "------------------------ STARTING DEPLOYMENT ------------------------"

# Check if the first argument is a directory
if [ ! -d "$1" ]
then
echo "😩 $1 is not a directory."
echo "🛑 Deployment failed."
exit 1
fi

# Change to working directory
cd $1

# Check if process is running

# Check if the second argument is a process
if [ -z "$2" ]
then
echo "😩 No process name provided."
echo "🛑 Deployment failed."
exit 1
fi
process_name=$2

# Check if binary exists
if [ ! -f "$process_name" ]
then
echo "😩 $process_name does not exist."
echo "🛑 Deployment failed."
exit 1
fi

echo "✅ Arguments are valid."

# Check if process is running
echo "🔍 Looking for $process_name process."
PID=$(pidof $process_name)

echo "🤨 Killing or not killing $process_name."

if [ ! -z "$PID" ]
then
echo "$process_name is running as $PID."
echo "⏳ Killing it."
kill -9 $PID
echo "✅ Killed $process_name."
else
echo "$process_name is not running."
echo "No killing needed."
fi

echo "🚀 Starting $process_name."

./$process_name > /dev/null 2>&1 &

echo "------------------------ DEPLOYMENT COMPLETED ------------------------"

exit 0

0 comments on commit 6a5d6e1

Please sign in to comment.