Update job #7
This file contains 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: Build and Deploy | |
on: | |
push: | |
branches: [main] | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: goto-bus-stop/setup-zig@v2 | |
with: | |
version: 0.12.0-dev.2236+32e88251e | |
- uses: actions/setup-node@v4 | |
- id: build-web | |
name: Build web assets | |
working-directory: web | |
run: | | |
npm install | |
npm run build | |
- id: build-night-math | |
name: Build WASM library | |
working-directory: night-math | |
run: zig build -Doptimize=ReleaseFast | |
- id: build-server | |
name: Build server | |
working-directory: server | |
run: zig build -Doptimize=ReleaseSafe | |
- id: create-artifact | |
name: Bundle package | |
run: | |
tar -cvf one-night.tar server/zig-out/bin/zig-server web/dist web/assets web/styles web/index.html | |
- name: Upload Bundle | |
uses: actions/upload-artifact@v4 | |
with: | |
name: one-night-${{ github.sha }} | |
path: one-night.tar | |
overwrite: true | |
retention-days: 3 | |
deploy: | |
runs-on: ubuntu-latest | |
needs: build | |
env: | |
USER_NAME: ${{ secrets.SSH_USER }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Write SSH Keys | |
run: | | |
mkdir -p ~/.ssh | |
chmod 700 ~/.ssh | |
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa | |
chmod 600 ~/.ssh/id_rsa | |
ssh-keyscan -H "${{ secrets.SSH_HOST }}" > ~/.ssh/known_hosts | |
chmod 644 ~/.ssh/known_hosts | |
- name: Download Bundle | |
uses: actions/download-artifact@v4 | |
with: | |
name: one-night-${{ github.ref }} | |
- name: Copy build files | |
run: | | |
sftp $USER_NAME:${{ github.secrets.SSH_HOST }} <<< ' | |
put one-night.tar | |
' | |
- name: Start Server | |
run: | | |
ssh $USER_NAME:${{ github.secrets.SSH_HOST }} <<< ' | |
tar -xf one-night.tar | |
cd server | |
nohup ./zig-out/bin/zig-server > logs.out & | |
' |