ci: fix deploy — stop before SCP, absolute path, separate steps #2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Deploy | |
| on: | |
| push: | |
| branches: [main] | |
| workflow_dispatch: | |
| env: | |
| CARGO_TERM_COLOR: always | |
| jobs: | |
| build-and-deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: dtolnay/rust-toolchain@stable | |
| - name: Cache cargo registry | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ~/.cargo/registry | |
| ~/.cargo/git | |
| key: ${{ runner.os }}-cargo-${{ hashFiles('Cargo.lock') }} | |
| - name: Build | |
| run: cargo build --release | |
| - name: Set up SSH key | |
| run: | | |
| mkdir -p ~/.ssh | |
| echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/deploy_key | |
| chmod 600 ~/.ssh/deploy_key | |
| - name: Stop service | |
| run: | | |
| ssh -i ~/.ssh/deploy_key \ | |
| -o StrictHostKeyChecking=accept-new \ | |
| ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} \ | |
| "sudo systemctl stop deathfr" | |
| - name: Deploy binary | |
| run: | | |
| scp -i ~/.ssh/deploy_key \ | |
| -o StrictHostKeyChecking=accept-new \ | |
| target/release/deathfr \ | |
| ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}:/home/deathfr/deathfr/deathfr-bin | |
| - name: Start service | |
| run: | | |
| ssh -i ~/.ssh/deploy_key \ | |
| -o StrictHostKeyChecking=accept-new \ | |
| ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} \ | |
| "sudo systemctl start deathfr" |