|
| 1 | +name: Deploy Website |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + paths: ['website/**'] |
| 7 | + # 手动触发入口:用于部署链路验证与紧急重部署(不依赖路径变更) |
| 8 | + workflow_dispatch: |
| 9 | + |
| 10 | +jobs: |
| 11 | + deploy: |
| 12 | + runs-on: ubuntu-latest |
| 13 | + timeout-minutes: 30 |
| 14 | + steps: |
| 15 | + - uses: actions/checkout@v4 |
| 16 | + |
| 17 | + - uses: actions/setup-node@v4 |
| 18 | + with: |
| 19 | + node-version: 22 |
| 20 | + cache: 'npm' |
| 21 | + cache-dependency-path: website/package-lock.json |
| 22 | + |
| 23 | + - name: Install dependencies and build |
| 24 | + env: |
| 25 | + # 下载源基址:配置了 CDN 后填入该 Secret(如 https://dl.entropydecrease.com); |
| 26 | + # 未配置时为空字符串,前端自动回退至自建服务器 |
| 27 | + NEXT_PUBLIC_DOWNLOAD_BASE: ${{ secrets.DOWNLOAD_BASE_URL }} |
| 28 | + run: | |
| 29 | + cd website |
| 30 | + npm ci |
| 31 | + npm run build |
| 32 | +
|
| 33 | + - name: Ensure target directory exists |
| 34 | + uses: appleboy/ssh-action@v1 |
| 35 | + with: |
| 36 | + host: ${{ secrets.SERVER_HOST }} |
| 37 | + username: ${{ secrets.SERVER_USER }} |
| 38 | + key: ${{ secrets.SSH_PRIVATE_KEY }} |
| 39 | + script: mkdir -p /opt/Entropydecrease/website |
| 40 | + |
| 41 | + - name: Upload static files to server |
| 42 | + uses: appleboy/scp-action@v0.1.7 |
| 43 | + with: |
| 44 | + host: ${{ secrets.SERVER_HOST }} |
| 45 | + username: ${{ secrets.SERVER_USER }} |
| 46 | + key: ${{ secrets.SSH_PRIVATE_KEY }} |
| 47 | + source: website/out/* |
| 48 | + target: /opt/Entropydecrease/website |
| 49 | + strip_components: 2 |
| 50 | + rm: true |
| 51 | + |
| 52 | + - name: Restart Nginx and verify deployment |
| 53 | + uses: appleboy/ssh-action@v1 |
| 54 | + with: |
| 55 | + host: ${{ secrets.SERVER_HOST }} |
| 56 | + username: ${{ secrets.SERVER_USER }} |
| 57 | + key: ${{ secrets.SSH_PRIVATE_KEY }} |
| 58 | + script: | |
| 59 | + # scp 的 rm:true 会重建挂载目录导致 bind mount 失效,必须重启容器 |
| 60 | + docker restart entropy-decrease-nginx |
| 61 | + sleep 5 |
| 62 | + curl -sf https://entropydecrease.com/ | grep -q "熵减" || exit 1 |
| 63 | +
|
| 64 | + - name: Notify IndexNow |
| 65 | + run: | |
| 66 | + curl -sf -X POST "https://api.indexnow.org/indexnow" \ |
| 67 | + -H "Content-Type: application/json; charset=utf-8" \ |
| 68 | + -d '{ |
| 69 | + "host": "entropydecrease.com", |
| 70 | + "key": "2483a0d298b94b62a30be65fce88940e", |
| 71 | + "keyLocation": "https://entropydecrease.com/2483a0d298b94b62a30be65fce88940e.txt", |
| 72 | + "urlList": [ |
| 73 | + "https://entropydecrease.com/", |
| 74 | + "https://entropydecrease.com/download", |
| 75 | + "https://entropydecrease.com/philosophy", |
| 76 | + "https://entropydecrease.com/features", |
| 77 | + "https://entropydecrease.com/features/dive", |
| 78 | + "https://entropydecrease.com/support", |
| 79 | + "https://entropydecrease.com/faq" |
| 80 | + ] |
| 81 | + }' || echo "IndexNow notify failed (non-blocking)" |
0 commit comments