mirror of
https://github.com/ClovertaTheTrilobita/SanYeCao-blog.git
synced 2026-07-03 15:41:26 +00:00
222 lines
No EOL
5.9 KiB
YAML
222 lines
No EOL
5.9 KiB
YAML
name: Sync and Deploy Astro Blog
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- master
|
|
|
|
workflow_dispatch:
|
|
|
|
concurrency:
|
|
group: deploy-blog
|
|
cancel-in-progress: true
|
|
|
|
jobs:
|
|
sync-blog-content:
|
|
if: github.event_name == 'push'
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: write
|
|
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v5
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Configure git
|
|
run: |
|
|
git config user.name "github-actions[bot]"
|
|
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
|
|
|
|
- name: Checkout blog-content branch
|
|
run: |
|
|
git checkout blog-content
|
|
git pull origin blog-content
|
|
|
|
- name: Merge master into blog-content
|
|
run: |
|
|
git merge origin/master --no-edit
|
|
|
|
- name: Push blog-content
|
|
run: |
|
|
git push origin blog-content
|
|
|
|
build-and-deploy:
|
|
needs: sync-blog-content
|
|
if: github.event_name == 'push'
|
|
runs-on: ubuntu-latest
|
|
environment:
|
|
name: production
|
|
url: https://blog.cloverta.top
|
|
|
|
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@v5
|
|
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: Install Playwright system dependencies
|
|
run: npx playwright install-deps chromium
|
|
timeout-minutes: 10
|
|
|
|
- name: Install Playwright Chromium headless shell
|
|
run: |
|
|
for attempt in 1 2 3; do
|
|
echo "Installing Playwright Chromium headless shell: attempt ${attempt}/3"
|
|
|
|
if timeout 8m npx playwright install chromium --only-shell; then
|
|
echo "Playwright browser installed successfully."
|
|
exit 0
|
|
fi
|
|
|
|
echo "Playwright browser installation failed or hung."
|
|
echo "Removing incomplete browser cache before retrying..."
|
|
rm -rf ~/.cache/ms-playwright
|
|
|
|
sleep 10
|
|
done
|
|
|
|
echo "Playwright browser installation failed after 3 attempts."
|
|
exit 1
|
|
timeout-minutes: 30
|
|
env:
|
|
PLAYWRIGHT_DOWNLOAD_CONNECTION_TIMEOUT: "120000"
|
|
|
|
- name: List installed Playwright browsers
|
|
run: npx playwright install --list
|
|
|
|
- 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}/
|
|
|
|
manual-deploy:
|
|
if: github.event_name == 'workflow_dispatch'
|
|
runs-on: ubuntu-latest
|
|
environment:
|
|
name: production
|
|
url: https://blog.cloverta.top
|
|
|
|
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@v5
|
|
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: Install Playwright system dependencies
|
|
run: npx playwright install-deps chromium
|
|
timeout-minutes: 10
|
|
|
|
- name: Install Playwright Chromium headless shell
|
|
run: |
|
|
for attempt in 1 2 3; do
|
|
echo "Installing Playwright Chromium headless shell: attempt ${attempt}/3"
|
|
|
|
if timeout 8m npx playwright install chromium --only-shell; then
|
|
echo "Playwright browser installed successfully."
|
|
exit 0
|
|
fi
|
|
|
|
echo "Playwright browser installation failed or hung."
|
|
echo "Removing incomplete browser cache before retrying..."
|
|
rm -rf ~/.cache/ms-playwright
|
|
|
|
sleep 10
|
|
done
|
|
|
|
echo "Playwright browser installation failed after 3 attempts."
|
|
exit 1
|
|
timeout-minutes: 30
|
|
env:
|
|
PLAYWRIGHT_DOWNLOAD_CONNECTION_TIMEOUT: "120000"
|
|
|
|
- name: List installed Playwright browsers
|
|
run: npx playwright install --list
|
|
|
|
- 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}/ |