60 lines
1.6 KiB
YAML
60 lines
1.6 KiB
YAML
name: CI/CD Pipeline
|
|
|
|
on: push
|
|
|
|
env:
|
|
CARGO_TARGET: x86_64-unknown-linux-musl
|
|
SSH_HOST: ${{ secrets.SSH_HOST }}
|
|
SSH_USER: ${{ secrets.SSH_USER }}
|
|
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
|
|
|
|
jobs:
|
|
test:
|
|
runs-on: ubuntu-latest
|
|
container: git.hofer.link/philipp/ci-images:rust-latest
|
|
steps:
|
|
- uses: actions/checkout@v3
|
|
|
|
- name: Cache Cargo dependencies
|
|
uses: Swatinem/rust-cache@v2
|
|
|
|
- name: Build
|
|
run: cargo build
|
|
|
|
- name: Backend tests
|
|
run: cargo test --verbose
|
|
|
|
deploy:
|
|
runs-on: ubuntu-latest
|
|
container: git.hofer.link/philipp/ci-images:rust-latest
|
|
needs: [test]
|
|
if: github.ref == 'refs/heads/main'
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v3
|
|
|
|
- name: Cache Cargo dependencies
|
|
uses: Swatinem/rust-cache@v2
|
|
|
|
- name: Build
|
|
run: |
|
|
cargo build --release --target $CARGO_TARGET
|
|
strip target/$CARGO_TARGET/release/player
|
|
|
|
- name: Deploy to production
|
|
run: |
|
|
mkdir -p ~/.ssh
|
|
ssh-keyscan -H $SSH_HOST >> ~/.ssh/known_hosts
|
|
echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa
|
|
chmod 600 ~/.ssh/id_rsa
|
|
|
|
scp -C target/$CARGO_TARGET/release/player $SSH_USER@$SSH_HOST:/root/oe1-player/player-updating
|
|
ssh $SSH_USER@$SSH_HOST 'sudo systemctl stop oe1-player'
|
|
ssh $SSH_USER@$SSH_HOST 'mv /root/oe1-player/player-updating /root/oe1-player/player'
|
|
ssh $SSH_USER@$SSH_HOST 'sudo systemctl start oe1-player'
|
|
env:
|
|
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
|
|
SSH_HOST: ${{ secrets.SSH_HOST }}
|
|
SSH_USER: ${{ secrets.SSH_USER }}
|
|
|