{"id":31128,"date":"2026-06-11T12:00:00","date_gmt":"2026-06-11T04:00:00","guid":{"rendered":"https:\/\/cn.hostease.com\/blog\/?p=31128"},"modified":"2026-06-15T16:16:19","modified_gmt":"2026-06-15T08:16:19","slug":"github-actions-auto-deploy-vps","status":"publish","type":"post","link":"https:\/\/cn.hostease.com\/blog\/tutorials\/github-actions-auto-deploy-vps\/","title":{"rendered":"GitHub Actions \u81ea\u52a8\u90e8\u7f72\u5230 VPS\uff1a\u4ece\u96f6\u642d\u5efa CI\/CD \u6d41\u6c34\u7ebf"},"content":{"rendered":"<p>\u8fd8\u8bb0\u5f97\u90a3\u4e9b\u5e74\u7528 FTP \u624b\u52a8\u4e0a\u4f20\u4ee3\u7801\u7684\u65e5\u5b50\u5417\uff1f\u6bcf\u6b21\u6539\u4e00\u884c\u914d\u7f6e\uff0c\u90fd\u8981\u6253\u5f00 FileZilla\uff0c\u627e\u5230\u5bf9\u5e94\u76ee\u5f55\uff0c\u62d6\u62fd\u6587\u4ef6\uff0c\u7948\u7977\u6ca1\u6709\u9057\u6f0f\u3002\u90e8\u7f72\u5b8c\u8fd8\u8981\u624b\u52a8\u5237\u65b0\u6d4f\u89c8\u5668\u68c0\u67e5\u6548\u679c\uff0c\u4e07\u4e00\u51fa\u9519\u53c8\u5f97\u56de\u6eda\u2014\u2014\u6574\u4e2a\u8fc7\u7a0b\u8017\u65f6\u3001\u4f4e\u6548\uff0c\u8fd8\u5bb9\u6613\u56e0\u4eba\u4e3a\u758f\u5ffd\u5bfc\u81f4\u7ebf\u4e0a\u4e8b\u6545\u3002<\/p>\n<p>\u672c\u6587\u5c06\u6559\u4f60\u5982\u4f55\u7528 GitHub Actions \u642d\u5efa\u81ea\u52a8\u90e8\u7f72\u6d41\u6c34\u7ebf\uff0c\u8ba9\u4ee3\u7801\u63a8\u9001\u540e\u81ea\u52a8\u6d4b\u8bd5\u3001\u6784\u5efa\u3001\u90e8\u7f72\u5230 <a href=\"https:\/\/cn.hostease.com\/vps\/\">VPS<\/a>\uff0c\u5f7b\u5e95\u544a\u522b\u624b\u52a8\u4e0a\u4f20\u7684\u4f4e\u6548\u6d41\u7a0b\u3002<\/p>\n<p>\u5982\u679c\u4f60\u6b63\u5728\u4f7f\u7528 <a href=\"https:\/\/cn.hostease.com\">Hostease<\/a> \u7684 VPS \u6216[\u72ec\u7acb\u670d\u52a1\u5668](https:\/\/cn.hostease.com\/dedicated-server\/)\u6258\u7ba1\u9879\u76ee\uff0c\u90a3\u4e48\u606d\u559c\u4f60\uff0c\u4f60\u5df2\u7ecf\u62e5\u6709\u4e86\u5f3a\u5927\u7684\u57fa\u7840\u8bbe\u65bd\u3002\u73b0\u5728\uff0c\u53ea\u9700\u8981\u518d\u8fc8\u51fa\u4e00\u6b65\u2014\u2014\u501f\u52a9 GitHub Actions \u642d\u5efa CI\/CD \u6d41\u6c34\u7ebf\uff0c\u5c31\u80fd\u8ba9\u6bcf\u4e00\u6b21\u4ee3\u7801\u63a8\u9001\u81ea\u52a8\u89e6\u53d1\u6d4b\u8bd5\u3001\u6784\u5efa\u548c\u90e8\u7f72\uff0c\u628a\u91cd\u590d\u52b3\u52a8\u5f7b\u5e95\u4ea4\u7ed9\u673a\u5668\u3002<\/p>\n<p>\u672c\u6587\u5c06\u4ece\u96f6\u5f00\u59cb\uff0c\u5e26\u4f60\u642d\u5efa\u4e00\u6761\u5b8c\u6574\u7684 GitHub Actions \u81ea\u52a8\u90e8\u7f72\u6d41\u6c34\u7ebf\uff0c\u6db5\u76d6\u6838\u5fc3\u6982\u5ff5\u3001\u5b9e\u6218\u914d\u7f6e\u3001\u5b89\u5168\u52a0\u56fa\u4ee5\u53ca\u591a\u73af\u5883\u8fdb\u9636\u65b9\u6848\u3002<\/p>\n<h2>\u4e00\u3001GitHub Actions \u6838\u5fc3\u6982\u5ff5<\/h2>\n<p>\u5728\u52a8\u624b\u5199\u914d\u7f6e\u4e4b\u524d\uff0c\u5148\u641e\u6e05\u695a\u56db\u4e2a\u5173\u952e\u672f\u8bed\uff1a<\/p>\n<ul>\n<li><strong>Workflow\uff08\u5de5\u4f5c\u6d41\uff09<\/strong>\uff1a\u5b58\u653e\u5728 <code>.github\/workflows\/<\/code> \u76ee\u5f55\u4e0b\u7684 YAML \u6587\u4ef6\uff0c\u5b9a\u4e49\u4e86\u4e00\u6574\u5957\u81ea\u52a8\u5316\u6d41\u7a0b\u3002\u4e00\u4e2a\u4ed3\u5e93\u53ef\u4ee5\u6709\u591a\u4e2a workflow\uff0c\u5206\u522b\u8d1f\u8d23\u6d4b\u8bd5\u3001\u90e8\u7f72\u3001\u53d1\u5e03\u7b49\u4e0d\u540c\u4efb\u52a1\u3002<\/li>\n<li><strong>Job\uff08\u4f5c\u4e1a\uff09<\/strong>\uff1aworkflow \u4e2d\u7684\u4e00\u4e2a\u72ec\u7acb\u6267\u884c\u5355\u5143\u3002\u591a\u4e2a job \u9ed8\u8ba4\u5e76\u884c\u8fd0\u884c\uff0c\u4e5f\u53ef\u4ee5\u7528 <code>needs<\/code> \u5173\u952e\u5b57\u4e32\u884c\u4f9d\u8d56\u3002\u6bcf\u4e2a job \u8fd0\u884c\u5728\u72ec\u7acb\u7684\u865a\u62df\u673a\uff08runner\uff09\u4e0a\u3002<\/li>\n<li><strong>Step\uff08\u6b65\u9aa4\uff09<\/strong>\uff1ajob \u5185\u7684\u5177\u4f53\u64cd\u4f5c\uff0c\u53ef\u4ee5\u662f\u4e00\u6761 shell \u547d\u4ee4\uff0c\u4e5f\u53ef\u4ee5\u662f\u8c03\u7528\u793e\u533a\u63d0\u4f9b\u7684 Action\u3002\u6b65\u9aa4\u6309\u987a\u5e8f\u4f9d\u6b21\u6267\u884c\u3002<\/li>\n<li><strong>Runner\uff08\u8fd0\u884c\u5668\uff09<\/strong>\uff1a\u6267\u884c job \u7684\u670d\u52a1\u5668\u73af\u5883\u3002GitHub \u63d0\u4f9b\u514d\u8d39\u7684 <code>ubuntu-latest<\/code>\u3001<code>windows-latest<\/code> \u7b49\u6258\u7ba1 runner\uff0c\u4e5f\u53ef\u4ee5\u4f7f\u7528\u81ea\u6258\u7ba1 runner\u3002<\/li>\n<\/ul>\n<p>\u5b83\u4eec\u7684\u5173\u7cfb\u662f\uff1aworkflow \u5305\u542b\u591a\u4e2a job\uff0c\u6bcf\u4e2a job \u5305\u542b\u591a\u4e2a step\uff0c\u6bcf\u4e2a job \u8fd0\u884c\u5728\u4e00\u4e2a runner \u4e0a\u3002<\/p>\n<h3>GitHub Actions \u7684\u514d\u8d39\u989d\u5ea6<\/h3>\n<p>\u5bf9\u4e8e\u516c\u5f00\u4ed3\u5e93\uff0cGitHub Actions \u5b8c\u5168\u514d\u8d39\u3002\u79c1\u6709\u4ed3\u5e93\u6bcf\u6708\u6709 2000 \u5206\u949f\u7684\u514d\u8d39\u989d\u5ea6\uff08Linux runner\uff09\uff0c\u5bf9\u4e8e\u4e2a\u4eba\u9879\u76ee\u548c\u4e2d\u5c0f\u578b\u56e2\u961f\u6765\u8bf4\u7ef0\u7ef0\u6709\u4f59\u3002\u8fd9\u4e5f\u662f\u5b83\u76f8\u6bd4 Jenkins \u7b49\u81ea\u5efa\u65b9\u6848\u7684\u6700\u5927\u4f18\u52bf\u2014\u2014\u96f6\u8fd0\u7ef4\u6210\u672c\u3002<\/p>\n<h2>\u4e8c\u3001\u5b9e\u6218\uff1a\u7f16\u5199 deploy.yml<\/h2>\n<p>\u63a5\u4e0b\u6765\u6211\u4eec\u4ee5\u4e00\u4e2a\u5178\u578b\u7684\u524d\u7aef\u9879\u76ee\u4e3a\u4f8b\uff08\u6784\u5efa\u540e\u90e8\u7f72\u5230 VPS\uff09\uff0c\u7f16\u5199\u5b8c\u6574\u7684 workflow \u914d\u7f6e\u6587\u4ef6\u3002<\/p>\n<h3>2.1 \u521b\u5efa workflow \u6587\u4ef6<\/h3>\n<p>\u5728\u9879\u76ee\u6839\u76ee\u5f55\u521b\u5efa <code>.github\/workflows\/deploy.yml<\/code>\uff1a<\/p>\n<pre><code class=\"language-yaml\">name: Deploy to VPS\n\non:\n  push:\n    branches:\n      - main\n\njobs:\n  build-and-deploy:\n    runs-on: ubuntu-latest\n\n    steps:\n      - name: Checkout code\n        uses: actions\/checkout@v4\n\n      - name: Setup Node.js\n        uses: actions\/setup-node@v4\n        with:\n          node-version: '20'\n          cache: 'npm'\n\n      - name: Install dependencies\n        run: npm ci\n\n      - name: Run tests\n        run: npm test\n\n      - name: Build project\n        run: npm run build\n\n      - name: Deploy to VPS via SSH\n        uses: appleboy\/ssh-action@v1\n        with:\n          host: ${{ secrets.SERVER_HOST }}\n          username: ${{ secrets.SERVER_USER }}\n          key: ${{ secrets.SSH_PRIVATE_KEY }}\n          script: |\n            cd \/var\/www\/myapp\n            git pull origin main\n            npm ci --production\n            npm run build\n            pm2 restart myapp\n<\/code><\/pre>\n<h3>2.2 \u9010\u884c\u89e3\u6790<\/h3>\n<ul>\n<li><code>on: push \u2192 branches: main<\/code>\uff1a\u4ec5\u5f53\u4ee3\u7801\u63a8\u9001\u5230 main \u5206\u652f\u65f6\u89e6\u53d1\uff0c\u907f\u514d\u5f00\u53d1\u5206\u652f\u7684\u9891\u7e41\u89e6\u53d1\u3002<\/li>\n<li><code>actions\/checkout@v4<\/code>\uff1a\u5c06\u4ed3\u5e93\u4ee3\u7801\u514b\u9686\u5230 runner \u7684\u5de5\u4f5c\u76ee\u5f55\u3002<\/li>\n<li><code>actions\/setup-node@v4<\/code>\uff1a\u5b89\u88c5\u6307\u5b9a\u7248\u672c\u7684 Node.js\uff0c\u5e76\u542f\u7528 npm \u7f13\u5b58\u52a0\u901f\u540e\u7eed\u6784\u5efa\u3002<\/li>\n<li><code>npm ci<\/code>\uff1a\u4e25\u683c\u6309\u7167 lock \u6587\u4ef6\u5b89\u88c5\u4f9d\u8d56\uff0c\u6bd4 <code>npm install<\/code> \u66f4\u5feb\u66f4\u53ef\u9760\uff0c\u9002\u5408 CI \u73af\u5883\u3002<\/li>\n<li><code>npm test<\/code>\uff1a\u8fd0\u884c\u6d4b\u8bd5\u5957\u4ef6\u3002\u5982\u679c\u6d4b\u8bd5\u5931\u8d25\uff0c\u540e\u7eed\u6b65\u9aa4\u4e0d\u4f1a\u6267\u884c\uff0c\u90e8\u7f72\u81ea\u52a8\u4e2d\u65ad\u3002<\/li>\n<li><code>appleboy\/ssh-action<\/code>\uff1a\u793e\u533a\u5e7f\u6cdb\u4f7f\u7528\u7684 SSH Action\uff0c\u901a\u8fc7 SSH \u8fde\u63a5 VPS \u5e76\u6267\u884c\u8fdc\u7a0b\u547d\u4ee4\u3002<\/li>\n<\/ul>\n<h3>2.3 \u66ff\u4ee3\u65b9\u6848\uff1arsync \u540c\u6b65\u6784\u5efa\u4ea7\u7269<\/h3>\n<p>\u5982\u679c\u4f60\u4e0d\u60f3\u5728 VPS \u4e0a\u91cd\u590d\u6784\u5efa\uff0c\u4e5f\u53ef\u4ee5\u9009\u62e9\u5728 runner \u4e0a\u6784\u5efa\u5b8c\u6210\u540e\uff0c\u7528 rsync \u53ea\u540c\u6b65\u4ea7\u7269\u76ee\u5f55\uff1a<\/p>\n<pre><code class=\"language-yaml\">      - name: Deploy build artifacts via rsync\n        uses: burnett01\/rsync-deployments@7.0.1\n        with:\n          switches: -avzr --delete\n          path: .\/dist\/\n          remote_path: \/var\/www\/myapp\/dist\/\n          remote_host: ${{ secrets.SERVER_HOST }}\n          remote_user: ${{ secrets.SERVER_USER }}\n          remote_key: ${{ secrets.SSH_PRIVATE_KEY }}\n<\/code><\/pre>\n<p>\u8fd9\u79cd\u65b9\u5f0f\u9002\u5408\u7eaf\u9759\u6001\u7ad9\u70b9\uff0cVPS \u4e0a\u53ea\u9700\u4e00\u4e2a Nginx \u6307\u5411 <code>\/var\/www\/myapp\/dist\/<\/code> \u5373\u53ef\u3002<\/p>\n<h2>\u4e09\u3001\u5b89\u5168\u914d\u7f6e\uff1aSecrets\u3001SSH Key \u4e0e known_hosts<\/h2>\n<p>CI\/CD \u6d41\u6c34\u7ebf\u4e2d\u6d89\u53ca\u670d\u52a1\u5668\u5bc6\u7801\u3001\u79c1\u94a5\u7b49\u654f\u611f\u4fe1\u606f\uff0c\u7edd\u4e0d\u80fd\u786c\u7f16\u7801\u5728 YAML \u6587\u4ef6\u4e2d\u3002GitHub \u63d0\u4f9b\u4e86 <strong>Secrets<\/strong> \u673a\u5236\u6765\u5b89\u5168\u5b58\u50a8\u8fd9\u4e9b\u51ed\u636e\u3002<\/p>\n<h3>3.1 \u751f\u6210 SSH \u5bc6\u94a5\u5bf9<\/h3>\n<p>\u5728\u672c\u5730\u7ec8\u7aef\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\uff0c\u751f\u6210\u4e13\u7528\u7684\u90e8\u7f72\u5bc6\u94a5\uff1a<\/p>\n<pre><code class=\"language-bash\">ssh-keygen -t ed25519 -C \"github-actions-deploy\" -f ~\/.ssh\/deploy_key -N \"\"\n<\/code><\/pre>\n<p>\u8fd9\u4f1a\u751f\u6210\u4e24\u4e2a\u6587\u4ef6\uff1a<\/p>\n<ul>\n<li><code>deploy_key<\/code>\uff08\u79c1\u94a5\uff09\u2192 \u5b58\u5165 GitHub Secrets<\/li>\n<li><code>deploy_key.pub<\/code>\uff08\u516c\u94a5\uff09\u2192 \u90e8\u7f72\u5230 VPS \u7684 <code>~\/.ssh\/authorized_keys<\/code><\/li>\n<\/ul>\n<h3>3.2 \u914d\u7f6e VPS \u7aef<\/h3>\n<p>\u5c06\u516c\u94a5\u6dfb\u52a0\u5230 VPS \u7684\u6388\u6743\u5217\u8868\uff1a<\/p>\n<pre><code class=\"language-bash\">cat ~\/.ssh\/deploy_key.pub >> ~\/.ssh\/authorized_keys\nchmod 600 ~\/.ssh\/authorized_keys\n<\/code><\/pre>\n<p>\u5982\u679c\u4f60\u7684 VPS \u9762\u677f\u652f\u6301 SSH Key \u7ba1\u7406\uff0c\u4e5f\u53ef\u4ee5\u901a\u8fc7\u9762\u677f\u754c\u9762\u76f4\u63a5\u6dfb\u52a0\u516c\u94a5\uff0c\u64cd\u4f5c\u66f4\u52a0\u76f4\u89c2\u3002<\/p>\n<h3>3.3 \u914d\u7f6e GitHub Secrets<\/h3>\n<p>\u8fdb\u5165\u4ed3\u5e93 \u2192 Settings \u2192 Secrets and variables \u2192 Actions\uff0c\u6dfb\u52a0\u4ee5\u4e0b\u4e09\u4e2a Secrets\uff1a<\/p>\n<ul>\n<li><strong>SERVER_HOST<\/strong>\uff1aVPS \u7684 IP \u5730\u5740\u6216\u57df\u540d\uff0c\u4f8b\u5982 <code>123.45.67.89<\/code><\/li>\n<li><strong>SERVER_USER<\/strong>\uff1aSSH \u767b\u5f55\u7528\u6237\u540d\uff0c\u4f8b\u5982 <code>deploy<\/code><\/li>\n<li><strong>SSH_PRIVATE_KEY<\/strong>\uff1a\u4e0a\u4e00\u6b65\u751f\u6210\u7684\u79c1\u94a5\u5b8c\u6574\u5185\u5bb9\uff0c\u5305\u62ec <code>-----BEGIN OPENSSH PRIVATE KEY-----<\/code> \u548c\u7ed3\u5c3e\u6807\u8bb0<\/li>\n<\/ul>\n<h3>3.4 \u83b7\u53d6 known_hosts \u6307\u7eb9<\/h3>\n<p>\u4e3a\u9632\u6b62 SSH \u4e2d\u95f4\u4eba\u653b\u51fb\uff0c\u5efa\u8bae\u5728 workflow \u4e2d\u56fa\u5b9a <code>known_hosts<\/code>\uff1a<\/p>\n<pre><code class=\"language-bash\">ssh-keyscan -H 123.45.67.89 >> ~\/.ssh\/known_hosts\n<\/code><\/pre>\n<p>\u7136\u540e\u5c06\u8f93\u51fa\u5185\u5bb9\u5b58\u5165 <code>KNOWN_HOSTS<\/code> Secret\uff0c\u5728 Action \u4e2d\u4f7f\u7528\uff1a<\/p>\n<pre><code class=\"language-yaml\">      - name: Setup SSH known hosts\n        uses: webfactory\/ssh-agent@v0.9.0\n        with:\n          ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}\n          ssh-known-hosts: ${{ secrets.KNOWN_HOSTS }}\n<\/code><\/pre>\n<h2>\u56db\u3001\u8fdb\u9636\uff1a\u591a\u73af\u5883\u90e8\u7f72\u4e0e\u56de\u6eda\u7b56\u7565<\/h2>\n<p>\u5f53\u9879\u76ee\u6b65\u5165\u6b63\u8f68\uff0c\u4f60\u901a\u5e38\u9700\u8981\u533a\u5206 staging\uff08\u9884\u53d1\u5e03\uff09\u548c production\uff08\u751f\u4ea7\uff09\u4e24\u5957\u73af\u5883\u3002GitHub Actions \u901a\u8fc7 <strong>Environment<\/strong> \u529f\u80fd\u4f18\u96c5\u5730\u89e3\u51b3\u4e86\u8fd9\u4e2a\u9700\u6c42\u3002<\/p>\n<h3>4.1 \u591a\u73af\u5883 Workflow<\/h3>\n<pre><code class=\"language-yaml\">name: Multi-Environment Deploy\n\non:\n  push:\n    branches:\n      - develop\n      - main\n\njobs:\n  deploy:\n    runs-on: ubuntu-latest\n    environment: ${{ github.ref == 'refs\/heads\/main' && 'production' || 'staging' }}\n\n    steps:\n      - uses: actions\/checkout@v4\n\n      - name: Deploy\n        uses: appleboy\/ssh-action@v1\n        with:\n          host: ${{ github.ref == 'refs\/heads\/main' && secrets.PROD_HOST || secrets.STAGING_HOST }}\n          username: ${{ secrets.SERVER_USER }}\n          key: ${{ secrets.SSH_PRIVATE_KEY }}\n          script: |\n            cd ${{ github.ref == 'refs\/heads\/main' && '\/var\/www\/prod' || '\/var\/www\/staging' }}\n            git fetch --all\n            git reset --hard origin\/${{ github.ref == 'refs\/heads\/main' && 'main' || 'develop' }}\n            npm ci --production\n            npm run build\n            pm2 restart ${{ github.ref == 'refs\/heads\/main' && 'prod-app' || 'staging-app' }}\n<\/code><\/pre>\n<p>\u5728 GitHub \u4ed3\u5e93\u7684 Settings \u2192 Environments \u4e2d\u5206\u522b\u521b\u5efa <code>staging<\/code> \u548c <code>production<\/code> \u73af\u5883\uff0c\u5e76\u4e3a production \u73af\u5883\u6dfb\u52a0\u5ba1\u6279\u4fdd\u62a4\u2014\u2014\u8fd9\u6837\u6bcf\u6b21\u90e8\u7f72\u5230\u751f\u4ea7\u73af\u5883\u524d\uff0c\u90fd\u9700\u8981\u6307\u5b9a\u4eba\u5458\u624b\u52a8\u6279\u51c6\u3002<\/p>\n<h3>4.2 \u56de\u6eda\u7b56\u7565<\/h3>\n<p>\u5373\u4f7f\u6709\u81ea\u52a8\u5316\u6d4b\u8bd5\u4fdd\u9a7e\u62a4\u822a\uff0c\u7ebf\u4e0a\u5076\u5c14\u4ecd\u4f1a\u51fa\u95ee\u9898\u3002\u4ee5\u4e0b\u662f\u4e24\u79cd\u5b9e\u7528\u7684\u56de\u6eda\u65b9\u6848\uff1a<\/p>\n<p><strong>\u65b9\u6848\u4e00\uff1aGit commit \u56de\u6eda<\/strong><\/p>\n<pre><code class=\"language-bash\"># \u5728 VPS \u4e0a\u56de\u9000\u5230\u4e0a\u4e00\u4e2a\u7248\u672c\ncd \/var\/www\/myapp\ngit log --oneline -5          # \u67e5\u770b\u6700\u8fd15\u6b21\u63d0\u4ea4\ngit reset --hard abc1234      # \u56de\u9000\u5230\u6307\u5b9a commit\nnpm ci --production\nnpm run build\npm2 restart myapp\n<\/code><\/pre>\n<p><strong>\u65b9\u6848\u4e8c\uff1aRelease Tag \u90e8\u7f72<\/strong><\/p>\n<p>\u5c06\u89e6\u53d1\u6761\u4ef6\u6539\u4e3a tag \u63a8\u9001\uff0c\u6bcf\u6b21\u90e8\u7f72\u5bf9\u5e94\u4e00\u4e2a\u7248\u672c\u6807\u7b7e\uff0c\u56de\u6eda\u65f6\u5207\u6362\u5230\u6307\u5b9a tag \u5373\u53ef\uff1a<\/p>\n<pre><code class=\"language-yaml\">on:\n  push:\n    tags:\n      - 'v*'\n<\/code><\/pre>\n<h3>4.3 \u901a\u77e5\u4e0e\u76d1\u63a7<\/h3>\n<p>\u90e8\u7f72\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7 Slack\u3001Telegram \u6216\u9489\u9489\u7b49\u6e20\u9053\u53d1\u9001\u901a\u77e5\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a Telegram \u901a\u77e5\u7684\u793a\u4f8b\u6b65\u9aa4\uff1a<\/p>\n<pre><code class=\"language-yaml\">      - name: Send Telegram notification\n        if: always()\n        uses: appleboy\/telegram-action@v1\n        with:\n          to: ${{ secrets.TELEGRAM_CHAT_ID }}\n          token: ${{ secrets.TELEGRAM_BOT_TOKEN }}\n          message: |\n            \ud83d\ude80 \u90e8\u7f72 ${{ job.status }}\n            \ud83d\udce6 \u5206\u652f: ${{ github.ref_name }}\n            \ud83d\udcdd \u63d0\u4ea4: ${{ github.event.head_commit.message }}\n            \ud83d\udc64 \u4f5c\u8005: ${{ github.actor }}\n<\/code><\/pre>\n<p>\u66f4\u591a\u670d\u52a1\u5668\u8fd0\u7ef4\u76f8\u5173\u5185\u5bb9\uff0c\u53ef\u4ee5\u53c2\u8003 <a href=\"https:\/\/cn.hostease.com\/blog\/server\/\">\u670d\u52a1\u5668\u8fd0\u7ef4\u6307\u5357<\/a> \u4e2d\u7684\u7cfb\u5217\u6559\u7a0b\u3002<\/p>\n<p>\u66f4\u591a\u9009\u62e9 VPS\u76f8\u5173\u5185\u5bb9\uff0c\u53ef\u4ee5\u53c2\u8003 <a href=\"https:\/\/cn.hostease.com\/blog\/hosting-guide\/\" class=\"broken_link\">\u4e3b\u673a\u9009\u8d2d\u6307\u5357<\/a> \u4e2d\u7684\u7cfb\u5217\u6559\u7a0b\u3002<\/p>\n<h2>\u5de5\u4f5c\u6d41\u4f18\u5316\u6280\u5de7<\/h2>\n<p>\u5f53\u4f60\u7684 CI\/CD \u6d41\u6c34\u7ebf\u8fd0\u884c\u4e00\u6bb5\u65f6\u95f4\u540e\uff0c\u53ef\u80fd\u4f1a\u9047\u5230\u6784\u5efa\u901f\u5ea6\u53d8\u6162\u3001\u914d\u989d\u6d88\u8017\u8fc7\u5feb\u7b49\u95ee\u9898\u3002\u4ee5\u4e0b\u51e0\u4e2a\u4f18\u5316\u7b56\u7565\u53ef\u4ee5\u663e\u8457\u63d0\u5347\u6548\u7387\u5e76\u964d\u4f4e\u6210\u672c\u3002<\/p>\n<h3>\u7f13\u5b58\u4f9d\u8d56\u52a0\u901f\u6784\u5efa<\/h3>\n<p>\u6bcf\u6b21 CI \u8fd0\u884c\u90fd\u91cd\u65b0\u5b89\u88c5\u4f9d\u8d56\u4f1a\u6d6a\u8d39\u5927\u91cf\u65f6\u95f4\u3002\u4f7f\u7528\u7f13\u5b58 Action \u53ef\u4ee5\u5c06\u4f9d\u8d56\u7f13\u5b58\u5728 GitHub \u7684\u5bf9\u8c61\u5b58\u50a8\u4e2d\uff0c\u901a\u5e38\u80fd\u5c06\u5b89\u88c5\u6b65\u9aa4\u4ece\u4e24\u4e09\u5206\u949f\u7f29\u77ed\u5230\u5341\u79d2\u4ee5\u5185\u3002<\/p>\n<h3>\u77e9\u9635\u7b56\u7565\u5b9e\u73b0\u591a\u73af\u5883\u6d4b\u8bd5<\/h3>\n<p>\u5982\u679c\u4f60\u7684\u9879\u76ee\u9700\u8981\u5728\u591a\u4e2a Node.js \u7248\u672c\u6216\u64cd\u4f5c\u7cfb\u7edf\u4e0a\u6d4b\u8bd5\uff0c\u77e9\u9635\u7b56\u7565\u662f\u6700\u4f18\u96c5\u7684\u65b9\u6848\u3002\u53ea\u9700\u5728\u5de5\u4f5c\u6d41\u4e2d\u5b9a\u4e49\u77e9\u9635\u53d8\u91cf\uff0cGitHub Actions \u4f1a\u81ea\u52a8\u4e3a\u6bcf\u79cd\u7ec4\u5408\u521b\u5efa\u72ec\u7acb\u4efb\u52a1\u5e76\u884c\u8fd0\u884c\u3002<\/p>\n<h3>\u81ea\u6258\u7ba1 Runner \u7684\u6210\u672c\u63a7\u5236<\/h3>\n<p>\u5bf9\u4e8e\u79c1\u6709\u4ed3\u5e93\uff0cGitHub Actions \u7684\u514d\u8d39\u989d\u5ea6\u6709\u9650\u3002\u5982\u679c\u6784\u5efa\u9891\u7e41\uff0c\u53ef\u4ee5\u8003\u8651\u4f7f\u7528\u81ea\u6258\u7ba1 Runner\uff0c\u5c06 CI \u4efb\u52a1\u8dd1\u5728\u81ea\u5df1\u7684 VPS \u4e0a\uff0c\u7701\u53bb\u6309\u5206\u949f\u8ba1\u8d39\u7684\u6210\u672c\u3002<\/p>\n<h2>\u603b\u7ed3\u4e0e\u884c\u52a8\u5efa\u8bae<\/h2>\n<p>\u901a\u8fc7\u672c\u6587\uff0c\u4f60\u5df2\u7ecf\u4e86\u89e3\u4e86 GitHub Actions \u7684\u6838\u5fc3\u6982\u5ff5\uff0c\u5e76\u638c\u63e1\u4e86\u4ece\u57fa\u7840\u5230\u8fdb\u9636\u7684\u5b8c\u6574\u90e8\u7f72\u65b9\u6848\u3002\u56de\u987e\u4e00\u4e0b\u5173\u952e\u8981\u70b9\uff1a<\/p>\n<ul>\n<li>Workflow \u2192 Job \u2192 Step \u2192 Runner\uff0c\u56db\u5c42\u7ed3\u6784\u6e05\u6670\u5206\u5de5<\/li>\n<li>\u4f7f\u7528 Secrets \u5b58\u50a8\u654f\u611f\u4fe1\u606f\uff0c\u516c\u94a5\u90e8\u7f72\u5230 VPS\uff0c\u79c1\u94a5\u4ea4\u7ed9 GitHub<\/li>\n<li>rsync \u9002\u5408\u9759\u6001\u7ad9\u70b9\uff0cSSH + \u8fdc\u7a0b\u811a\u672c\u9002\u5408\u9700\u8981\u5728\u670d\u52a1\u5668\u6784\u5efa\u7684\u9879\u76ee<\/li>\n<li>Environment + \u5206\u652f\u7b56\u7565\u5b9e\u73b0\u591a\u73af\u5883\u9694\u79bb\uff0ctag \u90e8\u7f72\u4fbf\u4e8e\u7248\u672c\u56de\u6eda<\/li>\n<\/ul>\n<p>\u73b0\u5728\u5c31\u884c\u52a8\u8d77\u6765\u5427\uff1a<\/p>\n<ol>\n<li>\u6253\u5f00\u4f60\u7684 GitHub \u4ed3\u5e93\uff0c\u521b\u5efa <code>.github\/workflows\/deploy.yml<\/code><\/li>\n<li>\u751f\u6210 SSH \u5bc6\u94a5\u5bf9\uff0c\u914d\u7f6e Secrets<\/li>\n<li>\u63a8\u4e00\u6b21\u4ee3\u7801\uff0c\u89c2\u5bdf Actions \u9875\u9762\u7684\u7eff\u8272\u52fe \u2705<\/li>\n<\/ol>\n<p>\u5982\u679c\u4f60\u6b63\u5728\u5bfb\u627e\u4e00\u53f0\u7a33\u5b9a\u53ef\u9760\u7684\u670d\u52a1\u5668\u6765\u6258\u7ba1\u9879\u76ee\uff0c\u4e0d\u59a8\u4e86\u89e3\u4e00\u4e0b <a href=\"https:\/\/cn.hostease.com\">Hostease<\/a> \u63d0\u4f9b\u7684 VPS \u65b9\u6848\u2014\u2014\u914d\u5408 GitHub Actions \u7684\u81ea\u52a8\u5316\u6d41\u6c34\u7ebf\uff0c\u4f60\u5c06\u62e5\u6709\u4e00\u5957\u771f\u6b63\u7701\u5fc3\u7684\u5f00\u53d1\u90e8\u7f72\u4f53\u9a8c\u3002\u5173\u4e8e[\u670d\u52a1\u5668\u914d\u7f6e](https:\/\/cn.hostease.com\/blog\/server\/)\u4e0e\u4f18\u5316\u7684\u66f4\u591a\u6280\u5de7\uff0c\u4e5f\u53ef\u4ee5\u53c2\u8003\u6211\u4eec\u7684 <a href=\"https:\/\/cn.hostease.com\/vps-hosting\/\">VPS \u6258\u7ba1\u6307\u5357<\/a> \u548c <a href=\"https:\/\/cn.hostease.com\/blog\/\">\u6280\u672f\u535a\u5ba2<\/a>\uff0c\u52a9\u4f60\u9ad8\u6548\u8fd0\u7ef4\uff0c\u4e13\u6ce8\u5f00\u53d1\u3002<\/p>\n<p>\u5efa\u8bae\u5c06\u672c\u6587\u6536\u85cf\u4e3a\u90e8\u7f72\u6e05\u5355\uff0c\u6bcf\u6b21\u4e0a\u7ebf\u65b0\u9879\u76ee\u65f6\u5bf9\u7167\u68c0\u67e5\uff0c\u53ef\u4ee5\u907f\u514d 90% \u7684\u5e38\u89c1\u914d\u7f6e\u95ee\u9898\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4ece\u96f6\u642d\u5efa GitHub Actions \u81ea\u52a8\u90e8\u7f72\u6d41\u6c34\u7ebf\uff0c\u4ee3\u7801\u63a8\u9001\u5373\u81ea\u52a8\u6d4b\u8bd5\u3001\u6784\u5efa\u3001\u90e8\u7f72\u5230 VPS\uff0c\u542b\u5b8c\u6574 workflow \u914d\u7f6e\u793a\u4f8b\u3002<\/p>\n","protected":false},"author":2,"featured_media":31170,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4099],"tags":[4360,4377,882,3976],"class_list":["post-31128","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","tag-cicd","tag-githubactions","tag-vps","tag-category"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/cn.hostease.com\/blog\/wp-content\/uploads\/2026\/06\/31128_github-actions-auto-deploy-vps-cover.webp","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/cn.hostease.com\/blog\/wp-json\/wp\/v2\/posts\/31128","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cn.hostease.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cn.hostease.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cn.hostease.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/cn.hostease.com\/blog\/wp-json\/wp\/v2\/comments?post=31128"}],"version-history":[{"count":1,"href":"https:\/\/cn.hostease.com\/blog\/wp-json\/wp\/v2\/posts\/31128\/revisions"}],"predecessor-version":[{"id":31150,"href":"https:\/\/cn.hostease.com\/blog\/wp-json\/wp\/v2\/posts\/31128\/revisions\/31150"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cn.hostease.com\/blog\/wp-json\/wp\/v2\/media\/31170"}],"wp:attachment":[{"href":"https:\/\/cn.hostease.com\/blog\/wp-json\/wp\/v2\/media?parent=31128"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cn.hostease.com\/blog\/wp-json\/wp\/v2\/categories?post=31128"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cn.hostease.com\/blog\/wp-json\/wp\/v2\/tags?post=31128"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}