Skip to content

Commit

Permalink
update auto sync script
Browse files Browse the repository at this point in the history
  • Loading branch information
zizdlp committed Aug 30, 2024
1 parent a819bd7 commit 83f902b
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 8 deletions.
31 changes: 27 additions & 4 deletions Features/Synchronization.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,49 @@ To configure GitHub Actions for ZBook repositories, you need to create a YAML fi
Create a file named `.github/workflows/main.yml` in the root directory of your ZBook repository. This file will contain the GitHub Actions configuration.

```yaml
name: auto_sync
name: Auto Sync

on:
push:
branches:
- main

jobs:
auto_sync:
runs-on: ubuntu-latest
steps:
- name: Deploy Stage
run: |
curl -X POST ${{ secrets.ZBOOK_URI }} \
# Enable error handling
set -e
# Execute the API request and capture the response
RESPONSE=$(curl -X POST ${{ secrets.ZBOOK_URI }} \
-H 'Content-Type: application/json' \
-d '{
"repo_name": "${{ secrets.ZBOOK_REPO_NAME }}",
"username": "${{ secrets.ZBOOK_USERNAME }}",
"sync_token": "${{ secrets.ZBOOK_SYNC_TOKEN }}"
}' \
--max-time 600 # Set the maximum timeout to 600 seconds
}' --max-time 600)
# Output the response content
echo "Response: $RESPONSE"
# Check if the response is empty
if [ -z "$RESPONSE" ]; then
echo "Error: Empty response from API"
exit 1
fi
# Check if the response contains the expected status code or key fields
STATUS_CODE=$(echo "$RESPONSE" | grep -oP '(?<="status":)\d+' || echo "200")
if [ "$STATUS_CODE" -ne 200 ]; then
echo "Error: API request failed with status code $STATUS_CODE"
exit 1
fi
echo "API request successful."
```
In the GitHub repository's Secrets, you need to configure the following variables:
Expand Down
31 changes: 27 additions & 4 deletions 功能/同步.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,49 @@ ZBook 仓库可以配置手动同步或者自动同步,对于手动同步,
在 ZBook 仓库的根目录下创建一个文件路径 .github/workflows/main.yml,这个文件将包含 GitHub Actions 的配置。

```yaml
name: auto_sync
name: Auto Sync

on:
push:
branches:
- main

jobs:
auto_sync:
runs-on: ubuntu-latest
steps:
- name: Deploy Stage
run: |
curl -X POST ${{ secrets.ZBOOK_URI }} \
# 启用错误处理
set -e
# 执行 API 请求并捕获响应
RESPONSE=$(curl -X POST ${{ secrets.ZBOOK_URI }} \
-H 'Content-Type: application/json' \
-d '{
"repo_name": "${{ secrets.ZBOOK_REPO_NAME }}",
"username": "${{ secrets.ZBOOK_USERNAME }}",
"sync_token": "${{ secrets.ZBOOK_SYNC_TOKEN }}"
}' \
--max-time 600 # 设置最大超时时间为600秒
}' --max-time 600)
# 输出响应内容
echo "Response: $RESPONSE"
# 检查响应内容是否为空
if [ -z "$RESPONSE" ]; then
echo "Error: Empty response from API"
exit 1
fi
# 检查响应中是否包含预期的内容(例如状态码或关键字段)
STATUS_CODE=$(echo "$RESPONSE" | grep -oP '(?<="status":)\d+' || echo "200")
if [ "$STATUS_CODE" -ne 200 ]; then
echo "Error: API request failed with status code $STATUS_CODE"
exit 1
fi
echo "API request successful."
```
在 GitHub 仓库的 Secrets 中,需要提前配置以下变量:
Expand Down

0 comments on commit 83f902b

Please sign in to comment.