github.com/xtls/xray-core@v1.8.12-0.20240518155711-3168d27b0bdb/.github/workflows/release.yml (about)

     1  name: Build and Release
     2  
     3  # NOTE: This Github Actions file depends on the Makefile.
     4  #       Building the correct package requires the correct binaries generated by the Makefile. To 
     5  #       ensure the correct output, the Makefile must accept the appropriate input and compile the 
     6  #       correct file with the correct name. If you need to modify this file, please ensure it won't 
     7  #       disrupt the Makefile.
     8  
     9  on:
    10    workflow_dispatch:
    11    release:
    12      types: [published]
    13    push:
    14      branches:
    15        - main
    16      paths:
    17        - "**/*.go"
    18        - "go.mod"
    19        - "go.sum"
    20        - ".github/workflows/*.yml"
    21    pull_request:
    22      types: [opened, synchronize, reopened]
    23      paths:
    24        - "**/*.go"
    25        - "go.mod"
    26        - "go.sum"
    27        - ".github/workflows/*.yml"
    28  jobs:
    29    prepare:
    30      runs-on: ubuntu-latest
    31      steps:
    32        - name: Restore Cache
    33          uses: actions/cache/restore@v4
    34          with:
    35            path: resources
    36            key: xray-geodat-
    37  
    38        - name: Update Geodat
    39          id: update
    40          uses: nick-fields/retry@v3
    41          with:
    42            timeout_minutes: 60
    43            retry_wait_seconds: 60
    44            max_attempts: 60
    45            command: |
    46              [ -d 'resources' ] || mkdir resources
    47              LIST=('geoip geoip geoip' 'domain-list-community dlc geosite')
    48              for i in "${LIST[@]}"
    49              do
    50                INFO=($(echo $i | awk 'BEGIN{FS=" ";OFS=" "} {print $1,$2,$3}'))
    51                FILE_NAME="${INFO[2]}.dat"
    52                echo -e "Verifying HASH key..."
    53                HASH="$(curl -sL "https://raw.githubusercontent.com/v2fly/${INFO[0]}/release/${INFO[1]}.dat.sha256sum" | awk -F ' ' '{print $1}')"
    54                if [ -s "./resources/${FILE_NAME}" ] && [ "$(sha256sum "./resources/${FILE_NAME}" | awk -F ' ' '{print $1}')" == "${HASH}" ]; then
    55                    continue
    56                else
    57                    echo -e "Downloading https://raw.githubusercontent.com/v2fly/${INFO[0]}/release/${INFO[1]}.dat..."
    58                    curl -L "https://raw.githubusercontent.com/v2fly/${INFO[0]}/release/${INFO[1]}.dat" -o ./resources/${FILE_NAME}
    59                    echo -e "Verifying HASH key..."
    60                    [ "$(sha256sum "./resources/${FILE_NAME}" | awk -F ' ' '{print $1}')" == "${HASH}" ] || { echo -e "The HASH key of ${FILE_NAME} does not match cloud one."; exit 1; }
    61                    echo "unhit=true" >> $GITHUB_OUTPUT
    62                fi
    63              done
    64  
    65        - name: Save Cache
    66          uses: actions/cache/save@v4
    67          if: ${{ steps.update.outputs.unhit }}
    68          with:
    69            path: resources
    70            key: xray-geodat-${{ github.sha }}-${{ github.run_number }}
    71  
    72    build:
    73      needs: prepare
    74      permissions:
    75        contents: write
    76      strategy:
    77        matrix:
    78          # Include amd64 on all platforms.
    79          goos: [windows, freebsd, openbsd, linux, darwin]
    80          goarch: [amd64, 386]
    81          exclude:
    82            # Exclude i386 on darwin
    83            - goarch: 386
    84              goos: darwin
    85          include:
    86            # BEIGIN MacOS ARM64
    87            - goos: darwin
    88              goarch: arm64
    89            # END MacOS ARM64
    90            # BEGIN Linux ARM 5 6 7
    91            - goos: linux
    92              goarch: arm
    93              goarm: 7
    94            - goos: linux
    95              goarch: arm
    96              goarm: 6
    97            - goos: linux
    98              goarch: arm
    99              goarm: 5
   100            # END Linux ARM 5 6 7
   101            # BEGIN Android ARM 8
   102            - goos: android
   103              goarch: arm64
   104            # END Android ARM 8
   105            # Windows ARM
   106            - goos: windows
   107              goarch: arm64
   108            - goos: windows
   109              goarch: arm
   110              goarm: 7
   111            # BEGIN Other architectures
   112            # BEGIN riscv64 & ARM64 & LOONG64
   113            - goos: linux
   114              goarch: arm64
   115            - goos: linux
   116              goarch: riscv64
   117            - goos: linux
   118              goarch: loong64
   119            # END riscv64 & ARM64 & LOONG64
   120            # BEGIN MIPS
   121            - goos: linux
   122              goarch: mips64
   123            - goos: linux
   124              goarch: mips64le
   125            - goos: linux
   126              goarch: mipsle
   127            - goos: linux
   128              goarch: mips
   129            # END MIPS
   130            # BEGIN PPC
   131            - goos: linux
   132              goarch: ppc64
   133            - goos: linux
   134              goarch: ppc64le
   135            # END PPC
   136            # BEGIN FreeBSD ARM
   137            - goos: freebsd
   138              goarch: arm64
   139            - goos: freebsd
   140              goarch: arm
   141              goarm: 7
   142            # END FreeBSD ARM
   143            # BEGIN S390X
   144            - goos: linux
   145              goarch: s390x
   146            # END S390X
   147            # END Other architectures
   148            # BEGIN OPENBSD ARM
   149            - goos: openbsd
   150              goarch: arm64
   151            - goos: openbsd
   152              goarch: arm
   153              goarm: 7
   154            # END OPENBSD ARM
   155        fail-fast: false
   156  
   157      runs-on: ubuntu-latest
   158      env:
   159        GOOS: ${{ matrix.goos }}
   160        GOARCH: ${{ matrix.goarch }}
   161        GOARM: ${{ matrix.goarm }}
   162        CGO_ENABLED: 0
   163      steps:
   164        - name: Checkout codebase
   165          uses: actions/checkout@v4
   166  
   167        - name: Show workflow information 
   168          run: |
   169            export _NAME=$(jq ".[\"$GOOS-$GOARCH$GOARM$GOMIPS\"].friendlyName" -r < .github/build/friendly-filenames.json)
   170            echo "GOOS: $GOOS, GOARCH: $GOARCH, GOARM: $GOARM, GOMIPS: $GOMIPS, RELEASE_NAME: $_NAME"
   171            echo "ASSET_NAME=$_NAME" >> $GITHUB_ENV
   172  
   173        - name: Set up Go
   174          uses: actions/setup-go@v5
   175          with:
   176            go-version-file: go.mod
   177            check-latest: true
   178  
   179        - name: Get project dependencies
   180          run: go mod download
   181        
   182        - name: Build Xray
   183          run: |
   184            mkdir -p build_assets
   185            make
   186            find . -maxdepth 1 -type f -regex '.*\(wxray\|xray\|xray_softfloat\)\(\|.exe\)' -exec mv {} ./build_assets/ \;
   187  
   188        - name: Restore Cache
   189          uses: actions/cache/restore@v4
   190          with:
   191            path: resources
   192            key: xray-geodat-
   193  
   194        - name: Copy README.md & LICENSE
   195          run: |
   196            mv -f resources/* build_assets
   197            cp ${GITHUB_WORKSPACE}/README.md ./build_assets/README.md
   198            cp ${GITHUB_WORKSPACE}/LICENSE ./build_assets/LICENSE
   199  
   200        - name: Create ZIP archive
   201          shell: bash
   202          run: |
   203            pushd build_assets || exit 1
   204            touch -mt $(date +%Y01010000) *
   205            zip -9vr ../Xray-${{ env.ASSET_NAME }}.zip .
   206            popd || exit 1
   207            FILE=./Xray-${{ env.ASSET_NAME }}.zip
   208            DGST=$FILE.dgst
   209            for METHOD in {"md5","sha1","sha256","sha512"}
   210            do
   211              openssl dgst -$METHOD $FILE | sed 's/([^)]*)//g' >>$DGST
   212            done
   213  
   214        - name: Change the name
   215          run: |
   216            mv build_assets Xray-${{ env.ASSET_NAME }}
   217  
   218        - name: Upload files to Artifacts
   219          uses: actions/upload-artifact@v4
   220          with:
   221            name: Xray-${{ env.ASSET_NAME }}
   222            path: |
   223              ./Xray-${{ env.ASSET_NAME }}/*
   224  
   225        - name: Upload binaries to release
   226          uses: svenstaro/upload-release-action@v2
   227          if: github.event_name == 'release'
   228          with:
   229            repo_token: ${{ secrets.GITHUB_TOKEN }}
   230            file: ./Xray-${{ env.ASSET_NAME }}.zip*
   231            tag: ${{ github.ref }}
   232            file_glob: true