Files
test-1/.gitea/workflows/deploy.yml
xiaofangqing 619597a7d4
Some checks failed
deploy & notify / build (push) Failing after 34s
ci: 更新微信工作通知Action的版本引用格式
2026-03-20 09:35:31 +08:00

170 lines
6.1 KiB
YAML

name: deploy & notify
on:
push:
branches: [main]
jobs:
build:
runs-on: ubuntu-latest
steps:
# ---------- 设置安全 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: 设置开始时间
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@1.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: |
cd test-folder
touch a.txt
echo "hello Gitea" > a.txt
cat 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@1.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@1.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 }}"
}
}