From 76b0e6ecacd080faf7aa91e743b5a012d8cd6448 Mon Sep 17 00:00:00 2001 From: LeoZhang <117000082@qq.com> Date: Tue, 25 Aug 2020 14:25:59 +0800 Subject: [PATCH] ci/cd --- .github/workflows/main.yml | 60 ++++++++++++++++++++++++++++++++++++++ pm2.config.json | 9 ++++++ 2 files changed, 69 insertions(+) create mode 100644 .github/workflows/main.yml create mode 100644 pm2.config.json diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..7c18da8 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,60 @@ +name: Publish And Deploy Demo +on: + push: + tags: + - 'v*' + +jobs: + build-and-deploy: + runs-on: ubuntu-latest + steps: + + # 下载源码 + - name: Checkout + uses: actions/checkout@master + + # 打包构建 + - name: Build + uses: actions/setup-node@master + - run: npm install + - run: npm run build + - run: tar -zcvf release.tgz .nuxt static nuxt.config.js package.json package-lock.json pm2.config.json + + # 发布 Release + - name: Create Release + id: create_release + uses: actions/create-release@master + env: + GITHUB_TOKEN: ${{ secrets.TOKEN }} + with: + tag_name: ${{ github.ref }} + release_name: Release ${{ github.ref }} + draft: false + prerelease: false + + # 上传构建结果到 Release + - name: Upload Release Asset + id: upload-release-asset + uses: actions/upload-release-asset@master + env: + GITHUB_TOKEN: ${{ secrets.TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ./release.tgz + asset_name: release.tgz + asset_content_type: application/x-tgz + + # 部署到服务器 + - name: Deploy + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.HOST }} + username: ${{ secrets.USERNAME }} + password: ${{ secrets.PASSWORD }} + port: ${{ secrets.PORT }} + script: | + cd /root/realworld-nuxtjs + wget https://github.com/95erlong/realworld-nuxtjs/releases/latest/download/release.tgz -O release.tgz + tar zxvf release.tgz + npm install --production + pm2 reload pm2.config.js \ No newline at end of file diff --git a/pm2.config.json b/pm2.config.json new file mode 100644 index 0000000..dbee9e6 --- /dev/null +++ b/pm2.config.json @@ -0,0 +1,9 @@ +{ + "apps": [ + { + "name": "RealWorld", + "script": "npm", + "args": "start" + } + ] +} \ No newline at end of file