1.在服务器生成ssh密钥对 教程
2.将密钥添加到仓库的Secrets中
代码仓库 - Settings - Secrets - Actions
添加完成后就可以在action中使用了
3.部署代码示例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
| name: Build and Deploy
on: push: branches: - main
permissions: contents: read
jobs: build: runs-on: ubuntu-latest environment: production steps: - name: Checkout uses: actions/checkout@v3 - name: Cache nodemodules uses: actions/cache@v1 env: cache-name: cache-node-modules with: path: ./node_modules key: ${{ runner.os }}-dist-${{ env.cache-name }}-${{ hashFiles('./package.json') }} restore-keys: | ${{ runner.os }}-dist-${{ env.cache-name }}- ${{ runner.os }}-dist- ${{ runner.os }}- - name: Install run: yarn - name: Build run: yarn build - name: Deploy uses: AEnterprise/rsync-deploy@v1.0 env: DEPLOY_KEY: ${{ secrets.SERVER_PRIVATE_KEY }} ARGS: '-avz --delete' FOLDER: 'dist/' SERVER_PORT: ${{ secrets.SERVER_PORT }} SERVER_IP: ${{ secrets.SERVER_HOST }} USERNAME: ${{ secrets.USER_NAME }} SERVER_DESTINATION: ${{secrets.SERVER_DESTINATION}}
|