forked from juewuy/ShellCrash
-
Notifications
You must be signed in to change notification settings - Fork 0
215 lines (199 loc) · 7.21 KB
/
test.yaml
File metadata and controls
215 lines (199 loc) · 7.21 KB
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
name: Test
on:
workflow_dispatch:
inputs:
tag1:
description: 'project name of meta, such as MetaCubeX/mihomo'
required: true
type: string
tag2:
description: 'tag or branches of meta, such as v1.18.0 or Alpha'
required: true
type: string
tag3:
description: 'a new prerelease name (such as clash.meta.alpha) or only upload-artifact'
required: false
type: string
tag4:
description: 'git push as crashcore (such as meta) or only upload-artifact'
required: false
type: string
tag5:
description: 'build tags'
required: false
type: string
jobs:
go:
runs-on: ubuntu-latest
outputs:
version: ${{steps.go.outputs.version}}
steps:
- name: get latest go version
id: go
run: |
echo version=$(curl -s https://raw.githubusercontent.com/actions/go-versions/update-versions-manifest-file/versions-manifest.json | grep -oE '"version": "[0-9]{1}.[0-9]{1,}(.[0-9]{1,})?"' | head -1 | cut -d':' -f2 | sed 's/ //g; s/"//g') >> $GITHUB_OUTPUT
meta:
runs-on: ubuntu-latest
needs: go
env:
REPO: ${{ github.event.inputs.tag1 }}
TAGS: ${{ github.event.inputs.tag5 }}
outputs:
version: ${{steps.meta.outputs.version}}
tags: ${{steps.meta.outputs.tags}}
steps:
- name: get meta version
id: meta
run: |
version=${{ github.event.inputs.tag2 }}
echo version=$version >> $GITHUB_OUTPUT
if [ -z "$TAGS" ];then
echo tags='' >> $GITHUB_OUTPUT
else
echo tags=$TAGS >> $GITHUB_OUTPUT
fi
cross:
strategy:
matrix:
include:
# linux
- name: linux-amd64
goos: linux
goarch: amd64
goamd64: v1
# - name: linux-386
# goos: linux
# goarch: 386
# - name: linux-arm64
# goos: linux
# goarch: arm64
# - name: linux-armv5
# goos: linux
# goarch: arm
# goarm: 5
# - name: linux-armv7
# goos: linux
# goarch: arm
# goarm: 7
# - name: linux-mips-softfloat
# goos: linux
# goarch: mips
# gomips: softfloat
# - name: linux-mipsle-softfloat
# goos: linux
# goarch: mipsle
# gomips: softfloat
# - name: linux-mipsle-hardfloat
# goos: linux
# goarch: mipsle
# gomips: hardfloat
fail-fast: false
runs-on: ubuntu-latest
needs:
- go
- meta
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
GOAMD64: ${{ matrix.goamd64 }}
GOARM: ${{ matrix.goarm }}
GOMIPS: ${{ matrix.gomips }}
CGO_ENABLED: 0
TAGS: ${{needs.meta.outputs.tags}}
VERSION: ${{needs.meta.outputs.version}}
steps:
- name: Checkout meta
uses: actions/checkout@v5
with:
repository: ${{ github.event.inputs.tag1 }}
ref: ${{ github.event.inputs.tag2 }}
fetch-depth: 1
- name: Setup Go
uses: actions/setup-go@v6
with:
go-version: ${{needs.go.outputs.version}}
- name: Set variables
run: |
VERSION="${GITHUB_REF_NAME,,}-$(git rev-parse --short HEAD)"
VERSION="${VERSION//\//-}"
PackageVersion="$(curl -s "https://api.github.com/repos/MetaCubeX/mihomo/releases/latest" | jq -r '.tag_name' | sed 's/v//g' | awk -F '.' '{$NF = $NF + 1; print}' OFS='.').${VERSION/-/.}"
if [ -n "${{ github.event.inputs.version }}" ]; then
VERSION=${{ github.event.inputs.version }}
PackageVersion="${VERSION#v}"
fi
echo "VERSION=${VERSION}" >> $GITHUB_ENV
echo "PackageVersion=${PackageVersion}" >> $GITHUB_ENV
echo "BUILDTIME=$(date)" >> $GITHUB_ENV
echo "CGO_ENABLED=0" >> $GITHUB_ENV
echo "BUILDTAG=-extldflags --static" >> $GITHUB_ENV
echo "GOTOOLCHAIN=local" >> $GITHUB_ENV
- name: Update CA
run: |
sudo apt-get update && sudo apt-get install ca-certificates
sudo update-ca-certificates
cp -f /etc/ssl/certs/ca-certificates.crt component/ca/ca-certificates.crt
- name: build core
id: build
run: |
go env
go build -v -tags "${TAGS}" -o meta -trimpath -ldflags "${BUILDTAG} -X 'github.com/metacubex/mihomo/constant.Version=${VERSION}' -X 'github.com/metacubex/mihomo/constant.BuildTime=${BUILDTIME}' -w -s -buildid="
- name: Upload file to workspace
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.name }}
path: meta
push_to_git:
needs:
- cross
- meta
runs-on: ubuntu-latest
env:
RELEASE: ${{ github.event.inputs.tag3 }}
PUSHDIR: ${{ github.event.inputs.tag4 }}
VERSION: ${{needs.meta.outputs.version}}
steps:
- name: Checkout bin branch (create if missing)
uses: actions/checkout@v5
with:
fetch-depth: 1
ref: update
- name: Download file from workspace
uses: actions/download-artifact@v4
with:
path: ./tmp
- name: Zip core by tar
run: |
for arch in amd64 armv5 armv7 arm64 mips-softfloat mipsle-hardfloat mipsle-softfloat;do
[ ! -f ./tmp/linux-${arch}/meta ] && continue
mv -f ./tmp/linux-${arch}/meta ./tmp/CrashCore
chmod +x ./tmp/CrashCore
tar --no-same-owner -zcvf ./tmp/clash-linux-${arch}.tar.gz -C ./tmp CrashCore
done
- name: Commit and push
if: ${{ env.PUSHDIR != '' }}
run: |
crashcore='meta'
mkdir -p ./bin/${crashcore}
rm -fr ./bin/${crashcore}/*
mv -f ./tmp/clash-linux-*.tar.gz ./bin/${crashcore}/
rm -fr ./tmp
sed -i "s/${crashcore}_v=.*/${crashcore}_v=${VERSION}/" ./bin/version
git config --global user.email "github-actions[bot]@users.noreply.github.com" && git config --global user.name "github-actions[bot]"
git add . && git commit -m "更新${crashcore}内核至${VERSION}" || exit 0
git push
- name: Create Release and Upload Release Asset
if: ${{ env.RELEASE != '' && env.PUSHDIR == '' }}
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ github.event.inputs.tag3 }}
name: ${{ github.event.inputs.tag3 }}
body: "The ${{env.VERSION}} version of ${{ github.event.inputs.tag1 }} \n这是${{ github.event.inputs.tag1 }}的${{env.VERSION}}版本内核文件\nhttps://github.com/${{ github.event.inputs.tag1 }}/releases \nOnly support for ShellCrash\n仅适配ShellCrash项目"
draft: false
prerelease: true
files: |
./tmp/clash*.tar.gz
- name: Cleanup Workflow
uses: Mattraks/delete-workflow-runs@main
with:
retain_days: 1
keep_minimum_runs: 2