-
Notifications
You must be signed in to change notification settings - Fork 6
99 lines (86 loc) · 3.8 KB
/
Release_ADblock_File.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
name: Release_ADblock_File
on:
schedule:
- cron: '*/20 * * * *' # 每20分钟运行一次
workflow_dispatch: # 允许手动触发工作流
jobs:
create-release:
runs-on: ubuntu-latest
steps:
# 步骤0:清除之前的日志文件
- name: Clear previous logs
run: |
sudo rm -rf /home/runner/runners/*/_diag/*.log || true
# 步骤1:检出代码
- name: Checkout code
uses: actions/checkout@v3
# 步骤2:获取当前时间
- name: Get current time
id: current-time
run: echo "time=$(date +'%y%m%d%H%M')" >> $GITHUB_ENV # 将时间保存为环境变量
# 步骤3:更新时间戳文件
- name: Update timestamp file
run: echo "${{ env.time }}" > timestamp.txt # 将时间写入 timestamp.txt 文件
# 步骤4:拉取最新的 main 分支并合并(失败则跳过)
- name: Pull and merge latest main
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git fetch origin main
git merge origin/main --no-edit || echo "Merge failed, skipping merge"
env:
TOKEN: ${{ secrets.TOKEN }} # 使用存储在仓库密钥中的 TOKEN
# 步骤5:强制添加、提交并推送更改
- name: Force add and commit changes
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git add -f adblock_reject.srs adblock_reject_domain.txt adblock_reject.json timestamp.txt
git commit -m "Forced update of adblock files and timestamp" || echo "No changes to commit"
git push origin main --force || echo "Push failed but continuing"
env:
TOKEN: ${{ secrets.TOKEN }} # 使用存储在仓库密钥中的 TOKEN
# 步骤6:创建新的发布
- name: Get current timestamp
id: get_timestamp
run: echo "time=$(date +%s)" >> $GITHUB_ENV # 获取当前时间的 UNIX 时间戳并存储在 GITHUB_ENV 中
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.TOKEN }} # 使用 TOKEN 进行身份验证
with:
tag_name: release-${{ env.time }} # 使用时间戳作为标签名
release_name: Release ${{ env.time }} # 使用时间戳作为发布名称
body: "Periodic release of adblock files." # 发布说明
draft: false # 创建正式发布,而非草稿
# 步骤7:上传 adblock_reject.srs
- name: Upload adblock_reject.srs
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./adblock_reject.srs
asset_name: adblock_reject.srs
asset_content_type: text/plain
# 步骤8:上传 adblock_reject_domain.txt
- name: Upload adblock_reject_domain.txt
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./adblock_reject_domain.txt
asset_name: adblock_reject_domain.txt
asset_content_type: text/plain
# 步骤9:上传 adblock_reject.json
- name: Upload adblock_reject.json
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./adblock_reject.json
asset_name: adblock_reject.json
asset_content_type: application/json