From 549c8977883b5d52265b6e8f4999234bb6cf87c9 Mon Sep 17 00:00:00 2001 From: root <3234374354@qq.com> Date: Sat, 30 Nov 2024 23:41:42 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9B=E5=BB=BA=E8=87=AA=E5=8A=A8=E9=83=A8?= =?UTF-8?q?=E7=BD=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .githun/workflows/main.yml | 59 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 .githun/workflows/main.yml diff --git a/.githun/workflows/main.yml b/.githun/workflows/main.yml new file mode 100644 index 0000000..bb38498 --- /dev/null +++ b/.githun/workflows/main.yml @@ -0,0 +1,59 @@ +name: Deploy +on: + push: + branches: + - main + +jobs: + build-and-deploy: + runs-on: ubuntu-latest # 运行环境,告诉它运行在什么环境 + steps: # 步骤 + + # 第一步:下载源码(CI/CD拉取代码到自己的本地) + - name: Checkout + uses: actions/checkout@main + + # 第二步:打包构建 + - name: Build + uses: actions/setup-node@main + # - run: npm install # 安装第三方包 + # - run: npm run build # 打包 + - run: tar -zcvf release.tgz . + # 把当前源代码目录所有文件,打包压缩为release.tgz + + # 第三步:发布 Release + - name: Create Release # 创建Release,可以在仓库看到一个个版本 + id: create_release + uses: actions/create-release@main + # env: + # GITHUB_TOKEN: ${{ secrets.TOKEN }} # 之前GitHub添加的Token + with: + tag_name: ubdata + release_name: Release ubdata + draft: false # 是否是草稿 + prerelease: false # 是否是预发布 + + # 第四步:上传构建结果到 Release(把打包的tgz上传到Release) + - name: Upload Release Asset + id: upload-release-asset + uses: actions/upload-release-asset@main + env: + GITHUB_TOKEN: ${{ secrets.TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} # 上传地址,通过创建Release获取到的 + asset_path: ./release.tgz # 要上传文件 + asset_name: release.tgz # 上传后的文件名 + asset_content_type: application/x-tgz + + # 第五步:部署到服务器 + - name: Deploy + uses: appleboy/ssh-action@main # 使用ssh链接服务器 + with: + host: 10.147.17.161 + username: root + password: Hxl110119 + port: 22 + script: | # 执行命令(运行到服务器)cd:要确保服务器有这个目录; wget:下载上一步的release到服务器; tar:解压; 安装依赖;启动服务 + cd /www/1panel/apps/openresty/openresty/www/sites/other/index + wget http://10.147.17.160:3000/he_and_smallyue/other-web/releases/latest/download/release.tgz -O release.tgz + tar zxvf release.tgz