forked from zhongfly/now-subconverter
-
Notifications
You must be signed in to change notification settings - Fork 0
174 lines (164 loc) · 6.12 KB
/
main.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
name: Update subconverter
# 默认设置,在定时任务中使用
env:
# 提交说明的内容
message: 'Update subconverter'
# 从何处更新subconverter
# release 从release中下载稳定版,可用下面的tag参数指定版本
# build 拉取最新代码自行编译
# action 从最新commit所关联github action处下载
branch: 'action'
# 当branch参数设置为release时,下载指定版本的release
# 设置为latest时,自动选择最新版本release
tag: 'latest'
# 自定义配置文件的方法
# sed 在Modify pref.ini by sed步骤中,用sed命令修改配置文件
# files 使用本项目中/files文件夹中的所有文件
modify_method: 'files'
on:
# 定时任务,格式:minute(0 - 59) hour(0 - 23) day_of_the month (1 - 31) month(1 - 12 or JAN-DEC) day of the week (0 - 6 or SUN-SAT)
# 以下示例为每周日0点0分运行
# 删除以下行首的#号启用定时任务
# schedule:
# - cron: 0 0 * * SUN
# 点击star运行
# 删除以下行首的#号启用
#watch:
# types: [started]
workflow_dispatch:
inputs:
message:
description: 'commit message'
required: false
default: 'Update subconverter'
branch:
description: 'update subconverter from where?(action/build/release)'
required: false
default: 'action'
tag:
description: 'specific version tag if branch is "release"'
required: false
default: 'latest'
modify_method:
description: 'modify configuration file by sed or /files'
required: false
default: 'sed'
concurrency:
group: subconverter
# 自动取消其他运行中的workflow
cancel-in-progress: true
jobs:
Build:
name: Fetch and Update
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: variable mapper
id: export
uses: kanga333/variable-mapper@v0.2.2
with:
key: "${{ github.event_name }}"
map: |
{
"workflow_dispatch": {
"message": "${{ github.event.inputs.message }}",
"branch": "${{ github.event.inputs.branch }}",
"tag": "${{ github.event.inputs.tag }}",
"modify_method": "${{ github.event.inputs.modify_method }}"
},
".*": {
"message": "${{ env.message }}",
"branch": "${{ env.branch }}",
"tag": "${{ env.tag }}",
"modify_method": "${{ env.modify_method }}"
}
}
export_to: output,env
- name: '[action]Get latest commit sha'
if: ${{ env.branch == 'action' }}
id: get_sha
uses: mego22/actions-git-sha@main
with:
repo: "https://github.com/tindy2013/subconverter.git"
- name: '[action]Wait for build to succeed'
if: ${{ env.branch == 'action' }}
uses: fountainhead/action-wait-for-check@v1.0.0
id: wait
with:
token: ${{ secrets.GITHUB_TOKEN }}
checkName: "Linux x86_64 Build"
ref: ${{ steps.get_sha.outputs.sha }}
repo: subconverter
owner: tindy2013
intervalSeconds: 30
- name: '[action]Download artifact'
if: ${{ env.branch == 'action' && steps.wait.outputs.conclusion == 'success' }}
uses: dawidd6/action-download-artifact@v2
with:
workflow: build.yml
commit: ${{ steps.get_sha.outputs.sha }}
name: subconverter_linux64
path: /tmp/subconverter
repo: tindy2013/subconverter
- name: '[action]Clean up'
if: ${{ env.branch == 'action' }}
run: |
sudo rm -rf subconverter
mv -f /tmp/subconverter subconverter
mv -f subconverter/subconverter subconverter/subconverter.exe
sudo chmod +x subconverter/subconverter.exe
- name: '[build]Prepare'
if: ${{ env.branch == 'build' }}
run: |
cd /tmp
git clone https://github.com/tindy2013/subconverter.git
- name: '[build]Build'
if: ${{ env.branch == 'build' }}
run: docker run -v /tmp/subconverter:/root/workdir multiarch/alpine:amd64-latest-stable /bin/sh -c "apk add bash git nodejs npm && cd /root/workdir && chmod +x scripts/build.alpine.release.sh && bash scripts/build.alpine.release.sh"
- name: '[build]Clean up'
if: ${{ env.branch == 'build' }}
run: |
sudo rm -rf subconverter
mv -f /tmp/subconverter/subconverter subconverter
mv -f subconverter/subconverter subconverter/subconverter.exe
sudo chmod +x subconverter/subconverter.exe
- name: '[release]Download from release'
if: ${{ env.branch == 'release' }}
uses: i3h/download-release-asset@v1
with:
owner: tindy2013
repo: subconverter
tag: ${{ env.tag }}
file: "subconverter_linux64.tar.gz"
- name: '[release]extract release'
if: ${{ env.branch == 'release' }}
run: |
sudo rm -rf subconverter/*
tar -xzf subconverter_linux64.tar.gz -C ./
sudo rm -f subconverter_linux64.tar.gz
mv -f subconverter/subconverter subconverter/subconverter.exe
sudo chmod +x subconverter/subconverter.exe
- name: Modify pref.ini by sed
if: ${{ env.modify_method == 'sed' }}
run: |
if [ -e subconverter/pref.example.ini ]; then
cp -f subconverter/pref.example.ini subconverter/pref.ini
fi
sed -i 's/api_mode=false/api_mode=true/g' subconverter/pref.ini
sed -i 's/managed_config_prefix=http:\/\/127.0.0.1:25500/managed_config_prefix=https:\/\/sub.tgchuichui.xyz/g' subconverter/pref.ini
sed -i 's/async_fetch_ruleset=false/async_fetch_ruleset=true/g' subconverter/pref.ini
sed -i 's/max_concurrent_threads=./max_concurrent_threads=1/g' subconverter/pref.ini
- name: Modify pref.ini by files
if: ${{ env.modify_method == 'files' }}
run: |
sudo cp -rf files/* subconverter/
- name: Add & Commit
uses: EndBug/add-and-commit@v6
with:
author_name: GitHub Action
author_email: noreply@github.com
message: ${{ env.message }}
add: "-A"
env:
token: ${{ secrets.GITHUB_TOKEN }}