From 0ca7785cdf8d547cca94e274b18d52c5942b7963 Mon Sep 17 00:00:00 2001 From: xiaofangqing Date: Fri, 20 Mar 2026 09:29:11 +0800 Subject: [PATCH] =?UTF-8?q?ci:=20=E9=87=8D=E6=9E=84=E9=83=A8=E7=BD=B2?= =?UTF-8?q?=E5=B7=A5=E4=BD=9C=E6=B5=81=E5=B9=B6=E6=B7=BB=E5=8A=A0=E4=BC=81?= =?UTF-8?q?=E4=B8=9A=E5=BE=AE=E4=BF=A1=E9=80=9A=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/deploy.yml | 172 ++++++++++++++++++++++++++++++++---- 1 file changed, 155 insertions(+), 17 deletions(-) diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml index 27aa77c..0775122 100644 --- a/.gitea/workflows/deploy.yml +++ b/.gitea/workflows/deploy.yml @@ -1,31 +1,169 @@ -# .gitea/workflows/deploy.yml -name: deploy demo +name: deploy & notify on: push: - branches: - - "main" # 针对 main 分支 - paths: - - ".gitea/workflows/*" # 表示推送到main分支 并且以下文件进行了修改才会执行 - - "src/**" - - "package.json" + branches: [main] jobs: - deploy: + build: runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 # 第三方的 action + # ---------- 设置安全 commit message ---------- + - name: 设置安全 commit message + run: | + MSG="${{ github.event.head_commit.message }}" + SAFE_COMMIT=$(echo "$MSG" | tr -d '\r\n') + if [ -z "$SAFE_COMMIT" ]; then + SAFE_COMMIT="${{ github.actor }}触发了Git构建" + fi + echo "SAFE_COMMIT=$SAFE_COMMIT" >> $GITHUB_ENV - - name: create a folder # 创建文件夹 + # ---------- 开始构建通知 ---------- + - name: 设置开始时间 + run: | + START_TIME=$(TZ='Asia/Shanghai' date '+%Y-%m-%d %H:%M:%S') + echo "START_TIME=$START_TIME" >> $GITHUB_ENV + + - name: 通知-构建开始 + uses: https://gitea.com/seepine/action-wechat-work.git@v1.0.8 + env: + WECHAT_WORK_BOT_WEBHOOK: ${{ secrets.WECOM_WEBHOOK_KEY }} + with: + msgtype: template_card + template_card: | + { + "card_type": "text_notice", + "source": { + "icon_url": "https://gitea.com/assets/img/favicon.png", + "desc": "Gitea Actions", + "desc_color": 0 + }, + "main_title": { + "title": "${{ github.repository }}" + }, + "emphasis_content": { + "title": "running", + "desc": "BUILD_RUNNING" + }, + "quote_area": { + "quote_text": "${{ env.SAFE_COMMIT }}" + }, + "sub_title_text": "[${{ github.ref_name }}] 分支开始构建", + "horizontal_content_list": [ + {"keyname": "构建编号", "value": "#${{ github.run_number }}"}, + {"keyname": "构建分支", "value": "${{ github.ref_name }}"}, + {"keyname": "触发用户", "value": "${{ github.actor }}"}, + {"keyname": "触发时间", "value": "${{ env.START_TIME }}"} + ], + "card_action": { + "type": 1, + "url": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" + } + } + + # ---------- 检出 + 你的构建步骤 ---------- + - name: 开始构建 + uses: actions/checkout@v3 + + - name: create a folder run: mkdir test-folder - - name: create a file # 创建一个文件 - run: | # 这样下面就可以执行多行 + - name: create a file + run: | cd test-folder touch a.txt - echo "hello world " > a.txt + echo "hello Gitea" > a.txt cat a.txt - - name: delete a file # 删除文件 - run: rm -rf a.txt + - name: delete a file + run: rm -rf test-folder/a.txt + + # ---------- 构建成功通知 ---------- + - name: 设置完成时间 + if: ${{ success() }} + run: | + FINISHED_TIME=$(TZ='Asia/Shanghai' date '+%Y-%m-%d %H:%M:%S') + echo "FINISHED_TIME=$FINISHED_TIME" >> $GITHUB_ENV + + - name: 通知-构建成功 + if: ${{ success() }} + uses: https://gitea.com/seepine/action-wechat-work.git@v1.0.8 + env: + WECHAT_WORK_BOT_WEBHOOK: ${{ secrets.WECOM_WEBHOOK_KEY }} + with: + msgtype: template_card + template_card: | + { + "card_type": "text_notice", + "source": { + "icon_url": "https://gitea.com/assets/img/favicon.png", + "desc": "Gitea Actions", + "desc_color": 0 + }, + "main_title": { + "title": "${{ github.repository }}" + }, + "emphasis_content": { + "title": "success", + "desc": "BUILD_SUCCESS" + }, + "quote_area": { + "quote_text": "${{ env.SAFE_COMMIT }}" + }, + "sub_title_text": "[${{ github.ref_name }}] 分支构建成功", + "horizontal_content_list": [ + {"keyname": "构建编号", "value": "#${{ github.run_number }}"}, + {"keyname": "构建分支", "value": "${{ github.ref_name }}"}, + {"keyname": "触发用户", "value": "${{ github.actor }}"}, + {"keyname": "完成时间", "value": "${{ env.FINISHED_TIME }}"} + ], + "card_action": { + "type": 1, + "url": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" + } + } + + # ---------- 构建失败通知 ---------- + - name: 设置失败时间 + if: ${{ failure() }} + run: | + FAILED_TIME=$(TZ='Asia/Shanghai' date '+%Y-%m-%d %H:%M:%S') + echo "FAILED_TIME=$FAILED_TIME" >> $GITHUB_ENV + + - name: 通知-构建失败 + if: ${{ failure() }} + uses: https://gitea.com/seepine/action-wechat-work.git@v1.0.8 + env: + WECHAT_WORK_BOT_WEBHOOK: ${{ secrets.WECOM_WEBHOOK_KEY }} + with: + msgtype: template_card + template_card: | + { + "card_type": "text_notice", + "source": { + "icon_url": "https://gitea.com/assets/img/favicon.png", + "desc": "Gitea Actions", + "desc_color": 0 + }, + "main_title": { + "title": "${{ github.repository }}" + }, + "emphasis_content": { + "title": "failed", + "desc": "BUILD_FAILED" + }, + "quote_area": { + "quote_text": "${{ env.SAFE_COMMIT }}" + }, + "sub_title_text": "[${{ github.ref_name }}] 分支构建失败", + "horizontal_content_list": [ + {"keyname": "构建编号", "value": "#${{ github.run_number }}"}, + {"keyname": "构建分支", "value": "${{ github.ref_name }}"}, + {"keyname": "触发用户", "value": "${{ github.actor }}"}, + {"keyname": "完成时间", "value": "${{ env.FAILED_TIME}}"} + ], + "card_action": { + "type": 1, + "url": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" + } + }