Skip to content

Commit 9bf5cce

Browse files
committed
workflow: update compile action
1 parent 184daeb commit 9bf5cce

1 file changed

Lines changed: 113 additions & 180 deletions

File tree

.github/workflows/compile_meta_core.yml

Lines changed: 113 additions & 180 deletions
Original file line numberDiff line numberDiff line change
@@ -52,217 +52,150 @@ jobs:
5252
echo "upstream_smart_id=alpha-smart-g$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
5353
echo "upstream_smart_id: alpha-smart-g$(git rev-parse --short HEAD)"
5454
55-
Compile_Meta_Core:
55+
Compile_Core:
5656
runs-on: ubuntu-latest
5757
needs: Get-Commit-id
58-
if: ${{ needs.Get-Commit-id.outputs.current_id != needs.Get-Commit-id.outputs.upstream_id }}
58+
if: ${{ needs.Get-Commit-id.outputs.current_id != needs.Get-Commit-id.outputs.upstream_id || needs.Get-Commit-id.outputs.current_smart_id != needs.Get-Commit-id.outputs.upstream_smart_id }}
5959
strategy:
6060
matrix:
61-
arch: [normal, loongarch_abi1]
61+
core:
62+
- { type: meta, repo: MetaCubeX/mihomo, src: metacubex_src, version_prefix: alpha-g, artifact: meta-core, goversion: '1.26' }
63+
- { type: smart, repo: vernesong/mihomo, src: vernesong_src, version_prefix: alpha-smart-g, artifact: smart-core, goversion: '1.26' }
64+
jobs:
65+
- { goos: linux, goarch: '386', output: '386', upxflag: '--lzma --best' }
66+
- { goos: linux, goarch: amd64, goamd64: v1, output: amd64-compatible, upxflag: '--lzma --best' }
67+
- { goos: linux, goarch: amd64, goamd64: v3, output: amd64, upxflag: '--lzma --best' }
68+
- { goos: linux, goarch: amd64, goamd64: v1, output: amd64-v1, upxflag: '--lzma --best' }
69+
- { goos: linux, goarch: amd64, goamd64: v2, output: amd64-v2, upxflag: '--lzma --best' }
70+
- { goos: linux, goarch: amd64, goamd64: v3, output: amd64-v3, upxflag: '--lzma --best' }
71+
- { goos: linux, goarch: arm, goarm: '5', output: armv5, upxflag: '--lzma --best' }
72+
- { goos: linux, goarch: arm, goarm: '6', output: armv6, upxflag: '--lzma --best' }
73+
- { goos: linux, goarch: arm, goarm: '7', output: armv7, upxflag: '--lzma --best' }
74+
- { goos: linux, goarch: arm64, output: arm64, upxflag: '--lzma --best' }
75+
- { goos: linux, goarch: mips, gomips: softfloat, output: mips-softfloat, upxflag: '--lzma --best' }
76+
- { goos: linux, goarch: mips, gomips: hardfloat, output: mips-hardfloat, upxflag: '--lzma --best' }
77+
- { goos: linux, goarch: mipsle, gomips: softfloat, output: mipsle-softfloat, upxflag: '--best' }
78+
- { goos: linux, goarch: mipsle, gomips: hardfloat, output: mipsle-hardfloat, upxflag: '--best' }
79+
- { goos: linux, goarch: mips64, output: mips64, upxflag: '--lzma --best' }
80+
- { goos: linux, goarch: mips64le, output: mips64le, upxflag: '--lzma --best' }
81+
- { goos: linux, goarch: riscv64, output: riscv64, upxflag: '--lzma --best' }
82+
- { goos: linux, goarch: s390x, output: s390x, upxflag: '--lzma --best' }
83+
- { goos: linux, goarch: loong64, output: loong64-abi2, upxflag: '--lzma --best' }
84+
- { goos: linux, goarch: loong64, abi: '1', output: loong64-abi1, upxflag: '--lzma --best' }
6285
steps:
63-
- name: Checkout OpenClash Repository
64-
uses: actions/checkout@v6
65-
with:
66-
ref: core
86+
- name: Check if build needed
87+
id: check_skip
88+
run: |
89+
if [ "${{ matrix.core.type }}" = "meta" ] && [ "${{ needs.Get-Commit-id.outputs.current_id }}" = "${{ needs.Get-Commit-id.outputs.upstream_id }}" ]; then
90+
echo "Meta is up to date, skipping build"
91+
echo "skip=true" >> $GITHUB_OUTPUT
92+
elif [ "${{ matrix.core.type }}" = "smart" ] && [ "${{ needs.Get-Commit-id.outputs.current_smart_id }}" = "${{ needs.Get-Commit-id.outputs.upstream_smart_id }}" ]; then
93+
echo "Smart is up to date, skipping build"
94+
echo "skip=true" >> $GITHUB_OUTPUT
95+
else
96+
echo "skip=false" >> $GITHUB_OUTPUT
97+
fi
6798
6899
- name: Apt Update
100+
if: ${{ steps.check_skip.outputs.skip != 'true' }}
69101
env:
70102
DEBIAN_FRONTEND: noninteractive
71103
run: |
72104
sudo apt-get update
73105
sudo apt-get -y install wget git tar
74106
75107
- name: Setup UPX
108+
if: ${{ steps.check_skip.outputs.skip != 'true' }}
76109
run: |
77110
wget https://github.com/upx/upx/releases/download/v3.95/upx-3.95-amd64_linux.tar.xz
78111
tar xf upx-3.95-amd64_linux.tar.xz
79112
echo "upx=${{ github.workspace }}/upx-3.95-amd64_linux/upx" >> $GITHUB_ENV
80113
81-
- name: Prepare Makefiles and Temp Dirs for Meta
82-
run: |
83-
mkdir -p ${{ github.workspace }}/build_temp/meta_makefiles/normal
84-
cp ${{ github.workspace }}/.github/makefile/meta ${{ github.workspace }}/build_temp/meta_makefiles/normal/Makefile
85-
86-
mkdir -p ${{ github.workspace }}/build_temp/meta_makefiles/loong64_abi1
87-
cp ${{ github.workspace }}/.github/makefile/meta_loongarch_abi1 ${{ github.workspace }}/build_temp/meta_makefiles/loong64_abi1/Makefile
88-
89-
mkdir -p ${{ github.workspace }}/build_temp/meta_output/${{ matrix.arch }}/bin
90-
91114
- name: Setup Go
115+
if: ${{ steps.check_skip.outputs.skip != 'true' && !(matrix.jobs.goarch == 'loong64' && matrix.jobs.abi == '1') }}
92116
uses: actions/setup-go@v6
93117
with:
94-
go-version: "1.25"
118+
go-version: ${{ matrix.core.goversion }}
95119
check-latest: true
96120
cache: false
97-
98-
- name: Define Go Archive Directory
99-
id: go_paths
100-
run: |
101-
echo "archive_dir=${{ runner.temp }}/go-archives" >> $GITHUB_OUTPUT
102-
mkdir -p ${{ runner.temp }}/go-archives
103121

