Files
publish/.gitea/workflows/deploy.yml
voson 96c35afab6
Some checks failed
deploy / build-and-deploy (push) Failing after 1m6s
chore: update deploy workflow to use sshpass for SSH authentication and cache npm dependencies
2026-02-03 17:31:42 +08:00

60 lines
1.8 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
name: deploy
on:
push:
branches:
- main
jobs:
build-and-deploy:
runs-on: self-hosted
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20
- name: Cache npm dependencies
# gitea 不支持 actions/cache@v4使用 v3 代替
uses: actions/cache@v3
with:
path: ~/.npm
key: npm-${{ hashFiles('package-lock.json') }}
restore-keys: npm-
- name: Install
run: npm ci
- name: Build
env:
SITE_URL: ${{ vars.SITE_URL }}
run: npm run build
- name: Install sshpass
run: |
if ! command -v sshpass &> /dev/null; then
if command -v apt-get &> /dev/null; then
sudo apt-get update && sudo apt-get install -y sshpass
elif command -v yum &> /dev/null; then
sudo yum install -y sshpass
elif command -v apk &> /dev/null; then
sudo apk add --no-cache sshpass
fi
fi
- name: Add known_hosts
run: |
mkdir -p ~/.ssh
ssh-keyscan -p "${{ vars.DEPLOY_SSH_PORT }}" -H "${{ vars.DEPLOY_SSH_HOST }}" >> ~/.ssh/known_hosts
- name: Deploy via tar over SSH
env:
SSHPASS: ${{ secrets.DEPLOY_SSH_PASSWORD }}
run: |
tar -C dist -czf - . | \
sshpass -e ssh -o StrictHostKeyChecking=yes -o ConnectTimeout=15 -p "${{ vars.DEPLOY_SSH_PORT }}" "${{ vars.DEPLOY_SSH_USER }}@${{ vars.DEPLOY_SSH_HOST }}" \
"set -euo pipefail; tmp='${{ vars.DEPLOY_PATH }}.tmp'; rm -rf \"\$tmp\"; mkdir -p \"\$tmp\"; tar -xzf - -C \"\$tmp\"; rm -rf '${{ vars.DEPLOY_PATH }}'; mv \"\$tmp\" '${{ vars.DEPLOY_PATH }}'"