Files
TeleUploader/.gitea/workflows/deploy.yml
T
Claude b9a3fcd828
Build & Deploy (Nix) / build-and-deploy (push) Successful in 49s
ci: nix build in CI + profile-based deploy (auto-update systemd)
2026-07-30 16:27:35 +07:00

73 lines
2.4 KiB
YAML

name: Build & Deploy (Nix)
on:
push:
branches:
- main
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Check out repository
run: |
git clone https://git.imrnes.team/MythEclipse/TeleUploader.git .
git checkout ${{ github.sha }}
- name: Install Nix & Build
run: |
set -eu
# Install Nix (container-safe: --init none, root-only mode)
curl -fsSL https://install.determinate.systems/nix \
| sh -s -- install linux --no-confirm --init none 2>&1
# Enable flakes
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
# Build
nix build .#teleuploader --impure --option sandbox false 2>&1
echo "$(readlink result)" > /tmp/teleuploader-store-path
- name: Copy binary to target VPS & deploy
env:
VPS_HOST: ${{ secrets.VPS_HOST }}
VPS_USER: ${{ secrets.VPS_USER }}
VPS_SSH_KEY_VALUE: ${{ secrets.VPS_SSH_KEY_VALUE }}
run: |
set -eu
. /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh
STORE_PATH=$(cat /tmp/teleuploader-store-path)
echo "=== Store path: $STORE_PATH"
key_file=$(mktemp /tmp/deploy-key.XXXXXX)
printf '%s\n' "$VPS_SSH_KEY_VALUE" > "$key_file"
chmod 600 "$key_file"
# Copy binary closure to target VPS via Nix SSH store
export NIX_SSHOPTS="-i $key_file -o StrictHostKeyChecking=no"
nix copy --to "ssh://${VPS_USER}@${VPS_HOST}" "$STORE_PATH" 2>&1
# Deploy: update profile + restart service
NIX_BIN="/nix/var/nix/profiles/default/bin"
ssh -i "$key_file" -o StrictHostKeyChecking=no \
"${VPS_USER}@${VPS_HOST}" "
# Remove stale profile dir (if was created as mkdir -p)
if [ -d /nix/var/nix/profiles/teleuploader ] && [ ! -L /nix/var/nix/profiles/teleuploader ]; then
rm -rf /nix/var/nix/profiles/teleuploader
fi
export PATH=\$PATH:$NIX_BIN
nix-env --profile /nix/var/nix/profiles/teleuploader --set $STORE_PATH
systemctl daemon-reload
systemctl restart teleuploader
sleep 3
systemctl status teleuploader --no-pager 2>&1 | head -15
" 2>&1