104122
- name: Cache Go loongarch abi1 tarball
105123
id: cache_go_abi1
124+
if: ${{ steps.check_skip.outputs.skip != 'true' && matrix.jobs.goarch == 'loong64' && matrix.jobs.abi == '1' }}
106125
uses: actions/cache@v4
107126
with:
108-
path: ${{ steps.go_paths.outputs.archive_dir }}/go1.24.0.linux-amd64-abi1.tar.gz
109-
key: go-loongarch-abi1-1.24.0-${{ matrix.arch }}
110-
restore-keys: |
111-
go-loongarch-abi1-1.24.0-
112-
113-
- name: Clone MetaCubeX/mihomo source
114-
uses: actions/checkout@v6
115-
with:
116-
repository: MetaCubeX/mihomo
117-
ref: Alpha
118-
path: ./metacubex_src
119-
120-
- name: Compile Meta Core for ${{ matrix.arch }}
121-
run: |
122-
set -e
123-
cd ./metacubex_src
124-
GO_ARCHIVE_DIR="${{ steps.go_paths.outputs.archive_dir }}"
125-
126-
case "${{ matrix.arch }}" in
127-
normal)
128-
echo "Using default Go and Makefile"
129-
cp ../build_temp/meta_makefiles/normal/Makefile ./Makefile
130-
;;
131-
loongarch_abi1)
132-
echo "Setup Go for loongarch abi1"
133-
GO_TAR_FILE="go1.24.0.linux-amd64-abi1.tar.gz"
134-
if [[ "${{ steps.cache_go_abi1.outputs.cache-hit }}" != 'true' ]]; then
135-
echo "Cache not found for $GO_TAR_FILE, downloading..."
136-
wget -q "https://github.com/MetaCubeX/loongarch64-golang/releases/download/1.24.0/$GO_TAR_FILE" -O "$GO_ARCHIVE_DIR/$GO_TAR_FILE"
137-
else
138-
echo "Restored $GO_TAR_FILE from cache."
139-
fi
140-
sudo rm -rf /usr/local/go || true
141-
sudo tar zxf "$GO_ARCHIVE_DIR/$GO_TAR_FILE" -C /usr/local
142-
echo "/usr/local/go/bin" >> $GITHUB_PATH
143-
cp ../build_temp/meta_makefiles/loong64_abi1/Makefile ./Makefile
144-
;;
145-
esac
146-
go version
147-
make releases
148-
cp -rf ./bin/. ../build_temp/meta_output/${{ matrix.arch }}/bin/
149-
rm -rf ./bin/*
150-
151-
- name: Upload Meta Core Artifact
152-
uses: actions/upload-artifact@v4
153-
with:
154-
name: meta-core-${{ matrix.arch }}
155-
path: build_temp/meta_output/${{ matrix.arch }}/bin
156-
157-
Compile_Smart_Core:
158-
runs-on: ubuntu-latest
159-
needs: Get-Commit-id
160-
if: ${{ needs.Get-Commit-id.outputs.current_smart_id != needs.Get-Commit-id.outputs.upstream_smart_id }}
161-
strategy:
162-
matrix:
163-
arch: [normal, loongarch_abi1]
164-
steps:
165-
- name: Checkout OpenClash Repository
166-
uses: actions/checkout@v6
167-
with:
168-
ref: core
127+
path: ${{ runner.temp }}/go-archives/go1.26.0.linux-amd64-abi1.tar.gz
128+
key: go-loongarch-abi1-1.26.0
169129

170-
- name: Apt Update
171-
env:
172-
DEBIAN_FRONTEND: noninteractive
173-
run: |
174-
sudo apt-get update
175-
sudo apt-get -y install wget git tar
176-
177-
- name: Setup UPX
178-
run: |
179-
wget https://github.com/upx/upx/releases/download/v3.95/upx-3.95-amd64_linux.tar.xz
180-
tar xf upx-3.95-amd64_linux.tar.xz
181-
echo "upx=${{ github.workspace }}/upx-3.95-amd64_linux/upx" >> $GITHUB_ENV
182-
183-
- name: Prepare Makefiles and Temp Dirs for Smart
130+
- name: Setup Go for loongarch abi1
131+
if: ${{ steps.check_skip.outputs.skip != 'true' && matrix.jobs.goarch == 'loong64' && matrix.jobs.abi == '1' }}
184132
run: |
185-
mkdir -p ${{ github.workspace }}/build_temp/smart_makefiles/normal
186-
cp ${{ github.workspace }}/.github/makefile/meta ${{ github.workspace }}/build_temp/smart_makefiles/normal/Makefile
187-
sed -i 's/VERSION=alpha-g/VERSION=alpha-smart-g/' ${{ github.workspace }}/build_temp/smart_makefiles/normal/Makefile
188-
189-
mkdir -p ${{ github.workspace }}/build_temp/smart_makefiles/loong64_abi1
190-
cp ${{ github.workspace }}/.github/makefile/meta_loongarch_abi1 ${{ github.workspace }}/build_temp/smart_makefiles/loong64_abi1/Makefile
191-
sed -i 's/VERSION=alpha-g/VERSION=alpha-smart-g/' ${{ github.workspace }}/build_temp/smart_makefiles/loong64_abi1/Makefile
192-
193-
mkdir -p ${{ github.workspace }}/build_temp/smart_output/${{ matrix.arch }}/bin
194-
195-
- name: Setup Go
196-
uses: actions/setup-go@v5
197-
with:
198-
go-version: "1.24"
199-
check-latest: true
200-
cache: false
201-
202-
- name: Define Go Archive Directory
203-
id: go_paths
204-
run: |
205-
echo "archive_dir=${{ runner.temp }}/go-archives" >> $GITHUB_OUTPUT
206-
mkdir -p ${{ runner.temp }}/go-archives
207-
208-
- name: Cache Go loongarch abi1 tarball
209-
id: cache_go_abi1
210-
uses: actions/cache@v4
211-
with:
212-
path: ${{ steps.go_paths.outputs.archive_dir }}/go1.24.0.linux-amd64-abi1.tar.gz
213-
key: go-loongarch-abi1-1.24.0-${{ matrix.arch }}
214-
restore-keys: |
215-
go-loongarch-abi1-1.24.0-
133+
GO_TAR_FILE="go1.26.0.linux-amd64-abi1.tar.gz"
134+
GO_ARCHIVE_DIR="${{ runner.temp }}/go-archives"
135+
mkdir -p "$GO_ARCHIVE_DIR"
136+
if [[ "${{ steps.cache_go_abi1.outputs.cache-hit }}" != 'true' ]]; then
137+
echo "Downloading $GO_TAR_FILE..."
138+
wget -q "https://github.com/MetaCubeX/loongarch64-golang/releases/download/1.26.0/$GO_TAR_FILE" \
139+
-O "$GO_ARCHIVE_DIR/$GO_TAR_FILE"
140+
else
141+
echo "Restored $GO_TAR_FILE from cache."
142+
fi
143+
sudo rm -rf /usr/local/go
144+
sudo tar zxf "$GO_ARCHIVE_DIR/$GO_TAR_FILE" -C /usr/local
145+
echo "/usr/local/go/bin" >> $GITHUB_PATH
216146
217-
- name: Clone vernesong/mihomo source
147+
- name: Clone source (${{ matrix.core.type }})
148+
if: ${{ steps.check_skip.outputs.skip != 'true' }}
218149
uses: actions/checkout@v6
219150
with:
220-
repository: vernesong/mihomo
151+
repository: ${{ matrix.core.repo }}
221152
ref: Alpha
222-
path: ./vernesong_src
153+
path: ./${{ matrix.core.src }}
223154

224-
- name: Compile Smart Core for ${{ matrix.arch }}
155+
- name: Build Core (${{ matrix.core.type }}-${{ matrix.jobs.output }})
156+
id: build
157+
if: ${{ steps.check_skip.outputs.skip != 'true' }}
158+
env:
159+
GOOS: ${{ matrix.jobs.goos }}
160+
GOARCH: ${{ matrix.jobs.goarch }}
161+
GOAMD64: ${{ matrix.jobs.goamd64 }}
162+
GOARM: ${{ matrix.jobs.goarm }}
163+
GOMIPS: ${{ matrix.jobs.gomips }}
164+
CGO_ENABLED: 0
225165
run: |
166+
if [ "${{ matrix.core.type }}" = "meta" ] && [ "${{ needs.Get-Commit-id.outputs.current_id }}" = "${{ needs.Get-Commit-id.outputs.upstream_id }}" ]; then
167+
echo "Meta is up to date, skipping build"
168+
echo "skip=true" >> $GITHUB_OUTPUT
169+
exit 0
170+
fi
171+
if [ "${{ matrix.core.type }}" = "smart" ] && [ "${{ needs.Get-Commit-id.outputs.current_smart_id }}" = "${{ needs.Get-Commit-id.outputs.upstream_smart_id }}" ]; then
172+
echo "Smart is up to date, skipping build"
173+
echo "skip=true" >> $GITHUB_OUTPUT
174+
exit 0
175+
fi
226176
set -e
227-
cd ./vernesong_src
228-
GO_ARCHIVE_DIR="${{ steps.go_paths.outputs.archive_dir }}"
229-
230-
case "${{ matrix.arch }}" in
231-
normal)
232-
echo "Using default Go and Makefile"
233-
cp ../build_temp/smart_makefiles/normal/Makefile ./Makefile
234-
;;
235-
loongarch_abi1)
236-
echo "Setup Go for loongarch abi1"
237-
GO_TAR_FILE="go1.24.0.linux-amd64-abi1.tar.gz"
238-
if [ ! -f "$GO_ARCHIVE_DIR/$GO_TAR_FILE" ]; then
239-
echo "CRITICAL: $GO_TAR_FILE not found in $GO_ARCHIVE_DIR. Attempting fallback download."
240-
wget -q "https://github.com/MetaCubeX/loongarch64-golang/releases/download/1.24.0/$GO_TAR_FILE" -O "$GO_ARCHIVE_DIR/$GO_TAR_FILE"
241-
if [ ! -f "$GO_ARCHIVE_DIR/$GO_TAR_FILE" ]; then
242-
echo "ERROR: Fallback download for $GO_TAR_FILE failed. Exiting."
243-
exit 1
244-
fi
245-
fi
246-
sudo rm -rf /usr/local/go || true
247-
sudo tar zxf "$GO_ARCHIVE_DIR/$GO_TAR_FILE" -C /usr/local
248-
echo "/usr/local/go/bin" >> $GITHUB_PATH
249-
cp ../build_temp/smart_makefiles/loong64_abi1/Makefile ./Makefile
250-
;;
251-
esac
252-
go version
253-
make releases
254-
cp -rf ./bin/. ../build_temp/smart_output/${{ matrix.arch }}/bin/
255-
rm -rf ./bin/*
256-
257-
- name: Upload Smart Core Artifact
177+
cd ./${{ matrix.core.src }}
178+
VERSION="${{ matrix.core.version_prefix }}$(git rev-parse --short HEAD)"
179+
BUILDTIME="$(date -u)"
180+
mkdir -p ./bin
181+
go build -tags with_gvisor -trimpath \
182+
-ldflags "-X 'github.com/metacubex/mihomo/constant.Version=${VERSION}' -X 'github.com/metacubex/mihomo/constant.BuildTime=${BUILDTIME}' -w -s -buildid=" \
183+
-o ./bin/clash
184+
chmod +x ./bin/clash
185+
${upx} ${{ matrix.jobs.upxflag }} ./bin/clash || true
186+
mkdir -p ../build_output
187+
tar -zcvf ../build_output/clash-linux-${{ matrix.jobs.output }}.tar.gz -C ./bin clash
188+
189+
- name: Upload Core Artifact (${{ matrix.core.type }}-${{ matrix.jobs.output }})
190+
if: ${{ steps.check_skip.outputs.skip != 'true' }}
258191
uses: actions/upload-artifact@v4
259192
with:
260-
name: smart-core-${{ matrix.arch }}
261-
path: build_temp/smart_output/${{ matrix.arch }}/bin
193+
name: ${{ matrix.core.artifact }}-${{ matrix.jobs.output }}
194+
path: build_output/clash-linux-${{ matrix.jobs.output }}.tar.gz
262195

263196
Publish:
264197
runs-on: ubuntu-latest
265-
needs: [Get-Commit-id, Compile_Meta_Core, Compile_Smart_Core]
198+
needs: [Get-Commit-id, Compile_Core]
266199
if: always() && (needs.Get-Commit-id.outputs.current_id != needs.Get-Commit-id.outputs.upstream_id || needs.Get-Commit-id.outputs.current_smart_id != needs.Get-Commit-id.outputs.upstream_smart_id)
267200
steps:
268201
- name: Checkout OpenClash Repository
@@ -288,12 +221,12 @@ jobs:
288221
289222
if [ "${{ needs.Get-Commit-id.outputs.current_id }}" != "${{ needs.Get-Commit-id.outputs.upstream_id }}" ]; then
290223
echo "Organizing MetaCubeX compiled files..."
291-
if [ "${{ needs.Compile_Meta_Core.result }}" == "success" ] || [ "${{ needs.Compile_Meta_Core.result }}" == "skipped" ]; then
224+
if [ "${{ needs.Compile_Core.result }}" == "success" ]; then
292225
rm -rf ./dev/meta/*
293-
for arch_type in normal loongarch_abi1; do
294-
if [ -d ./downloaded-artifacts/meta-core-$arch_type ] && [ -n "$(ls -A ./downloaded-artifacts/meta-core-$arch_type)" ]; then
295-
echo "Copying meta-core-$arch_type files..."
296-
cp -rf ./downloaded-artifacts/meta-core-$arch_type/. ./dev/meta/
226+
for artifact_dir in ./downloaded-artifacts/meta-core-*/; do
227+
if [ -d "$artifact_dir" ] && [ -n "$(ls -A "$artifact_dir")" ]; then
228+
echo "Copying $artifact_dir files..."
229+
cp -rf "$artifact_dir". ./dev/meta/
297230
changes_made_to_dev_meta=true
298231
fi
299232
done
@@ -302,18 +235,18 @@ jobs:
302235
commit_description="Meta to ${{ needs.Get-Commit-id.outputs.upstream_id }}"
303236
fi
304237
else
305-
echo "Compile_Meta_Core job failed, skipping..."
238+
echo "Compile_Core job failed, skipping meta..."
306239
fi
307240
fi
308241
309242
if [ "${{ needs.Get-Commit-id.outputs.current_smart_id }}" != "${{ needs.Get-Commit-id.outputs.upstream_smart_id }}" ]; then
310243
echo "Organizing vernesong compiled files..."
311-
if [ "${{ needs.Compile_Smart_Core.result }}" == "success" ] || [ "${{ needs.Compile_Smart_Core.result }}" == "skipped" ]; then
244+
if [ "${{ needs.Compile_Core.result }}" == "success" ]; then
312245
rm -rf ./dev/smart/*
313-
for arch_type in normal loongarch_abi1; do
314-
if [ -d ./downloaded-artifacts/smart-core-$arch_type ] && [ -n "$(ls -A ./downloaded-artifacts/smart-core-$arch_type)" ]; then
315-
echo "Copying smart-core-$arch_type files..."
316-
cp -rf ./downloaded-artifacts/smart-core-$arch_type/. ./dev/smart/
246+
for artifact_dir in ./downloaded-artifacts/smart-core-*/; do
247+
if [ -d "$artifact_dir" ] && [ -n "$(ls -A "$artifact_dir")" ]; then
248+
echo "Copying $artifact_dir files..."
249+
cp -rf "$artifact_dir". ./dev/smart/
317250
changes_made_to_dev_smart=true
318251
fi
319252
done
@@ -325,7 +258,7 @@ jobs:
325258
commit_description="${commit_description}Smart to ${{ needs.Get-Commit-id.outputs.upstream_smart_id }}"
326259
fi
327260
else
328-
echo "Compile_Smart_Core job failed, skipping..."
261+
echo "Compile_Core job failed, skipping smart..."
329262
fi
330263
fi
331264

0 commit comments

Comments
 (0)