deploy.yml 3.4 KB
Newer Older
V
vben 已提交
1 2 3 4 5 6 7 8
name: deploy

on:
  push:
    branches:
      - main

jobs:
V
Vben 已提交
9 10 11 12 13 14
  # push-to-ftp:
  #   if: "contains(github.event.head_commit.message, '[deploy]')"
  #   runs-on: ubuntu-latest
  #   steps:
  #     - name: Checkout
  #       uses: actions/checkout@v2
V
Vben 已提交
15

V
Vben 已提交
16 17 18 19 20 21
  #     - name: Sed Config Base
  #       shell: bash
  #       run: |
  #         sed -i  's#VITE_PUBLIC_PATH\s*=.*#VITE_PUBLIC_PATH = /next/#g' ./.env.production
  #         sed -i  "s#VITE_BUILD_COMPRESS\s*=.*#VITE_BUILD_COMPRESS = 'gzip'#g" ./.env.production
  #         cat ./.env.production
V
Vben 已提交
22

V
Vben 已提交
23 24 25 26
  #     - name: use Node.js 14
  #       uses: actions/setup-node@v2.1.2
  #       with:
  #         node-version: '14.x'
V
Vben 已提交
27

V
Vben 已提交
28 29 30
  #     - name: Get yarn cache
  #       id: yarn-cache
  #       run: echo "::set-output name=dir::$(yarn cache dir)"
V
Vben 已提交
31

V
Vben 已提交
32 33 34 35 36 37 38
  #     - name: Cache dependencies
  #       uses: actions/cache@v2
  #       with:
  #         path: ${{ steps.yarn-cache.outputs.dir }}
  #         key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
  #         restore-keys: |
  #           ${{ runner.os }}-yarn-
V
Vben 已提交
39

V
Vben 已提交
40 41 42 43
  #     - name: Build
  #       run: |
  #         yarn install
  #         yarn run build
V
Vben 已提交
44

V
Vben 已提交
45 46 47 48 49 50 51 52 53 54 55
  #     - name: Deploy
  #       uses: SamKirkland/FTP-Deploy-Action@2.0.0
  #       env:
  #         FTP_SERVER: ${{ secrets.FTP_SERVER }}
  #         FTP_USERNAME: ${{ secrets.FTP_USERNAME }}
  #         FTP_PASSWORD: ${{ secrets.FTP_PASSWORD }}
  #         METHOD: sftp
  #         PORT: ${{ secrets.FTP_PORT }}
  #         LOCAL_DIR: dist
  #         REMOTE_DIR: /srv/www/vben-admin
  #         ARGS: --delete --verbose --parallel=80
V
vben 已提交
56

V
Vben 已提交
57
  push-to-gh-pages:
V
Vben 已提交
58
    runs-on: ubuntu-latest
V
vben 已提交
59
    steps:
V
Vben 已提交
60
      - name: Checkout
J
JinMao 已提交
61
        uses: actions/checkout@v3
V
Vben 已提交
62 63 64 65 66

      - name: Sed Config Base
        shell: bash
        run: |
          sed -i  "s#VITE_BUILD_COMPRESS\s*=.*#VITE_BUILD_COMPRESS = 'gzip'#g" ./.env.production
V
vben 已提交
67
          sed -i  "s#VITE_DROP_CONSOLE\s*=.*#VITE_DROP_CONSOLE = true#g" ./.env.production
V
Vben 已提交
68 69
          cat ./.env.production

V
vben 已提交
70
      - name: use Node.js 16
J
JinMao 已提交
71
        uses: actions/setup-node@v3
V
Vben 已提交
72
        with:
V
vben 已提交
73
          node-version: '16.x'
V
Vben 已提交
74 75 76 77 78 79

      - name: Get yarn cache
        id: yarn-cache
        run: echo "::set-output name=dir::$(yarn cache dir)"

      - name: Cache dependencies
J
JinMao 已提交
80
        uses: actions/cache@v3
V
Vben 已提交
81 82 83 84 85 86 87 88
        with:
          path: ${{ steps.yarn-cache.outputs.dir }}
          key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
          restore-keys: |
            ${{ runner.os }}-yarn-

      - name: Set SSH Environment
        env:
J
JinMao 已提交
89
          DOCS_DEPLOY_KEY: ${{ secrets.ACTIONS_DEPLOY_KEY }}
V
Vben 已提交
90 91
        run: |
          mkdir -p ~/.ssh/
J
JinMao 已提交
92
          echo "$ACTIONS_DEPLOY_KEY" > ~/.ssh/id_rsa
V
Vben 已提交
93 94 95
          chmod 600 ~/.ssh/id_rsa
          ssh-keyscan github.com > ~/.ssh/known_hosts
          chmod 700 ~/.ssh && chmod 600 ~/.ssh/*
V
vben 已提交
96 97
          git config --global user.email "vbenadmin@163.com"
          git config --global user.name "vbenAdmin"
V
Vben 已提交
98 99 100 101 102

      - name: Build
        run: |
          yarn install
          yarn run build
V
Vben 已提交
103 104
          touch dist/.nojekyll
          cp dist/index.html dist/404.html
V
vben 已提交
105

J
JinMao 已提交
106 107 108 109
      - name: Delete gh-pages branch
        run: |
          git push origin --delete gh-pages

V
vben 已提交
110
      - name: Deploy
J
JinMao 已提交
111
        uses: peaceiris/actions-gh-pages@v2.5.0
V
vben 已提交
112
        env:
J
JinMao 已提交
113
          ACTIONS_DEPLOY_KEY: ${{secrets.ACTIONS_DEPLOY_KEY}}
V
vben 已提交
114
          PUBLISH_BRANCH: gh-pages
V
vben 已提交
115
          PUBLISH_DIR: ./dist
J
JinMao 已提交
116
          CNAME: vben.vvbin.cn
V
vben 已提交
117 118
        with:
          forceOrphan: true
V
vben 已提交
119

J
JinMao 已提交
120 121