Files
GMW/.gitea/workflows/deploy.yml
T
Developer f2b797e6ce
Build & Deploy (Nix) / build-and-deploy (backend) (push) Successful in 3m6s
Build & Deploy (Nix) / build-and-deploy (discord-gateway) (push) Successful in 2m23s
Build & Deploy (Nix) / build-and-deploy (proxy) (push) Successful in 2m37s
refactor(deploy): remove max-parallel setting from job strategy
2026-07-31 19:46:19 +07:00

69 lines
2.1 KiB
YAML

name: Build & Deploy (Nix)
on:
push:
branches:
- main
jobs:
build-and-deploy:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
service: [backend, discord-gateway, proxy]
steps:
- name: Check out repository
run: |
git clone https://git.imrnes.team/MythEclipse/GMW.git .
git checkout ${{ github.sha }}
- name: Build & Deploy ${{ matrix.service }}
env:
VPS_HOST: ${{ secrets.VPS_HOST }}
VPS_USER: ${{ secrets.VPS_USER }}
VPS_SSH_KEY: ${{ secrets.VPS_SSH_KEY }}
run: |
set -eu
# --- Install Nix & Build ---
curl -fsSL https://install.determinate.systems/nix \
| sh -s -- install linux --no-confirm --init none 2>&1
mkdir -p /etc/nix
echo "experimental-features = nix-command flakes" >> /etc/nix/nix.conf
. /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh
SERVICE="${{ matrix.service }}"
echo "=== Building: $SERVICE ==="
nix build ".#$SERVICE" --impure --option sandbox false 2>&1
STORE_PATH=$(readlink result)
echo "=== Store path: $STORE_PATH"
# --- Deploy ---
NIX_BIN="/nix/var/nix/profiles/default/bin"
PROFILE="/nix/var/nix/profiles/gmw-$SERVICE"
key_file=$(mktemp /tmp/deploy-key.XXXXXX)
printf '%s\n' "$VPS_SSH_KEY" > "$key_file"
chmod 600 "$key_file"
export NIX_SSHOPTS="-i $key_file -o StrictHostKeyChecking=no"
nix copy --to "ssh://${VPS_USER}@${VPS_HOST}" "$STORE_PATH" 2>&1
ssh -i "$key_file" -o StrictHostKeyChecking=no \
"${VPS_USER}@${VPS_HOST}" "
if [ -d $PROFILE ] && [ ! -L $PROFILE ]; then
rm -rf $PROFILE
fi
export PATH=\$PATH:$NIX_BIN
nix-env --profile $PROFILE --set $STORE_PATH
systemctl daemon-reload
systemctl restart gmw-$SERVICE
sleep 3
systemctl status gmw-$SERVICE --no-pager 2>&1 | head -12
" 2>&1