github.com/xraypb/xray-core@v1.6.6/.github/workflows/release.yml (about)

     1  name: Build and Release
     2  
     3  on:
     4    workflow_dispatch:
     5    release:
     6      types: [published]
     7    push:
     8      branches:
     9        - main
    10      paths:
    11        - "**/*.go"
    12        - "go.mod"
    13        - "go.sum"
    14        - ".github/workflows/*.yml"
    15    pull_request:
    16      types: [opened, synchronize, reopened]
    17      paths:
    18        - "**/*.go"
    19        - "go.mod"
    20        - "go.sum"
    21        - ".github/workflows/*.yml"
    22  jobs:
    23    build:
    24      permissions:
    25        contents: write
    26      strategy:
    27        matrix:
    28          # Include amd64 on all platforms.
    29          goos: [windows, freebsd, openbsd, linux, dragonfly, darwin]
    30          goarch: [amd64, 386]
    31          exclude:
    32            # Exclude i386 on darwin and dragonfly.
    33            - goarch: 386
    34              goos: dragonfly
    35            - goarch: 386
    36              goos: darwin
    37          include:
    38            # BEIGIN MacOS ARM64
    39            - goos: darwin
    40              goarch: arm64
    41            # END MacOS ARM64
    42            # BEGIN Linux ARM 5 6 7
    43            - goos: linux
    44              goarch: arm
    45              goarm: 7
    46            - goos: linux
    47              goarch: arm
    48              goarm: 6
    49            - goos: linux
    50              goarch: arm
    51              goarm: 5
    52            # END Linux ARM 5 6 7
    53            # BEGIN Android ARM 8
    54            - goos: android
    55              goarch: arm64
    56            # END Android ARM 8
    57            # Windows ARM
    58            - goos: windows
    59              goarch: arm64
    60            - goos: windows
    61              goarch: arm
    62              goarm: 7
    63            # BEGIN Other architectures
    64            # BEGIN riscv64 & ARM64
    65            - goos: linux
    66              goarch: arm64
    67            - goos: linux
    68              goarch: riscv64
    69            # END riscv64 & ARM64
    70            # BEGIN MIPS
    71            - goos: linux
    72              goarch: mips64
    73            - goos: linux
    74              goarch: mips64le
    75            - goos: linux
    76              goarch: mipsle
    77            - goos: linux
    78              goarch: mips
    79            # END MIPS
    80            # BEGIN PPC
    81            - goos: linux
    82              goarch: ppc64
    83            - goos: linux
    84              goarch: ppc64le
    85            # END PPC
    86            # BEGIN FreeBSD ARM
    87            - goos: freebsd
    88              goarch: arm64
    89            - goos: freebsd
    90              goarch: arm
    91              goarm: 7
    92            # END FreeBSD ARM
    93            # BEGIN S390X
    94            - goos: linux
    95              goarch: s390x
    96            # END S390X
    97            # END Other architectures
    98            # BEGIN OPENBSD ARM
    99            - goos: openbsd
   100              goarch: arm64
   101            - goos: openbsd
   102              goarch: arm
   103              goarm: 7
   104            # END OPENBSD ARM
   105        fail-fast: false
   106  
   107      runs-on: ubuntu-latest
   108      env:
   109        GOOS: ${{ matrix.goos }}
   110        GOARCH: ${{ matrix.goarch }}
   111        GOARM: ${{ matrix.goarm }}
   112        CGO_ENABLED: 0
   113      steps:
   114        - name: Checkout codebase
   115          uses: actions/checkout@v3
   116  
   117        - name: Show workflow information 
   118          run: |
   119            export _NAME=$(jq ".[\"$GOOS-$GOARCH$GOARM$GOMIPS\"].friendlyName" -r < .github/build/friendly-filenames.json)
   120            echo "GOOS: $GOOS, GOARCH: $GOARCH, GOARM: $GOARM, GOMIPS: $GOMIPS, RELEASE_NAME: $_NAME"
   121            echo "ASSET_NAME=$_NAME" >> $GITHUB_ENV
   122  
   123        - name: Set up Go
   124          uses: actions/setup-go@v3
   125          with:
   126            go-version: 1.19
   127            check-latest: true
   128  
   129        - name: Get project dependencies
   130          run: go mod download
   131        
   132        - name: Replace Custom to Commit ID
   133          if: github.event_name != 'release'
   134          run: |
   135            ID=$(git rev-parse --short ${{ github.sha }})
   136            if [ "${{ github.event_name }}" == 'pull_request' ]
   137            then
   138              ID=$(git rev-parse --short ${{ github.event.pull_request.head.sha }})
   139            fi
   140            sed -i '/build/ s/Custom/'$ID'/' ./core/core.go
   141   
   142        - name: Build Xray
   143          run: |
   144            mkdir -p build_assets
   145            go build -v -o build_assets/xray -trimpath -ldflags "-s -w -buildid=" ./main
   146  
   147        - name: Build background Xray on Windows 
   148          if: matrix.goos == 'windows'
   149          run: |
   150            go build -v -o build_assets/wxray.exe -trimpath -ldflags "-s -w -H windowsgui -buildid=" ./main
   151      
   152        - name: Build Mips softfloat Xray
   153          if: matrix.goarch == 'mips' || matrix.goarch == 'mipsle'
   154          run: |
   155            GOMIPS=softfloat go build -v -o build_assets/xray_softfloat -trimpath -ldflags "-s -w -buildid=" ./main
   156  
   157        - name: Rename Windows Xray
   158          if: matrix.goos == 'windows'
   159          run: |
   160            cd ./build_assets || exit 1
   161            mv xray xray.exe
   162  
   163        - name: Prepare to release
   164          run: |
   165            cp ${GITHUB_WORKSPACE}/README.md ./build_assets/README.md
   166            cp ${GITHUB_WORKSPACE}/LICENSE ./build_assets/LICENSE
   167            LIST=('geoip geoip geoip' 'domain-list-community dlc geosite')
   168            for i in "${LIST[@]}"
   169            do
   170              INFO=($(echo $i | awk 'BEGIN{FS=" ";OFS=" "} {print $1,$2,$3}'))
   171              LASTEST_TAG="$(curl -sL "https://api.github.com/repos/v2fly/${INFO[0]}/releases" | jq -r ".[0].tag_name" || echo "latest")"
   172              FILE_NAME="${INFO[2]}.dat"
   173              echo -e "Downloading ${FILE_NAME}..."
   174              curl -L "https://github.com/v2fly/${INFO[0]}/releases/download/${LASTEST_TAG}/${INFO[1]}.dat" -o ./build_assets/${FILE_NAME}
   175              echo -e "Verifying HASH key..."
   176              HASH="$(curl -sL "https://github.com/v2fly/${INFO[0]}/releases/download/${LASTEST_TAG}/${INFO[1]}.dat.sha256sum" | awk -F ' ' '{print $1}')"
   177              [ "$(sha256sum "./build_assets/${FILE_NAME}" | awk -F ' ' '{print $1}')" == "${HASH}" ] || { echo -e "The HASH key of ${FILE_NAME} does not match cloud one."; exit 1; }
   178            done
   179  
   180        - name: Create ZIP archive
   181          shell: bash
   182          run: |
   183            pushd build_assets || exit 1
   184            touch -mt $(date +%Y01010000) *
   185            zip -9vr ../Xray-${{ env.ASSET_NAME }}.zip .
   186            popd || exit 1
   187            FILE=./Xray-${{ env.ASSET_NAME }}.zip
   188            DGST=$FILE.dgst
   189            for METHOD in {"md5","sha1","sha256","sha512"}
   190            do
   191              openssl dgst -$METHOD $FILE | sed 's/([^)]*)//g' >>$DGST
   192            done
   193  
   194        - name: Change the name
   195          run: |
   196            mv build_assets Xray-${{ env.ASSET_NAME }}
   197  
   198        - name: Upload files to Artifacts
   199          uses: actions/upload-artifact@v3
   200          with:
   201            name: Xray-${{ env.ASSET_NAME }}
   202            path: |
   203              ./Xray-${{ env.ASSET_NAME }}/*
   204  
   205        - name: Upload binaries to release
   206          uses: svenstaro/upload-release-action@v2
   207          if: github.event_name == 'release'
   208          with:
   209            repo_token: ${{ secrets.GITHUB_TOKEN }}
   210            file: ./Xray-${{ env.ASSET_NAME }}.zip*
   211            tag: ${{ github.ref }}
   212            file_glob: true