mirror of
https://github.com/ClovertaTheTrilobita/SanYeCao-blog.git
synced 2026-04-01 17:50:13 +00:00
93 lines
No EOL
2.2 KiB
YAML
93 lines
No EOL
2.2 KiB
YAML
name: Deploy Astro Blog
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- blog-content
|
|
paths:
|
|
- 'src/blog/**'
|
|
- 'src/friends/**'
|
|
- 'package.json'
|
|
- 'package-lock.json'
|
|
- 'astro.config.mjs'
|
|
- 'astro.config.ts'
|
|
- 'public/**'
|
|
- '.github/workflows/deploy-blog.yml'
|
|
workflow_dispatch:
|
|
|
|
discussion:
|
|
types: [created, category_changed]
|
|
|
|
discussion_comment:
|
|
types: [created, edited, deleted]
|
|
|
|
concurrency:
|
|
group: deploy-blog
|
|
cancel-in-progress: true
|
|
|
|
jobs:
|
|
build-and-deploy:
|
|
if: >
|
|
github.event_name == 'push' ||
|
|
github.event_name == 'workflow_dispatch' ||
|
|
(
|
|
github.event_name == 'discussion' &&
|
|
github.event.discussion.category.slug == 'comments'
|
|
) ||
|
|
(
|
|
github.event_name == 'discussion_comment' &&
|
|
github.event.discussion.category.slug == 'comments'
|
|
)
|
|
runs-on: ubuntu-latest
|
|
|
|
env:
|
|
DEPLOY_HOST: ${{ vars.DEPLOY_HOST }}
|
|
DEPLOY_PORT: ${{ vars.DEPLOY_PORT }}
|
|
DEPLOY_PATH: ${{ vars.DEPLOY_PATH }}
|
|
DEPLOY_USER: ${{ vars.DEPLOY_USER }}
|
|
|
|
steps:
|
|
- name: Checkout blog-content branch
|
|
uses: actions/checkout@v4
|
|
with:
|
|
ref: blog-content
|
|
|
|
- name: Setup Node
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: 24
|
|
cache: npm
|
|
|
|
- name: Install dependencies
|
|
run: npm ci
|
|
|
|
- name: Create .env file
|
|
run: |
|
|
cat > .env <<'EOF'
|
|
${{ secrets.ENV_FILE }}
|
|
EOF
|
|
|
|
- name: Build Astro site
|
|
run: npm run build
|
|
|
|
- name: Install rsync and ssh client
|
|
run: sudo apt-get update && sudo apt-get install -y rsync openssh-client
|
|
|
|
- name: Setup SSH
|
|
run: |
|
|
mkdir -p ~/.ssh
|
|
echo "${{ secrets.DEPLOY_SSH_KEY }}" > ~/.ssh/id_rsa
|
|
chmod 600 ~/.ssh/id_rsa
|
|
echo "${{ secrets.DEPLOY_KNOWN_HOSTS }}" > ~/.ssh/known_hosts
|
|
chmod 644 ~/.ssh/known_hosts
|
|
|
|
- name: Deploy to server
|
|
run: |
|
|
rsync -avz --delete \
|
|
--omit-dir-times \
|
|
--no-perms \
|
|
--no-owner \
|
|
--no-group \
|
|
-e "ssh -p ${DEPLOY_PORT}" \
|
|
dist/ \
|
|
${DEPLOY_USER}@${DEPLOY_HOST}:${DEPLOY_PATH}/ |