1 #56
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build | |
on: | |
workflow_dispatch: | |
push: | |
paths-ignore: | |
- "docs/**" | |
- "README.md" | |
- ".github/ISSUE_TEMPLATE/**" | |
branches: | |
- Alpha | |
tags: | |
- "v*" | |
pull_request_target: | |
branches: | |
- Alpha | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
jobs: | |
# - { goos: darwin, goarch: arm64, output: arm64 } | |
# - { goos: darwin, goarch: amd64, output: amd64 } | |
# - { goos: linux, goarch: '386', output: '386' } | |
# - { goos: linux, goarch: amd64, output: amd64 } | |
- { goos: linux, goarch: amd64, goamd64: v3, output: amd64_v3, cgo: '0' } | |
# - { goos: linux, goarch: arm64, output: arm64 } | |
# - { goos: linux, goarch: arm, goarm: '7', output: armv7 } | |
# - { goos: linux, goarch: mips, mips: hardfloat, output: mips-hardfloat } | |
# - { goos: linux, goarch: mips, mips: softfloat, output: mips-softfloat } | |
# - { goos: linux, goarch: mipsle, mips: hardfloat, output: mipsle-hardfloat } | |
# - { goos: linux, goarch: mipsle, mips: softfloat, output: mipsle-softfloat } | |
# - { goos: linux, goarch: mips64, output: mips64 } | |
# - { goos: linux, goarch: mips64le, output: mips64le } | |
# - { goos: linux, goarch: loong64, output: loong64 } | |
# - { goos: linux, goarch: riscv64, output: riscv64 } | |
# - { goos: linux, goarch: s390x, output: s390x } | |
# - { goos: windows, goarch: '386', output: '386' } | |
# - { goos: windows, goarch: amd64, output: amd64 } | |
# - { goos: windows, goarch: amd64, goamd64: v3, output: amd64_v3 } | |
# - { goos: windows, goarch: '386', output: '386-go120', version: 20 } | |
# - { goos: windows, goarch: amd64, output: amd64-go120, version: 20 } | |
# - { goos: windows, goarch: amd64, goamd64: v3, output: amd64_v3-go120, version: 20 } | |
# - { goos: windows, goarch: arm64, output: arm64 } | |
# - { goos: freebsd, goarch: '386', output: '386' } | |
# - { goos: freebsd, goarch: amd64, output: amd64 } | |
# - { goos: freebsd, goarch: amd64, goamd64: v3, output: amd64_v3 } | |
# - { goos: freebsd, goarch: arm64, output: arm64 } | |
# - { goos: android, goarch: '386', ndk: i686-linux-android34, output: '386', cgo: '1'} | |
# - { goos: android, goarch: amd64, ndk: x86_64-linux-android34, output: amd64, cgo: '1' } | |
# - { goos: android, goarch: arm, ndk: armv7a-linux-androideabi34, output: armv7, cgo: '1' } | |
# - { goos: android, goarch: arm64, ndk: aarch64-linux-android34, output: arm64-v8, cgo: '1' } | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Go1.22 | |
if: ${{ matrix.jobs.version != '20' }} | |
uses: actions/setup-go@v5 | |
with: | |
go-version: ^1.22 | |
- name: Set up Go1.20 | |
if: ${{ matrix.jobs.version == '20' }} | |
uses: actions/setup-go@v5 | |
with: | |
go-version: ^1.20 | |
- name: Set Time Variable | |
run: | | |
echo "VERSION=$(git rev-parse --short HEAD)" >> $GITHUB_ENV | |
echo "BUILDTIME=$(date)" >> $GITHUB_ENV | |
- name: Setup NDK | |
if: ${{ matrix.jobs.goos == 'android' }} | |
uses: nttld/setup-ndk@v1 | |
id: setup-ndk | |
with: | |
ndk-version: r26c | |
- name: Set NDK path | |
if: ${{ matrix.jobs.goos == 'android' }} | |
run: | | |
echo "CC=${{steps.setup-ndk.outputs.ndk-path}}/toolchains/llvm/prebuilt/linux-x86_64/bin/${{matrix.jobs.ndk}}-clang" >> $GITHUB_ENV | |
- name: build core | |
env: | |
GOOS: ${{matrix.jobs.goos}} | |
GOARCH: ${{matrix.jobs.goarch}} | |
GOAMD64: ${{matrix.jobs.goamd64}} | |
GOARM: ${{matrix.jobs.arm}} | |
GOMIPS: ${{matrix.jobs.mips}} | |
CGO_ENABLED: ${{matrix.jobs.cgo}} | |
run: | | |
go build -v -tags "with_gvisor" -trimpath -ldflags "-extldflags --static -X 'github.com/metacubex/mihomo/constant.Version=${VERSION}' -X 'github.com/metacubex/mihomo/constant.BuildTime=${BUILDTIME}' -w -s -buildid=" | |
if [ "${{matrix.jobs.goos}}" = "windows" ]; then | |
zip -r mihomo-${{matrix.jobs.goos}}-${{matrix.jobs.output}}-${VERSION}.zip mihomo.exe | |
else | |
# tar -czvf mihomo-${{matrix.jobs.goos}}-${{matrix.jobs.output}}-${VERSION}.tar.gz mihomo | |
gzip -c mihomo > mihomo-${{matrix.jobs.goos}}-${{matrix.jobs.output}}-${VERSION}.gz | |
fi | |
- name: Create DEB package | |
if: ${{ matrix.jobs.goos == 'linux' }} | |
run: | | |
sudo apt-get install dpkg | |
mkdir -p mihomo-${{matrix.jobs.goos}}-${{matrix.jobs.output}}-${VERSION}/DEBIAN | |
mkdir -p mihomo-${{matrix.jobs.goos}}-${{matrix.jobs.output}}-${VERSION}/usr/bin | |
mkdir -p mihomo-${{matrix.jobs.goos}}-${{matrix.jobs.output}}-${VERSION}/etc/mihomo | |
mkdir -p mihomo-${{matrix.jobs.goos}}-${{matrix.jobs.output}}-${VERSION}/etc/systemd/system/ | |
mkdir -p mihomo-${{matrix.jobs.goos}}-${{matrix.jobs.output}}-${VERSION}/usr/share/licenses/mihomo | |
cp mihomo mihomo-${{matrix.jobs.goos}}-${{matrix.jobs.output}}-${VERSION}/usr/bin/mihomo | |
cp LICENSE mihomo-${{matrix.jobs.goos}}-${{matrix.jobs.output}}-${VERSION}/usr/share/licenses/mihomo/ | |
cp .github/mihomo.service mihomo-${{matrix.jobs.goos}}-${{matrix.jobs.output}}-${VERSION}/etc/systemd/system/ | |
cat > mihomo-${{matrix.jobs.goos}}-${{matrix.jobs.output}}-${VERSION}/etc/mihomo/config.yaml <<EOF | |
mixed-port: 7890 | |
external-controller: 127.0.0.1:9090 | |
EOF | |
cat > mihomo-${{matrix.jobs.goos}}-${{matrix.jobs.output}}-${VERSION}/DEBIAN/control <<EOF | |
Package: mihomo | |
Version: 1.18.2-alpha-${VERSION} | |
Section: | |
Priority: extra | |
Architecture: ${{matrix.jobs.goarch}} | |
Maintainer: MetaCubeX <[email protected]> | |
Homepage: https://wiki.metacubex.one/ | |
Description: The universal proxy platform. | |
EOF | |
dpkg-deb -Z gzip --build mihomo-${{matrix.jobs.goos}}-${{matrix.jobs.output}}-${VERSION} | |
- name: Save version | |
run: | | |
echo ${VERSION} > version.txt | |
shell: bash | |
- name: Archive production artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: ${{ matrix.jobs.goos }}-${{ matrix.jobs.output }} | |
path: | | |
mihomo*.gz | |
mihomo*.deb | |
mihomo*.zip | |
version.txt | |
Upload-Prerelease: | |
permissions: write-all | |
if: ${{ github.ref_type == 'branch' && !startsWith(github.event_name, 'pull_request') }} | |
needs: [build] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Download all workflow run artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
path: bin/ | |
merge-multiple: true | |
- name: Delete current release assets | |
uses: 8Mi-Tech/delete-release-assets-action@main | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
tag: Prerelease-${{ github.ref_name }} | |
deleteOnlyFromDrafts: false | |
- name: Set Env | |
run: | | |
echo "BUILDTIME=$(TZ=Asia/Shanghai date)" >> $GITHUB_ENV | |
shell: bash | |
- name: Tag Repo | |
uses: richardsimko/update-tag@v1 | |
with: | |
tag_name: Prerelease-${{ github.ref_name }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- run: | | |
cat > release.txt << 'EOF' | |
Release created at ${{ env.BUILDTIME }} | |
Synchronize ${{ github.ref_name }} branch code updates, keeping only the latest version | |
<br> | |
[我应该下载哪个文件? / Which file should I download?](https://github.com/MetaCubeX/mihomo/wiki/FAQ) | |
[二进制文件筛选 / Binary file selector](https://metacubex.github.io/Meta-Docs/startup/#_1) | |
[查看文档 / Docs](https://metacubex.github.io/Meta-Docs/) | |
EOF | |
- name: Upload Prerelease | |
uses: softprops/action-gh-release@v1 | |
if: ${{ success() }} | |
with: | |
tag_name: Prerelease-${{ github.ref_name }} | |
files: | | |
bin/* | |
prerelease: true | |
generate_release_notes: true | |
body_path: release.txt | |
Upload-Release: | |
permissions: write-all | |
if: ${{ github.ref_type=='tag' }} | |
needs: [build] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Get tags | |
run: | | |
echo "CURRENTVERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV | |
git fetch --tags | |
echo "PREVERSION=$(git describe --tags --abbrev=0 HEAD^)" >> $GITHUB_ENV | |
- name: Generate release notes | |
run: | | |
cp ./.github/genReleaseNote.sh ./ | |
bash ./genReleaseNote.sh -v ${PREVERSION}...${CURRENTVERSION} | |
rm ./genReleaseNote.sh | |
- uses: actions/download-artifact@v4 | |
with: | |
path: bin/ | |
merge-multiple: true | |
- name: Display structure of downloaded files | |
run: ls -R | |
working-directory: bin | |
- name: Upload Release | |
uses: softprops/action-gh-release@v1 | |
if: ${{ success() }} | |
with: | |
tag_name: ${{ github.ref_name }} | |
files: bin/* | |
generate_release_notes: true | |
body_path: release.md |