Skip to content

Commit

Permalink
Adding CD workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
ndefokou committed Nov 18, 2024
1 parent d485d74 commit 2acad7d
Showing 1 changed file with 36 additions and 10 deletions.
46 changes: 36 additions & 10 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Rust CI
name: Rust CI/CD

on:
push:
Expand All @@ -12,8 +12,9 @@ env:
CARGO_TERM_COLOR: always

jobs:
build:
name: Build, Test, and Lint
# Continuous Integration Job
ci:
name: Continuous Integration
runs-on: ubuntu-latest

steps:
Expand Down Expand Up @@ -45,13 +46,8 @@ jobs:

- name: Create example env file
run: |
if [ -f .github/scripts/test_config.sh ]; then
chmod +x .github/scripts/test_config.sh
sh .github/scripts/test_config.sh
else
echo "No test_config.sh script found, skipping..."
fi
chmod +x .github/scripts/test_config.sh
sh .github/scripts/test_config.sh
- name: Run Clippy (Lint)
run: cargo clippy --workspace --all-targets --all-features -- -D warnings

Expand All @@ -63,3 +59,33 @@ jobs:

- name: Run Tests
run: cargo nextest run --workspace --all-features

# Continuous Deployment Job
cd:
name: Continuous Deployment
needs: ci
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Rust
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: stable

- name: Build Release
run: cargo build --release --workspace --all-features

- name: Deploy to Production
env:
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
HOST: ${{ secrets.PRODUCTION_HOST }}
USER: ${{ secrets.PRODUCTION_USER }}
run: |
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ssh_key
chmod 600 ssh_key
scp -i ssh_key target/release/your_binary ${{ env.USER }}@${{ env.HOST }}:/path/to/your/binary
ssh -i ssh_key ${{ env.USER }}@${{ env.HOST }} 'systemctl restart your-service'
rm -f ssh_key

0 comments on commit 2acad7d

Please sign in to comment.