add ci
Some checks failed
CI/CD Pipeline / test (push) Successful in 4m10s
CI/CD Pipeline / deploy (push) Failing after 1m30s

This commit is contained in:
2025-07-19 15:43:01 +02:00
parent 673a0967b2
commit ba0c459843
2 changed files with 61 additions and 2 deletions

View File

@@ -0,0 +1,59 @@
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 }}