From 0cadd027ec06ea60bd81e195b063f4ad3f152e5f Mon Sep 17 00:00:00 2001 From: juewuy Date: Tue, 30 Jan 2024 18:47:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=86=85=E6=A0=B8=E5=8E=8B?= =?UTF-8?q?=E7=BC=A9=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/update_meta_core.yaml | 257 ++++++++++++++++----- .github/workflows/update_singbox_core.yaml | 26 ++- 2 files changed, 218 insertions(+), 65 deletions(-) diff --git a/.github/workflows/update_meta_core.yaml b/.github/workflows/update_meta_core.yaml index 09a2891..3f377d5 100644 --- a/.github/workflows/update_meta_core.yaml +++ b/.github/workflows/update_meta_core.yaml @@ -1,63 +1,194 @@ -name: Update Meta Core -on: - workflow_dispatch: - inputs: - tag: - description: 'tag of Clash Meta, such as Prerelease-Alpha, Prerelease-Beta, v1.11.1' - required: true - type: string -env: - download_tag: ${{ github.event.inputs.tag }} - download_version: '' - download_url: https://github.com/MetaCubeX/mihomo/releases/download -jobs: - Update: - runs-on: ubuntu-latest - steps: - - name: Clone Repository - uses: actions/checkout@main - - name: Init Dependencies - run: | - wget https://github.com/upx/upx/releases/download/v3.96/upx-3.96-amd64_linux.tar.xz - wget https://github.com/upx/upx/releases/download/v3.93/upx-3.93-amd64_linux.tar.xz - tar xf upx-3.96-amd64_linux.tar.xz - tar xf upx-3.93-amd64_linux.tar.xz - - name: Download Core - run: | - if [ "${download_tag}" = "Prerelease-Alpha" ] || [ "${download_tag}" = "Prerelease-Beta" ];then - download_version=$(curl -sL https://api.github.com/repos/MetaCubeX/mihomo/releases/tags/${download_tag} | grep linux-arm64 | head -n 1 | sed 's_.gz.*__;s_.*arm64-__') - else - download_version=${download_tag} - fi - echo "download_version=${download_version}" >> ${GITHUB_ENV} - archs=(amd64-compatible armv5 armv7 arm64 mips-softfloat mipsle-hardfloat mipsle-softfloat) - new_name=(amd64 armv5 armv7 armv8 mips-softfloat mipsle-hardfloat mipsle-softfloat) - mkdir tmp - for((i=0;i<7;i++));do - wget "${download_url}/${download_tag}/mihomo-linux-${archs[i]}-${download_version}.gz" -O - | gunzip -c > ./tmp/clash-linux-${new_name[i]} - chmod +x ./tmp/clash-linux-${new_name[i]} - if [ "${archs[i]}" != "armv5" ];then - if [[ ${archs[i]} = mips* ]];then - ./upx-3.93-amd64_linux/upx ./tmp/clash-linux-${new_name[i]} - else - ./upx-3.96-amd64_linux/upx ./tmp/clash-linux-${new_name[i]} - fi - fi - done - rm -fr upx* - - name: Update - run: | - rm -fr ./bin/meta/* - cp ./tmp/* ./bin/meta/ - rm -fr ./tmp - sed -i "s/meta_v=.*/meta_v=$(./bin/meta/clash-linux-amd64 -v 2>/dev/null | head -n 1 | sed 's/ linux.*//;s/.* //')/" bin/version - - name: Commit and push - run: | - git config --global user.email "juewuy@gmail.com" && git config --global user.name "Bot" - git add . && git commit -m "更新Meta内核至${download_version}" || exit 0 - git push - - name: Cleanup Workflow - uses: Mattraks/delete-workflow-runs@main - with: - retain_days: 1 - keep_minimum_runs: 2 +name: Build meta Core for ShellCrash + +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: setup go + uses: actions/setup-go@v4.1.0 + with: + go-version: ${{needs.go.outputs.version}} + + - 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-mipsel-softfloat + goos: linux + goarch: mipsle + gomips: softfloat + - name: linux-mipsel-hardfloat + goos: linux + goarch: mipsle + gomips: hardfloat + + fail-fast: false + runs-on: ubuntu-latest + needs: 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@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 + with: + repository: ${{ github.event.inputs.tag1 }} + ref: ${{ github.event.inputs.tag2 }} + fetch-depth: 1 + + - name: Setup Go + uses: actions/setup-go@v5 + with: + go-version: ${{ steps.go.outputs.version }} + + - name: Set ENV + run: | + sudo timedatectl set-timezone "Asia/Shanghai" + echo "BUILDTIME=$(date)" >> $GITHUB_ENV + shell: bash + + - name: build core + id: build + run: go build -v -trimpath -ldflags "-X 'github.com/metacubex/mihomo/constant.Version=${VERSION}' -X 'github.com/metacubex/mihomo/constant.BuildTime=${BUILDTIME}' -s -w -buildid=" -tags "${TAGS}" -o meta + + - 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: 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 mipsel-hardfloat mipsel-softfloat;do + 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 "juewuy@gmail.com" && git config --global user.name "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 diff --git a/.github/workflows/update_singbox_core.yaml b/.github/workflows/update_singbox_core.yaml index 8b25694..4952213 100644 --- a/.github/workflows/update_singbox_core.yaml +++ b/.github/workflows/update_singbox_core.yaml @@ -12,6 +12,14 @@ on: required: true type: string tag3: + description: 'a new prerelease name (such as singbox_core_178) or only upload-artifact' + required: false + type: string + tag4: + description: 'git push as crashcore (such as singbox or singboxp) or only upload-artifact' + required: false + type: string + tag5: description: 'build tags' required: false type: string @@ -31,7 +39,7 @@ jobs: needs: go env: REPO: ${{ github.event.inputs.tag1 }} - TAGS: ${{ github.event.inputs.tag3 }} + TAGS: ${{ github.event.inputs.tag5 }} outputs: version: ${{steps.sing-box.outputs.version}} tags: ${{steps.sing-box.outputs.tags}} @@ -135,12 +143,14 @@ jobs: name: ${{ matrix.name }} path: sing-box - push_to_bin: + push_to_git: needs: - cross - sing-box runs-on: ubuntu-latest env: + RELEASE: ${{ github.event.inputs.tag3 }} + PUSHDIR: ${{ github.event.inputs.tag4 }} VERSION: ${{needs.sing-box.outputs.version}} steps: - name: Checkout ShellCrash @@ -175,6 +185,18 @@ jobs: 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/singbox*.tar.gz + - name: Cleanup Workflow uses: Mattraks/delete-workflow-runs@main with: