123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- name: Deploy Prod
- on:
- workflow_dispatch:
- inputs:
- ref:
- description: "部署哪个ref, e.g.: main/61fas4/v1.0.0"
- required: true
- default: "main"
- concurrency:
- group: ${{ github.workflow }}
- cancel-in-progress: true
- jobs:
- build:
- runs-on: ubuntu-latest
- name: Build and Deploy
- permissions:
- contents: write
- outputs:
- tag: ${{ steps.generate_release_tag.outputs.next_release_tag }}
- release_url: ${{ steps.create_release.outputs.html_url }}
- steps:
- # - name: Generate release tag
- # id: generate_release_tag
- # uses: amitsingh-007/next-release-tag@v6.0.0
- # with:
- # github_token: ${{ secrets.GITHUB_TOKEN }}
- # tag_prefix: "v"
- # tag_template: "yyyy.mm.dd.i"
- # - name: Create Release
- # id: create_release
- # uses: actions/create-release@v1
- # env:
- # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- # with:
- # tag_name: ${{ steps.generate_release_tag.outputs.next_release_tag }}
- # release_name: Release ${{ steps.generate_release_tag.outputs.next_release_tag }}
- # draft: false
- # prerelease: false
- # commitish: ${{inputs.ref}}
- # - uses: actions/checkout@v4
- # with:
- # ref: ${{ steps.generate_release_tag.outputs.next_release_tag }}
- # - run: |
- # echo "deploying ref: ${{ inputs.ref }}"
- # echo "tag: ${{ steps.generate_release_tag.outputs.next_release_tag }}"
- # # - run: git rev-parse --abbrev-ref HEAD
- # - name: Use Node.js 20.x
- # uses: actions/setup-node@v4
- # with:
- # node-version: 20
- # cache: "npm"
- # - run: npm i
- # - run: npm run build
- # - name: Archive production artifacts
- # run: |
- # mkdir -p release
- # cp -r dist/* release/
- # tar -czvf release.tar.gz release/
- # - name: Upload Release Asset
- # uses: actions/upload-release-asset@v1
- # env:
- # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- # with:
- # upload_url: ${{ steps.create_release.outputs.upload_url }}
- # asset_path: ./release.tar.gz
- # asset_name: release.tar.gz
- # asset_content_type: application/gzip
- - name: executing remote ssh commands using ssh key
- uses: appleboy/ssh-action@v1.0.3
- with:
- host: ${{ secrets.PROD_SSH_HOST }}
- username: ${{ secrets.PROD_SSH_USER }}
- key: ${{ secrets.PROD_SSH_KEY }}
- port: ${{ secrets.PROD_SSH_PORT }}
- script: |
- whoami
- cd ${{secrets.PROD_SSH_DIR}}
- ls -l
- # - name: Publish with rsync
- # uses: GuillaumeFalourd/setup-rsync@v1.2
- # id: rsync
- # with:
- # ssh_key: ${{ secrets.PROD_SSH_KEY }}
- # - 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 }}
- # notify:
- # runs-on: ubuntu-latest
- # name: Notify deploy status
- # needs: build
- # steps:
- - name: Feishu notify deploy status
- if: ${{needs.build.result == 'success' || needs.build.result == 'failure'}}
- uses: wangsijie/feishu-bot@v1
- with:
- uuid: ${{secrets.FEISHU_CICD_BOT_ID}}
- data: |
- {
- "msg_type": "interactive",
- "card": {
- "elements": [
- {
- "tag": "div",
- "text": {
- "content": "**项目**: 知识建构",
- "tag": "lark_md"
- }
- },
- {
- "tag": "div",
- "text": {
- "content": "**环境**: PROD",
- "tag": "lark_md"
- }
- },
- {
- "tag": "div",
- "text": {
- "content": "**结果**: ${{needs.build.result == 'failure' && '❌' || '✅'}}",
- "tag": "lark_md"
- }
- },
- {
- "tag": "div",
- "text": {
- "content": "**Tag**: ${{needs.build.outputs.tag}}",
- "tag": "lark_md"
- }
- },
- {
- "actions": [{
- "tag": "button",
- "text": {
- "content": "查看过程",
- "tag": "lark_md"
- },
- "url": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}",
- "type": "default",
- "value": {}
- }, {
- "tag": "button",
- "text": {
- "content": "查看Release",
- "tag": "lark_md"
- },
- "url": "${{ needs.build.outputs.release_url }}",
- "type": "default",
- "value": {}
- }],
- "tag": "action"
- }
- ],
- "header": {
- "title": {
- "content": "部署结果通知",
- "tag": "plain_text"
- }
- }
- }
- }
|