Skip to content

Update README with working Shields.io badge routes #51

Update README with working Shields.io badge routes

Update README with working Shields.io badge routes #51

Workflow file for this run

name: Build, Run Tests & Deploy
on:
push:
branches:
- main
env:
CARGO_MAIN_COLOR: always
jobs:
build_and_test:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:latest
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
ports:
- 5432:5432
# This is needed because the Postgres container does not provide a healthcheck
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
steps:
- name: Checkout Sources
uses: actions/checkout@v2
- name: Install Stable Rust Toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
- name: Prepare Test Environment
run: |
sudo apt update
sudo apt install -y build-essential postgresql-client
mv .env.test .env
psql -h localhost -p 5432 -U postgres postgres < database.sql
env:
PGPASSWORD: postgres
- name: Install cargo-tarpaulin
uses: actions-rs/install@v0.1
with:
crate: cargo-tarpaulin
version: latest
use-tool-cache: false
- name: Run Tests
uses: actions-rs/cargo@v1
with:
command: tarpaulin
args: --verbose --count --release --all-features --tests --workspace --ignore-tests --out Xml -- --test-threads 1
env:
RUST_LOG: actix_web=info,actix_server=info
RUST_BACKTRACE: full
- name: Upload Test Coverage to codecov.io
uses: codecov/codecov-action@v1
with:
fail_ci_if_error: true
verbose: true
deploy:
runs-on: ubuntu-latest
needs: build_and_test
if: ${{ false }} # Disable for now
# if: needs.build_and_test.result == 'success'
steps:
- name: Setup & Configure SSH
run: |
sudo apt install -y ssh
mkdir -p ~/.ssh/
echo "${{secrets.SSH_KEY}}" > ~/.ssh/overdue_rsa
chmod 600 ~/.ssh/overdue_rsa
ssh-keyscan "${{secrets.SSH_HOST}}" >> ~/.ssh/known_hosts
# We hardcode the calls to the absolute paths of the executable binaries here since SSH is a non-interactive shell (different $PATH environment variables)
# Read these for more information:
# - https://stackoverflow.com/a/216204
# - https://unix.stackexchange.com/a/332533
- name: Deploy Overdue Backend Server
run: |
ssh -i ~/.ssh/overdue_rsa -o UserKnownHostsFile=~/.ssh/known_hosts -o ServerAliveInterval=240 -o ServerAliveCountMax=15 ${{secrets.SSH_USERNAME}}@${{secrets.SSH_HOST}} '
sudo systemctl stop overdue_backend.service;
sudo dpkg --purge overdue_backend;
cd overdue_backend && git fetch --all && git reset --hard origin/main && git clean -f -d && git pull origin main;
sudo rm -rf target;
cp -p /etc/letsencrypt/live/${{secrets.SERVER_DOMAIN_NAME}}/fullchain.pem /etc/letsencrypt/live/${{secrets.SERVER_DOMAIN_NAME}}/privkey.pem tls/;
export TARGET_TRIPLE=$(/root/.cargo/bin/rustc -vV | grep host | cut -d: -f2 | tr -d " ");
/root/.cargo/bin/cargo deb --target=$TARGET_TRIPLE;
sudo dpkg -i target/$TARGET_TRIPLE/debian/overdue_backend_0.2.0_amd64.deb;
sudo systemctl enable overdue_backend.service;
sudo systemctl start overdue_backend.service;
exit;
'
- name: Print Success Message
if: success()
run: echo '\u001b[32mContinuous deployment to DigitalOcean server is successful!\u001b[0m'
- name: Delete & Cleanup SSH Credentials
if: always()
run: |
sudo rm -rf ~/.ssh/overdue_rsa
sudo rm -rf ~/.ssh/known_hosts