-
Notifications
You must be signed in to change notification settings - Fork 0
216 lines (190 loc) · 9.46 KB
/
ci.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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
name: Automatic core compression
on:
schedule:
- cron: 0 7,15,23 * * *
workflow_dispatch:
inputs:
force:
type: boolean
push:
branches:
- main
paths:
- .github/workflows/ci.yml
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
download_tag: Prerelease-Alpha
download_version: ''
download_name: mihomo
download_url: https://github.com/MetaCubeX/mihomo/releases
jobs:
Core:
runs-on: ubuntu-latest
outputs:
cancel: ${{ steps.check.outputs.cancel }}
download_version: ${{ steps.check.outputs.download_version }}
strategy:
matrix:
include:
# - { os: darwin, arch: arm64, rname: '' }
# - { os: darwin, arch: amd64-compatible, rname: '' }
# - { os: darwin, arch: amd64, rname: '' }
# - { os: linux, arch: '386', rname: '' }
- { os: linux, arch: amd64-compatible, rname: '' }
- { os: linux, arch: amd64, rname: '' }
- { os: linux, arch: arm64, rname: '' }
# - { os: linux, arch: armv5, rname: '' }
# - { os: linux, arch: armv6, rname: '' }
- { os: linux, arch: armv7, rname: '' }
# - { os: linux, arch: mips-hardfloat, rname: '' }
# - { os: linux, arch: mips-softfloat, rname: '' }
# - { os: linux, arch: mipsle-hardfloat, rname: '' }
# - { os: linux, arch: mipsle-softfloat, rname: '' }
# - { os: linux, arch: mips64, rname: '' }
# - { os: linux, arch: mips64le, rname: '' }
# - { os: linux, arch: loong64-abi1, rname: '' }
# - { os: linux, arch: loong64-abi2, rname: '' }
# - { os: linux, arch: riscv64, rname: '' }
# - { os: linux, arch: s390x, rname: '' }
# - { os: windows, arch: '386', rname: '' }
- { os: windows, arch: amd64-compatible, rname: '' }
- { os: windows, arch: amd64, rname: '' }
# - { os: windows, arch: armv7, rname: '' }
# - { os: windows, arch: arm64, rname: '' }
# - { os: freebsd, arch: '386', rname: '' }
# - { os: freebsd, arch: amd64-compatible, rname: '' }
# - { os: freebsd, arch: amd64, rname: '' }
# - { os: freebsd, arch: arm64, rname: '' }
# - { os: android, arch: '386', rname: '' }
# - { os: android, arch: amd64, rname: '' }
# - { os: android, arch: armv7, rname: '' }
- { os: android, arch: arm64-v8, rname: 'arm64' }
# https://github.com/MetaCubeX/mihomo/blob/Alpha/.github/workflows/build.yml#L32-L68
# Go 1.22 with special patch can work on Windows 7
# https://github.com/MetaCubeX/go/commits/release-branch.go1.22/
# - { os: windows, arch: '386-go122', rname: '' }
# - { os: windows, arch: amd64-compatible-go122, rname: '' }
# - { os: windows, arch: amd64-go122, rname: '' }
# Go 1.21 can revert commit `9e4385` to work on Windows 7
# https://github.com/golang/go/issues/64622#issuecomment-1847475161
# (OR we can just use golang1.21.4 which unneeded any patch)
# - { os: windows, arch: '386-go121', rname: '' }
# - { os: windows, arch: amd64-compatible-go121, rname: '' }
# - { os: windows, arch: amd64-go121, rname: '' }
# Go 1.20 is the last release that will run on any release of Windows 7, 8, Server 2008 and Server 2012. Go 1.21 will require at least Windows 10 or Server 2016.
# - { os: windows, arch: '386-go120', rname: '' }
# - { os: windows, arch: amd64-compatible-go120, rname: '' }
# - { os: windows, arch: amd64-go120, rname: '' }
# Go 1.22 is the last release that will run on macOS 10.15 Catalina. Go 1.23 will require macOS 11 Big Sur or later.
# - { os: darwin, arch: arm64-go122, rname: '' }
# - { os: darwin, arch: amd64-compatible-go122, rname: '' }
# - { os: darwin, arch: amd64-go122, rname: '' }
# Go 1.20 is the last release that will run on macOS 10.13 High Sierra or 10.14 Mojave. Go 1.21 will require macOS 10.15 Catalina or later.
# - { os: darwin, arch: arm64-go120, rname: '' }
# - { os: darwin, arch: amd64-compatible-go120, rname: '' }
# - { os: darwin, arch: amd64-go120, rname: '' }
# only for test
# - { os: linux, arch: '386-go120', rname: '' }
# - { os: linux, arch: amd64-compatible-go120, rname: '' }
# - { os: linux, arch: amd64-go120, rname: '' }
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Get version
id: check
run: |
if [ "${download_tag}" = "Prerelease-Alpha" ];then
download_version=$(curl -sSL ${download_url}/download/${download_tag}/version.txt)
elif [ "${download_tag}" = "latest" ];then
download_version=$(curl -sSL ${download_url}/${download_tag}/download/version.txt)
else
download_version=${download_tag}
fi
echo "download_version=${download_version}" >> $GITHUB_OUTPUT
echo "download_version=${download_version}" >> $GITHUB_ENV
if [ "${{ inputs.force }}" != 'true' ] && [ "$(curl -sSL -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" https://api.github.com/repos/lolion1y/ci4core/releases/latest | awk -F'=| ' '/body/ {print $5}')" = "${download_version}" ];then
echo "cancel=true" >> $GITHUB_OUTPUT
echo "cancel=true" >> $GITHUB_ENV
fi
- name: Download upx
if: env.cancel == ''
run: |
upx_version=$(curl -sSL -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" https://api.github.com/repos/upx/upx/releases/latest | awk -F'"|v' '/tag_name/ {print $5}')
echo "upx_version=${upx_version}" >> $GITHUB_ENV
wget https://github.com/upx/upx/releases/latest/download/upx-${upx_version}-amd64_linux.tar.xz -O - | tar -Jx
# wget https://github.com/lolion1y/ci4core/raw/upx/upx-3.93-amd64_linux.tar.xz -O - | tar -Jx
- name: Download and compress core
if: env.cancel == ''
run: |
mkdir -p publish
if [ "${{ matrix.os }}" = "windows" ]; then
wget ${download_url}/download/${download_tag}/${download_name}-${{ matrix.os }}-${{ matrix.arch }}-${download_version}.zip
unzip -o ${download_name}-${{ matrix.os }}-${{ matrix.arch }}-${download_version}.zip
mv ${download_name}-${{ matrix.os }}-${{ matrix.arch }}.exe ./publish/clash.meta-${{ matrix.os }}-${{ matrix.arch }}.exe
chmod +x ./publish/clash.meta-${{ matrix.os }}-${{ matrix.arch }}.exe
./upx-${upx_version}-amd64_linux/upx ./publish/clash.meta-${{ matrix.os }}-${{ matrix.arch }}.exe
if [ "${{ matrix.rname }}" != '' ];then
mv ./publish/clash.meta-${{ matrix.os }}-${{ matrix.arch }}.exe ./publish/clash.meta-${{ matrix.os }}-${{ matrix.rname }}.exe
fi
else
wget ${download_url}/download/${download_tag}/${download_name}-${{ matrix.os }}-${{ matrix.arch }}-${download_version}.gz -O - | gzip -dc > ./publish/clash.meta-${{ matrix.os }}-${{ matrix.arch }}
chmod +x ./publish/clash.meta-${{ matrix.os }}-${{ matrix.arch }}
if [ "${{ matrix.arch }}" != "armv5" ];then
if [ "${{ matrix.arch }}" = "mips*" ];then
./upx-3.93-amd64_linux/upx ./publish/clash.meta-${{ matrix.os }}-${{ matrix.arch }}
else
./upx-${upx_version}-amd64_linux/upx ./publish/clash.meta-${{ matrix.os }}-${{ matrix.arch }}
fi
fi
if [ "${{ matrix.rname }}" != '' ];then
mv ./publish/clash.meta-${{ matrix.os }}-${{ matrix.arch }} ./publish/clash.meta-${{ matrix.os }}-${{ matrix.rname }}
fi
fi
- name: Archive production artifacts
if: env.cancel == ''
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.os }}-${{ matrix.arch }}
path: ./publish/*
Release:
needs: [Core]
if: needs.Core.outputs.cancel == ''
env:
download_version: ${{ needs.Core.outputs.download_version }}
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v4
with:
path: publish
merge-multiple: true
- name: Generate body.txt
run: echo -n "Core=${download_version} Time=`TZ='Asia/Shanghai' date "+%F %R %z"`" > body.txt
- name: Display structure of downloaded files
run: ls -R
working-directory: publish
- name: Git push assets to "release" branch
run: |
cd publish || exit 1
git init
git config --local user.name "github-actions[bot]"
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
git checkout -b release
git add .
git commit -m release
git remote add origin "https://${{ github.actor }}:${{ secrets.github_token }}@github.com/${{ github.repository }}"
git push -f -u origin release
- name: Delete current release assets
uses: andreaswilli/[email protected]
with:
github_token: ${{ secrets.github_token }}
tag: latest
deleteOnlyFromDrafts: false
- name: Upload Release
uses: softprops/[email protected]
with:
tag_name: latest
files: ./publish/*
generate_release_notes: true
body_path: body.txt