Astro-CI #3180
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Astro-CI | |
| on: | |
| workflow_dispatch: | |
| repository_dispatch: | |
| types: | |
| - update | |
| schedule: | |
| - cron: '0 */3 * * *' | |
| push: | |
| branches: | |
| - main | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '18' | |
| cache: 'yarn' | |
| # 0️⃣⸣ 强制清空工作区里的缓存文件,确保“以缓存为准” | |
| - name: Wipe local cache files | |
| run: | | |
| rm -f src/data/image-meta.json src/data/og-cache.json | |
| echo "✅ 已删除本地缓存文件,保证使用 Actions 缓存或重新生成" | |
| # 1️⃣ 恢复缓存 | |
| - name: Restore image/og cache | |
| uses: actions/cache@v4 | |
| id: cache-restore | |
| with: | |
| path: | | |
| src/data/image-meta.json | |
| src/data/og-cache.json | |
| key: astro-cache-single | |
| # 2️⃣ 恢复 node_modules 缓存 | |
| - name: Cache node modules | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ~/.yarn/cache | |
| ~/.npm | |
| node_modules | |
| **/node_modules | |
| key: ${{ runner.os }}-node-${{ hashFiles('**/yarn.lock', '**/package-lock.json') }} | |
| restore-keys: | | |
| ${{ runner.os }}-node- | |
| # 3️⃣ 安装依赖 | |
| - name: Install dependencies | |
| run: | | |
| yarn add sharp --ignore-engines | |
| yarn install | |
| # 4️⃣ 写入配置文件 | |
| - name: Write config file | |
| env: | |
| CONFIG_FILE: ${{ secrets.CONFIG_FILE }} | |
| run: | | |
| echo "$CONFIG_FILE" > ./.env | |
| # 5️⃣ 构建项目 | |
| - name: Build Astro project | |
| run: yarn build | |
| # 6️⃣ 部署到 VPS | |
| - name: Deploy to VPS | |
| env: | |
| VPS_HOST: ${{ secrets.VPS_HOST }} | |
| VPS_PORT: ${{ secrets.VPS_PORT }} | |
| VPS_USER: ${{ secrets.VPS_USER }} | |
| VPS_SSH_PRIVATE_KEY: ${{ secrets.VPS_SSH_PRIVATE_KEY }} | |
| run: | | |
| mkdir -p ~/.ssh | |
| chmod 700 ~/.ssh | |
| echo "$VPS_SSH_PRIVATE_KEY" > ~/.ssh/id_rsa | |
| chmod 600 ~/.ssh/id_rsa | |
| echo "StrictHostKeyChecking no" >> ~/.ssh/config | |
| rsync -avz --delete -e "ssh -p $VPS_PORT" dist/ $VPS_USER@$VPS_HOST:/var/11ty-data | |
| # - name: 安装 edgeone CLI | |
| # run: npm install -g edgeone | |
| # - name: 打包 dist 为 zip | |
| # run: | | |
| # # 确保 zip 已安装(Ubuntu 自带,如缺失可 apt-get install -y zip) | |
| # zip -r dist.zip ./dist | |
| # - name: 打包并部署到edgeone | |
| # run: | | |
| # npx edgeone pages deploy ./dist -n astro-book -t ${{ secrets.EDGE_TOKEN }} |