deploy-prod.yml 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. name: Deploy Prod
  2. on:
  3. workflow_dispatch:
  4. inputs:
  5. ref:
  6. description: "部署哪个ref, e.g.: main/61fas4/v1.0.0"
  7. required: true
  8. default: "main"
  9. concurrency:
  10. group: ${{ github.workflow }}
  11. cancel-in-progress: true
  12. jobs:
  13. build:
  14. runs-on: ubuntu-latest
  15. name: Build and Deploy
  16. permissions:
  17. contents: write
  18. outputs:
  19. tag: ${{ steps.generate_release_tag.outputs.next_release_tag }}
  20. release_url: ${{ steps.create_release.outputs.html_url }}
  21. steps:
  22. # - name: Generate release tag
  23. # id: generate_release_tag
  24. # uses: amitsingh-007/next-release-tag@v6.0.0
  25. # with:
  26. # github_token: ${{ secrets.GITHUB_TOKEN }}
  27. # tag_prefix: "v"
  28. # tag_template: "yyyy.mm.dd.i"
  29. # - name: Create Release
  30. # id: create_release
  31. # uses: actions/create-release@v1
  32. # env:
  33. # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  34. # with:
  35. # tag_name: ${{ steps.generate_release_tag.outputs.next_release_tag }}
  36. # release_name: Release ${{ steps.generate_release_tag.outputs.next_release_tag }}
  37. # draft: false
  38. # prerelease: false
  39. # commitish: ${{inputs.ref}}
  40. # - uses: actions/checkout@v4
  41. # with:
  42. # ref: ${{ steps.generate_release_tag.outputs.next_release_tag }}
  43. # - run: |
  44. # echo "deploying ref: ${{ inputs.ref }}"
  45. # echo "tag: ${{ steps.generate_release_tag.outputs.next_release_tag }}"
  46. # # - run: git rev-parse --abbrev-ref HEAD
  47. # - name: Use Node.js 20.x
  48. # uses: actions/setup-node@v4
  49. # with:
  50. # node-version: 20
  51. # cache: "npm"
  52. # - run: npm i
  53. # - run: npm run build
  54. # - name: Archive production artifacts
  55. # run: |
  56. # mkdir -p release
  57. # cp -r dist/* release/
  58. # tar -czvf release.tar.gz release/
  59. # - name: Upload Release Asset
  60. # uses: actions/upload-release-asset@v1
  61. # env:
  62. # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  63. # with:
  64. # upload_url: ${{ steps.create_release.outputs.upload_url }}
  65. # asset_path: ./release.tar.gz
  66. # asset_name: release.tar.gz
  67. # asset_content_type: application/gzip
  68. - name: executing remote ssh commands using ssh key
  69. uses: appleboy/ssh-action@v1.0.3
  70. with:
  71. host: ${{ secrets.PROD_SSH_HOST }}
  72. username: ${{ secrets.PROD_SSH_USER }}
  73. key: ${{ secrets.PROD_SSH_KEY }}
  74. port: ${{ secrets.PROD_SSH_PORT }}
  75. script: |
  76. whoami
  77. cd ${{secrets.PROD_SSH_DIR}}
  78. ls -l
  79. # - name: Publish with rsync
  80. # uses: GuillaumeFalourd/setup-rsync@v1.2
  81. # id: rsync
  82. # with:
  83. # ssh_key: ${{ secrets.PROD_SSH_KEY }}
  84. # - run: rsync -av -e 'ssh -i ${{ steps.rsync.outputs.ssh_key_path }} -p ${{secrets.PROD_SSH_PORT}} -o StrictHostKeyChecking=no -v' --delete ./dist/ ${{secrets.PROD_SSH_USER}}@${{secrets.PROD_SSH_HOST}}:${{ secrets.PROD_SSH_DIR }}
  85. # notify:
  86. # runs-on: ubuntu-latest
  87. # name: Notify deploy status
  88. # needs: build
  89. # steps:
  90. - name: Feishu notify deploy status
  91. if: ${{needs.build.result == 'success' || needs.build.result == 'failure'}}
  92. uses: wangsijie/feishu-bot@v1
  93. with:
  94. uuid: ${{secrets.FEISHU_CICD_BOT_ID}}
  95. data: |
  96. {
  97. "msg_type": "interactive",
  98. "card": {
  99. "elements": [
  100. {
  101. "tag": "div",
  102. "text": {
  103. "content": "**项目**: 知识建构",
  104. "tag": "lark_md"
  105. }
  106. },
  107. {
  108. "tag": "div",
  109. "text": {
  110. "content": "**环境**: PROD",
  111. "tag": "lark_md"
  112. }
  113. },
  114. {
  115. "tag": "div",
  116. "text": {
  117. "content": "**结果**: ${{needs.build.result == 'failure' && '❌' || '✅'}}",
  118. "tag": "lark_md"
  119. }
  120. },
  121. {
  122. "tag": "div",
  123. "text": {
  124. "content": "**Tag**: ${{needs.build.outputs.tag}}",
  125. "tag": "lark_md"
  126. }
  127. },
  128. {
  129. "actions": [{
  130. "tag": "button",
  131. "text": {
  132. "content": "查看过程",
  133. "tag": "lark_md"
  134. },
  135. "url": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}",
  136. "type": "default",
  137. "value": {}
  138. }, {
  139. "tag": "button",
  140. "text": {
  141. "content": "查看Release",
  142. "tag": "lark_md"
  143. },
  144. "url": "${{ needs.build.outputs.release_url }}",
  145. "type": "default",
  146. "value": {}
  147. }],
  148. "tag": "action"
  149. }
  150. ],
  151. "header": {
  152. "title": {
  153. "content": "部署结果通知",
  154. "tag": "plain_text"
  155. }
  156. }
  157. }
  158. }