This commit is contained in:
@@ -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 }}"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user