github.com/kelleygo/clashcore@v1.0.2/.github/workflows/build.yml (about)

     1  name: Build
     2  on:
     3    workflow_dispatch:
     4    push:
     5      paths-ignore:
     6        - "docs/**"
     7        - "README.md"
     8        - ".github/ISSUE_TEMPLATE/**"
     9      branches:
    10        - Alpha
    11      tags:
    12        - "v*"
    13    pull_request_target:
    14      branches:
    15        - Alpha
    16        
    17  concurrency:
    18    group: ${{ github.workflow }}-${{ github.ref }}
    19    cancel-in-progress: true
    20    
    21  env:
    22    REGISTRY: docker.io
    23  jobs:
    24    build:
    25      runs-on: ubuntu-latest
    26      strategy:
    27        matrix:
    28          jobs:
    29            - { goos: darwin, goarch: arm64, output: arm64 }
    30            - { goos: darwin, goarch: amd64, goamd64: v1, output: amd64-compatible }
    31            - { goos: darwin, goarch: amd64, goamd64: v3, output: amd64 }
    32  
    33            - { goos: linux, goarch: '386', output: '386' }
    34            - { goos: linux, goarch: amd64, goamd64: v1, output: amd64-compatible, test: test }
    35            - { goos: linux, goarch: amd64, goamd64: v3, output: amd64 }
    36            - { goos: linux, goarch: arm64, output: arm64 }
    37            - { goos: linux, goarch: arm, goarm: '5', output: armv5 }
    38            - { goos: linux, goarch: arm, goarm: '6', output: armv6 }
    39            - { goos: linux, goarch: arm, goarm: '7', output: armv7 }
    40            - { goos: linux, goarch: mips, mips: hardfloat, output: mips-hardfloat }
    41            - { goos: linux, goarch: mips, mips: softfloat, output: mips-softfloat }
    42            - { goos: linux, goarch: mipsle, mips: hardfloat, output: mipsle-hardfloat }
    43            - { goos: linux, goarch: mipsle, mips: softfloat, output: mipsle-softfloat }
    44            - { goos: linux, goarch: mips64, output: mips64 }
    45            - { goos: linux, goarch: mips64le, output: mips64le }
    46            - { goos: linux, goarch: loong64, output: loong64-abi1, abi: '1' }
    47            - { goos: linux, goarch: loong64, output: loong64-abi2, abi: '2' }
    48            - { goos: linux, goarch: riscv64, output: riscv64 }
    49            - { goos: linux, goarch: s390x, output: s390x }
    50  
    51            - { goos: windows, goarch: '386', output: '386' }
    52            - { goos: windows, goarch: amd64, goamd64: v1, output: amd64-compatible }
    53            - { goos: windows, goarch: amd64, goamd64: v3, output: amd64 }
    54            - { goos: windows, goarch: arm, goarm: '7', output: armv7 }
    55            - { goos: windows, goarch: arm64, output: arm64 }
    56  
    57            - { goos: freebsd, goarch: '386', output: '386' }
    58            - { goos: freebsd, goarch: amd64, goamd64: v1, output: amd64-compatible }
    59            - { goos: freebsd, goarch: amd64, goamd64: v3, output: amd64 }
    60            - { goos: freebsd, goarch: arm64, output: arm64 }
    61  
    62            - { goos: android, goarch: '386', ndk: i686-linux-android34, output: '386' }
    63            - { goos: android, goarch: amd64, ndk: x86_64-linux-android34, output: amd64 }
    64            - { goos: android, goarch: arm, ndk: armv7a-linux-androideabi34, output: armv7 }
    65            - { goos: android, goarch: arm64, ndk: aarch64-linux-android34, output: arm64-v8 }
    66  
    67            # 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.
    68            - { goos: windows, goarch: '386', output: '386-go120', goversion: '1.20' }
    69            - { goos: windows, goarch: amd64, goamd64: v1, output: amd64-compatible-go120, goversion: '1.20' }
    70            - { goos: windows, goarch: amd64, goamd64: v3, output: amd64-go120, goversion: '1.20' }
    71  
    72            # 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.
    73            - { goos: darwin, goarch: arm64, output: arm64-go120, goversion: '1.20' }
    74            - { goos: darwin, goarch: amd64, goamd64: v1, output: amd64-compatible-go120, goversion: '1.20' }
    75            - { goos: darwin, goarch: amd64, goamd64: v3, output: amd64-go120, goversion: '1.20' }
    76  
    77            # only for test
    78            - { goos: linux, goarch: '386', output: '386-go120', goversion: '1.20' }
    79            - { goos: linux, goarch: amd64, goamd64: v1, output: amd64-compatible-go120, goversion: '1.20', test: test }
    80            - { goos: linux, goarch: amd64, goamd64: v3, output: amd64-go120, goversion: '1.20' }
    81  
    82      steps:
    83      - uses: actions/checkout@v4
    84  
    85      - name: Set up Go
    86        if: ${{ matrix.jobs.goversion == '' && matrix.jobs.goarch != 'loong64' }}
    87        uses: actions/setup-go@v5
    88        with:
    89          go-version: '1.22'
    90  
    91      - name: Set up Go
    92        if: ${{ matrix.jobs.goversion != '' && matrix.jobs.goarch != 'loong64' }}
    93        uses: actions/setup-go@v5
    94        with:
    95          go-version: ${{ matrix.jobs.goversion }}
    96  
    97      - name: Set up Go1.21 loongarch abi1
    98        if: ${{ matrix.jobs.goarch == 'loong64' && matrix.jobs.abi == '1' }}
    99        run: |
   100          wget -q https://github.com/xishang0128/loongarch64-golang/releases/download/1.21.5/go1.21.5.linux-amd64-abi1.tar.gz
   101          sudo tar zxf go1.21.5.linux-amd64-abi1.tar.gz -C /usr/local
   102          echo "/usr/local/go/bin" >> $GITHUB_PATH
   103  
   104      - name: Set up Go1.21 loongarch abi2
   105        if: ${{ matrix.jobs.goarch == 'loong64' && matrix.jobs.abi == '2' }}
   106        run: |
   107          wget -q https://github.com/xishang0128/loongarch64-golang/releases/download/1.21.5/go1.21.5.linux-amd64-abi2.tar.gz
   108          sudo tar zxf go1.21.5.linux-amd64-abi2.tar.gz -C /usr/local
   109          echo "/usr/local/go/bin" >> $GITHUB_PATH
   110  
   111      - name: Set variables
   112        if: ${{github.ref_name=='Alpha'}}
   113        run: echo "VERSION=alpha-$(git rev-parse --short HEAD)" >> $GITHUB_ENV
   114        shell: bash
   115  
   116      - name: Set variables
   117        if: ${{github.ref_name=='' || github.ref_type=='tag'}}
   118        run: echo "VERSION=$(git describe --tags)" >> $GITHUB_ENV
   119        shell: bash
   120  
   121      - name: Set Time Variable
   122        run: |
   123          echo "BUILDTIME=$(date)" >> $GITHUB_ENV
   124          echo "CGO_ENABLED=0" >> $GITHUB_ENV
   125          echo "BUILDTAG=-extldflags --static" >> $GITHUB_ENV
   126  
   127      - name: Setup NDK
   128        if: ${{ matrix.jobs.goos == 'android' }}
   129        uses: nttld/setup-ndk@v1
   130        id: setup-ndk
   131        with:
   132          ndk-version: r26c
   133  
   134      - name: Set NDK path
   135        if: ${{ matrix.jobs.goos == 'android' }}
   136        run: |
   137          echo "CC=${{steps.setup-ndk.outputs.ndk-path}}/toolchains/llvm/prebuilt/linux-x86_64/bin/${{matrix.jobs.ndk}}-clang" >> $GITHUB_ENV
   138          echo "CGO_ENABLED=1" >> $GITHUB_ENV
   139          echo "BUILDTAG=" >> $GITHUB_ENV
   140  
   141      - name: Test
   142        if: ${{ matrix.jobs.test == 'test' }}
   143        run: |
   144          go test ./...
   145  
   146      - name: Update CA
   147        run: |
   148          sudo apt-get install ca-certificates
   149          sudo update-ca-certificates
   150          cp -f /etc/ssl/certs/ca-certificates.crt component/ca/ca-certificates.crt
   151  
   152      - name: Build core
   153        env:
   154          GOOS: ${{matrix.jobs.goos}}
   155          GOARCH: ${{matrix.jobs.goarch}}
   156          GOAMD64: ${{matrix.jobs.goamd64}}
   157          GOARM: ${{matrix.jobs.arm}}
   158          GOMIPS: ${{matrix.jobs.mips}}
   159        run: |
   160          echo $CGO_ENABLED
   161          go build -v -tags "with_gvisor" -trimpath -ldflags "${BUILDTAG} -X 'github.com/lingyicute/yiclashcore/constant.Version=${VERSION}' -X 'github.com/lingyicute/yiclashcore/constant.BuildTime=${BUILDTIME}' -w -s -buildid="
   162          if [ "${{matrix.jobs.goos}}" = "windows" ]; then
   163            cp yiclashcore.exe yiclashcore-${{matrix.jobs.goos}}-${{matrix.jobs.output}}.exe
   164            zip -r yiclashcore-${{matrix.jobs.goos}}-${{matrix.jobs.output}}-${VERSION}.zip yiclashcore-${{matrix.jobs.goos}}-${{matrix.jobs.output}}.exe
   165          else
   166            cp yiclashcore yiclashcore-${{matrix.jobs.goos}}-${{matrix.jobs.output}}
   167            gzip -c yiclashcore-${{matrix.jobs.goos}}-${{matrix.jobs.output}} > yiclashcore-${{matrix.jobs.goos}}-${{matrix.jobs.output}}-${VERSION}.gz
   168            rm yiclashcore-${{matrix.jobs.goos}}-${{matrix.jobs.output}}
   169          fi
   170  
   171      - name: Create DEB package
   172        if: ${{ matrix.jobs.goos == 'linux' && !contains(matrix.jobs.goarch, 'mips') }}
   173        run: |
   174          sudo apt-get install dpkg
   175          if [ "${{matrix.jobs.abi}}" = "1" ]; then
   176            ARCH=loongarch64
   177          else
   178            ARCH=${{matrix.jobs.goarch}}
   179          fi
   180          PackageVersion=$(curl -s "https://api.github.com/repos/lingyicute/YiClashCore/releases/latest" | grep -o '"tag_name": "[^"]*' | grep -o '[^"]*$' | sed 's/v//g' )
   181          if [ $(git branch | awk -F ' ' '{print $2}') = "Alpha" ]; then
   182            PackageVersion="$(echo "${PackageVersion}" | awk -F '.' '{$NF = $NF + 1; print}' OFS='.')-${VERSION}"
   183          fi
   184  
   185          mkdir -p yiclashcore-${{matrix.jobs.goos}}-${{matrix.jobs.output}}-${VERSION}/DEBIAN
   186          mkdir -p yiclashcore-${{matrix.jobs.goos}}-${{matrix.jobs.output}}-${VERSION}/usr/bin
   187          mkdir -p yiclashcore-${{matrix.jobs.goos}}-${{matrix.jobs.output}}-${VERSION}/etc/yiclashcore
   188          mkdir -p yiclashcore-${{matrix.jobs.goos}}-${{matrix.jobs.output}}-${VERSION}/etc/systemd/system/
   189          mkdir -p yiclashcore-${{matrix.jobs.goos}}-${{matrix.jobs.output}}-${VERSION}/usr/share/licenses/yiclashcore
   190  
   191          cp yiclashcore yiclashcore-${{matrix.jobs.goos}}-${{matrix.jobs.output}}-${VERSION}/usr/bin/yiclashcore
   192          cp LICENSE yiclashcore-${{matrix.jobs.goos}}-${{matrix.jobs.output}}-${VERSION}/usr/share/licenses/yiclashcore/
   193          cp .github/yiclashcore.service yiclashcore-${{matrix.jobs.goos}}-${{matrix.jobs.output}}-${VERSION}/etc/systemd/system/
   194  
   195          cat > yiclashcore-${{matrix.jobs.goos}}-${{matrix.jobs.output}}-${VERSION}/etc/yiclashcore/config.yaml <<EOF
   196          mixed-port: 7890
   197          external-controller: 127.0.0.1:9090
   198          EOF
   199  
   200          cat > yiclashcore-${{matrix.jobs.goos}}-${{matrix.jobs.output}}-${VERSION}/DEBIAN/control <<EOF
   201          Package: yiclashcore
   202          Version: ${PackageVersion}
   203          Section:
   204          Priority: extra
   205          Architecture: ${ARCH}
   206          Maintainer: MetaCubeX <none@example.com>
   207          Homepage: https://wiki.metacubex.one/
   208          Description: The universal proxy platform.
   209          EOF
   210  
   211          dpkg-deb -Z gzip --build yiclashcore-${{matrix.jobs.goos}}-${{matrix.jobs.output}}-${VERSION}
   212  
   213      - name: Convert DEB to RPM
   214        if: ${{ matrix.jobs.goos == 'linux' && !contains(matrix.jobs.goarch, 'mips') }}
   215        run: |
   216          sudo apt-get install -y alien
   217          alien --to-rpm --scripts yiclashcore-${{matrix.jobs.goos}}-${{matrix.jobs.output}}-${VERSION}.deb
   218          mv yiclashcore*.rpm yiclashcore-${{matrix.jobs.goos}}-${{matrix.jobs.output}}-${VERSION}.rpm
   219  
   220      # - name: Convert DEB to PKG
   221      #   if: ${{ matrix.jobs.goos == 'linux' && !contains(matrix.jobs.goarch, 'mips') && !contains(matrix.jobs.goarch, 'loong64') }}
   222      #   run: |
   223      #     docker pull archlinux
   224      #     docker run --rm -v ./:/mnt archlinux bash -c "
   225      #       pacman -Syu pkgfile base-devel --noconfirm
   226      #       curl -L https://github.com/helixarch/debtap/raw/master/debtap > /usr/bin/debtap
   227      #       chmod 755 /usr/bin/debtap
   228      #       debtap -u 
   229      #       debtap -Q /mnt/yiclashcore-${{matrix.jobs.goos}}-${{matrix.jobs.output}}-${VERSION}.deb
   230      #     "
   231      #     mv yiclashcore*.pkg.tar.zst yiclashcore-${{matrix.jobs.goos}}-${{matrix.jobs.output}}-${VERSION}.pkg.tar.zst
   232  
   233      - name: Save version
   234        run: |
   235          echo ${VERSION} > version.txt
   236        shell: bash
   237  
   238      - name: Archive production artifacts
   239        uses: actions/upload-artifact@v4
   240        with:
   241          name: ${{ matrix.jobs.goos }}-${{ matrix.jobs.output }}
   242          path: |
   243            yiclashcore*.gz
   244            yiclashcore*.deb
   245            yiclashcore*.rpm
   246            yiclashcore*.zip
   247            version.txt
   248  
   249    Upload-Prerelease:
   250      permissions: write-all
   251      if: ${{ github.ref_type == 'branch' && !startsWith(github.event_name, 'pull_request') }}
   252      needs: [build]
   253      runs-on: ubuntu-latest
   254      steps:
   255      - name: Download all workflow run artifacts
   256        uses: actions/download-artifact@v4
   257        with:
   258          path: bin/
   259          merge-multiple: true
   260  
   261      - name: Delete current release assets
   262        uses: 8Mi-Tech/delete-release-assets-action@main
   263        with:
   264          github_token: ${{ secrets.GITHUB_TOKEN }}
   265          tag: Prerelease-${{ github.ref_name }}
   266          deleteOnlyFromDrafts: false
   267      - name: Set Env
   268        run: |
   269          echo "BUILDTIME=$(TZ=Asia/Shanghai date)" >> $GITHUB_ENV
   270        shell: bash
   271  
   272      - name: Tag Repo
   273        uses: richardsimko/update-tag@v1
   274        with:
   275          tag_name: Prerelease-${{ github.ref_name }}
   276        env:
   277          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
   278        
   279      - run: |
   280          cat > release.txt << 'EOF'
   281          Release created at  ${{ env.BUILDTIME }}
   282          Synchronize ${{ github.ref_name }} branch code updates, keeping only the latest version
   283          <br>
   284          [我应该下载哪个文件? / Which file should I download?](https://github.com/lingyicute/YiClashCore/wiki/FAQ)
   285          [二进制文件筛选 / Binary file selector](https://metacubex.github.io/Meta-Docs/startup/#_1)
   286          [查看文档 / Docs](https://metacubex.github.io/Meta-Docs/)
   287          EOF
   288  
   289      - name: Upload Prerelease
   290        uses: softprops/action-gh-release@v1
   291        if: ${{  success() }}
   292        with:
   293          tag_name: Prerelease-${{ github.ref_name }}
   294          files: |
   295            bin/*
   296          prerelease: true
   297          generate_release_notes: true
   298          body_path: release.txt
   299  
   300    Upload-Release:
   301      permissions: write-all
   302      if: ${{ github.ref_type=='tag' }}
   303      needs: [build]
   304      runs-on: ubuntu-latest
   305      steps:
   306      - name: Checkout
   307        uses: actions/checkout@v4
   308        with:
   309          fetch-depth: 0
   310  
   311      - name: Get tags
   312        run: |
   313          echo "CURRENTVERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
   314          git fetch --tags
   315          echo "PREVERSION=$(git describe --tags --abbrev=0 HEAD^)" >> $GITHUB_ENV
   316  
   317      - name: Generate release notes
   318        run: |
   319            cp ./.github/genReleaseNote.sh ./
   320            bash ./genReleaseNote.sh -v ${PREVERSION}...${CURRENTVERSION}
   321            rm ./genReleaseNote.sh
   322  
   323      - uses: actions/download-artifact@v4
   324        with:
   325          path: bin/
   326          merge-multiple: true
   327  
   328      - name: Display structure of downloaded files
   329        run: ls -R
   330        working-directory: bin
   331  
   332      - name: Upload Release
   333        uses: softprops/action-gh-release@v1
   334        if: ${{  success() }}
   335        with:
   336          tag_name: ${{ github.ref_name }}
   337          files: bin/*
   338          generate_release_notes: true
   339          body_path: release.md
   340  
   341    Docker:
   342      if: ${{ !startsWith(github.event_name, 'pull_request') }}
   343      permissions: write-all
   344      needs: [build]
   345      runs-on: ubuntu-latest
   346      steps:
   347        - name: Checkout repository
   348          uses: actions/checkout@v4
   349          with:
   350            fetch-depth: 0
   351  
   352        - uses: actions/download-artifact@v4
   353          with:
   354            path: bin/
   355            merge-multiple: true
   356  
   357        - name: Display structure of downloaded files
   358          run: ls -R
   359          working-directory: bin
   360  
   361        - name: Set up QEMU
   362          uses: docker/setup-qemu-action@v3
   363  
   364        - name: Setup Docker buildx
   365          uses: docker/setup-buildx-action@v3
   366          with:
   367            version: latest
   368  
   369        # Extract metadata (tags, labels) for Docker
   370        # https://github.com/docker/metadata-action
   371        - name: Extract Docker metadata
   372          id: meta
   373          uses: docker/metadata-action@v5
   374          with:
   375            images: ${{ env.REGISTRY }}/${{ github.repository }}
   376  
   377        - name: Show files
   378          run: |
   379            ls .
   380            ls bin/
   381  
   382        - name: login to docker REGISTRY
   383          uses: docker/login-action@v3
   384          with:
   385            registry: ${{ env.REGISTRY }}
   386            username: ${{ secrets.DOCKER_HUB_USER }}
   387            password: ${{ secrets.DOCKER_HUB_TOKEN }}
   388  
   389        # Build and push Docker image with Buildx (don't push on PR)
   390        # https://github.com/docker/build-push-action
   391        - name: Build and push Docker image
   392          id: build-and-push
   393          uses: docker/build-push-action@v5
   394          with:
   395            context: .
   396            file: ./Dockerfile
   397            push: ${{ github.event_name != 'pull_request' }}
   398            platforms: |
   399              linux/386
   400              linux/amd64
   401              linux/arm64
   402              linux/arm/v7
   403            tags: ${{ steps.meta.outputs.tags }}
   404            labels: ${{ steps.meta.outputs.labels }}