Skip to content

Automatic core compression #150

Automatic core compression

Automatic core compression #150

Workflow file for this run

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