[{"data":1,"prerenderedAt":239},["ShallowReactive",2],{"content:\u002Fposts\u002F2022\u002Fgithubactions-deploy":3,"surround:\u002Fposts\u002F2022\u002Fgithubactions-deploy":228},{"id":4,"title":5,"body":6,"canonical":200,"categories":201,"date":203,"description":204,"draft":205,"extension":206,"image":207,"meta":208,"navigation":209,"path":210,"permalink":200,"readingTime":211,"recommend":200,"references":200,"seo":216,"sitemap":217,"stem":223,"tags":224,"type":200,"updated":203,"__hash__":227},"content\u002Fposts\u002F2022\u002FGitHubActions-deploy.md","使用GitHubActions部署",{"type":7,"value":8,"toc":184},"minimark",[9,14,25,28,32,36,39,43,59,62,74,83,109,112,118,122,125,131,134,149,155,159,166,174],[10,11,13],"h2",{"id":12},"github-actions","GitHub Actions",[15,16,17,18,24],"p",{},"GitHub Actions 是 GitHub 的持续集成服务，我们可以使用它做网站的自动部署等工作。可以点击下面的链接查看示例。\n",[19,20,21],"a",{"href":21,"rel":22},"https:\u002F\u002Fwww.ruanyifeng.com\u002Fblog\u002F2019\u002F09\u002Fgetting-started-with-github-actions.html",[23],"nofollow"," desc:true",[15,26,27],{},"我们这里只做应用。",[10,29,31],{"id":30},"github-变量","GitHub 变量",[33,34,35],"h3",{"id":35},"添加",[15,37,38],{},"可以到 GitHub 仓库的 settings -> Secrets -> Actions 中新增变量",[40,41,42],"h4",{"id":42},"具体步骤如下",[15,44,45,50,53,56],{},[46,47],"img",{"alt":48,"src":49},"","https:\u002F\u002Fbitmc.uno\u002Fpicgo\u002F679ad55c86890-78.webp",[46,51],{"alt":48,"src":52},"https:\u002F\u002Fbitmc.uno\u002Fpicgo\u002F679ad55dabe5f-78.webp",[46,54],{"alt":48,"src":55},"https:\u002F\u002Fbitmc.uno\u002Fpicgo\u002F679ad55e8f6c3-78.webp",[46,57],{"alt":48,"src":58},"https:\u002F\u002Fbitmc.uno\u002Fpicgo\u002F679ad55d2e6c4-78.webp",[33,60,61],{"id":61},"如何使用",[15,63,64,65,69,70,73],{},"在配置文件 ",[66,67,68],"code",{"code":68},".github\u002Fworkflows\u002Fmain.yml"," 中可以使用 ",[66,71,72],{"code":72},"${{secrets.变量名}}"," 的方式使用",[75,76,81],"pre",{"className":77,"code":79,"filename":68,"language":80,"meta":48},[78],"language-yml","name: copy dist file with scp\nuses: appleboy\u002Fscp-action@master\nwith:\n  host: ${{ secrets.WXW_HOST }}\n  username: ${{ secrets.WXW_USERNAME }}\n  password: ${{ secrets.WXW_PASSWORD }}\n  port: 22\n  source: public\u002F\n  target: ${{ secrets.WXW_TARGET }}\n","yml",[66,82,79],{"__ignoreMap":48},[84,85,86],"blockquote",{},[15,87,88,89,92,93,96,97,100,101,104,105],{},"这里的",[66,90,91],{"code":91},"WXW_HOST","是服务器公网 ip，",[66,94,95],{"code":95},"WXW_USERNAME"," 是服务器用户名， ",[66,98,99],{"code":99},"WXW_PASSWORD"," 是服务器用户密码， ",[66,102,103],{"code":103},"WXW_TARGET","是要复制文件到那个文件中。\n",[106,107,108],"strong",{},"我们会在下面的配置中使用这几个变量",[10,110,111],{"id":111},"最终代码",[75,113,116],{"className":114,"code":115,"language":80,"meta":68},[78],"name: deplay-hexo-blog\non:\n  push:\n    branches: [master]\n  workflow_dispatch:\n\njobs:\n  build:\n    runs-on: ubuntu-latest\n    steps:\n      - uses: actions\u002Fcheckout@v3\n      # 安装nodejs\n      - name: install nodejs\n        uses: actions\u002Fsetup-node@v3.4.1\n        with:\n          node-version: 16.x\n      # 安装依赖\n      - name: install packages\n        run: npm install\n      # 打包项目\n      - name: build\n        run: npm run build\n      # 文件复制到服务器\n      - name: copy dist file with scp\n        uses: appleboy\u002Fscp-action@master\n        with:\n          host: ${{ secrets.WXW_HOST }}\n          username: ${{ secrets.WXW_USERNAME }}\n          password: ${{ secrets.WXW_PASSWORD }}\n          port: 22\n          source: public\u002F\n          target: ${{ secrets.WXW_TARGET }}\n",[66,117,115],{"__ignoreMap":48},[33,119,121],{"id":120},"代码详解","代码详解：",[15,123,124],{},"这段代码表示在 master 分支提交时会触发该 actions",[75,126,129],{"className":127,"code":128,"language":80,"meta":48},[78],"on:\n  push:\n    branches: [master]\n  workflow_dispatch:\n",[66,130,128],{"__ignoreMap":48},[15,132,133],{},"这一段为使用 ubuntu-latest 虚拟机执行，安装 nodejs -> 安装依赖 -> 项目打包 -> 将文件复制到服务器指定位置",[15,135,136,137,140,141,144,145,148],{},"name 为 ",[66,138,139],{"code":139},"copy dist file with scp"," 这一段会把生成好的 ",[66,142,143],{"code":143},"public"," 文件复制到服务器指定位置 ",[66,146,147],{"code":147},"${{secrets.WXW_TARGET}}"," 下",[75,150,153],{"className":151,"code":152,"language":80,"meta":48},[78],"jobs:\n  build:\n    runs-on: ubuntu-latest\n    steps:\n      - uses: actions\u002Fcheckout@v3\n      # 安装nodejs\n      - name: install nodejs\n        uses: actions\u002Fsetup-node@v3.4.1\n        with:\n          node-version: 16.x\n      # 安装依赖\n      - name: install packages\n        run: npm install\n      # 打包项目\n      - name: build\n        run: npm run build\n      # 文件复制到服务器\n      - name: copy dist file with scp\n        uses: appleboy\u002Fscp-action@master\n        with:\n          host: ${{ secrets.WXW_HOST }}\n          username: ${{ secrets.WXW_USERNAME }}\n          password: ${{ secrets.WXW_PASSWORD }}\n          port: 22\n          source: public\u002F\n          target: ${{ secrets.WXW_TARGET }}\n",[66,154,152],{"__ignoreMap":48},[10,156,158],{"id":157},"服务器配置-nginx","服务器配置 nginx",[15,160,161,162,165],{},"我这里使用",[66,163,164],{"code":164},"www.weilog.me","这个域名",[75,167,172],{"className":168,"code":170,"language":171,"meta":48},[169],"language-nginx","server {\n    listen 80;\n    server_name www.weilog.me;\n    location \u002F {\n      root \u002Fcode\u002Fpublic;\n      index index.html;\n      try_files $uri $uri\u002F = 404;\n    }\n}\n","nginx",[66,173,170],{"__ignoreMap":48},[15,175,176,177,180,181,183],{},"配置好后，运行",[66,178,179],{"code":179},"nginx -s reload","重启一下 nginx 服务器，我们就可以使用",[66,182,164],{"code":164},"来访问我们部署好的网站了。",{"title":48,"searchDepth":185,"depth":185,"links":186},4,[187,189,196,199],{"id":12,"depth":188,"text":13},2,{"id":30,"depth":188,"text":31,"children":190},[191,195],{"id":35,"depth":192,"text":35,"children":193},3,[194],{"id":42,"depth":185,"text":42},{"id":61,"depth":192,"text":61},{"id":111,"depth":188,"text":111,"children":197},[198],{"id":120,"depth":192,"text":121},{"id":157,"depth":188,"text":158},null,[202],"代码","2022-12-05 16:25:27","使用阿里云服务器搭建 hexo 博客",false,"md","https:\u002F\u002Fbitmc.uno\u002Fpicgo\u002FGitHubActions-deploy.webp",{},true,"\u002Fposts\u002F2022\u002Fgithubactions-deploy",{"text":212,"minutes":213,"time":214,"words":215},"3 min read",2.555,153300,511,{"title":5,"description":204},{"loc":210,"images":218},[219,220,221,222],{"loc":49},{"loc":52},{"loc":55},{"loc":58},"posts\u002F2022\u002FGitHubActions-deploy",[225,226],"hexo","GitHubActions","4C_Y8XkKRQVavaJfLXCd1_KOugSvjBzW5C0nziRzOJ0",[229,234],{"title":230,"path":231,"stem":232,"date":233,"type":200,"children":-1},"nest 服务提供者","\u002Fposts\u002F2022\u002Fnest-providers","posts\u002F2022\u002Fnest-providers","2022-12-04 16:15:46",{"title":235,"path":236,"stem":237,"date":238,"type":200,"children":-1},"js数组","\u002Fposts\u002F2022\u002Fjs-array","posts\u002F2022\u002Fjs-array","2022-12-07 14:01:02",1789642595907]