github.com/xmplusdev/xray-core@v1.8.10/.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    prepare:
    24      runs-on: ubuntu-latest
    25      steps:
    26        - name: Restore Cache
    27          uses: actions/cache/restore@v4
    28          with:
    29            path: resources
    30            key: xray-geodat-
    31  
    32        - name: Update Geodat
    33          id: update
    34          uses: nick-fields/retry@v3
    35          with:
    36            timeout_minutes: 60
    37            retry_wait_seconds: 60
    38            max_attempts: 60
    39            command: |
    40              [ -d 'resources' ] || mkdir resources
    41              LIST=('geoip geoip geoip' 'domain-list-community dlc geosite')
    42              for i in "${LIST[@]}"
    43              do
    44                INFO=($(echo $i | awk 'BEGIN{FS=" ";OFS=" "} {print $1,$2,$3}'))
    45                FILE_NAME="${INFO[2]}.dat"
    46                echo -e "Verifying HASH key..."
    47                HASH="$(curl -sL "https://raw.githubusercontent.com/v2fly/${INFO[0]}/release/${INFO[1]}.dat.sha256sum" | awk -F ' ' '{print $1}')"
    48                if [ -s "./resources/${FILE_NAME}" ] && [ "$(sha256sum "./resources/${FILE_NAME}" | awk -F ' ' '{print $1}')" == "${HASH}" ]; then
    49                    continue
    50                else
    51                    echo -e "Downloading https://raw.githubusercontent.com/v2fly/${INFO[0]}/release/${INFO[1]}.dat..."
    52                    curl -L "https://raw.githubusercontent.com/v2fly/${INFO[0]}/release/${INFO[1]}.dat" -o ./resources/${FILE_NAME}
    53                    echo -e "Verifying HASH key..."
    54                    [ "$(sha256sum "./resources/${FILE_NAME}" | awk -F ' ' '{print $1}')" == "${HASH}" ] || { echo -e "The HASH key of ${FILE_NAME} does not match cloud one."; exit 1; }
    55                    echo "unhit=true" >> $GITHUB_OUTPUT
    56                fi
    57              done
    58  
    59        - name: Save Cache
    60          uses: actions/cache/save@v4
    61          if: ${{ steps.update.outputs.unhit }}
    62          with:
    63            path: resources
    64            key: xray-geodat-${{ github.sha }}-${{ github.run_number }}
    65  
    66    build:
    67      needs: prepare
    68      permissions:
    69        contents: write
    70      strategy:
    71        matrix:
    72          # Include amd64 on all platforms.
    73          goos: [linux]
    74          goarch: [amd64, 386]
    75          exclude:
    76            # Exclude i386 on darwin and dragonfly.
    77            - goarch: 386
    78              goos: dragonfly
    79            - goarch: 386
    80              goos: darwin
    81          include:
    82            # END MacOS ARM64
    83            # BEGIN Linux ARM 5 6 7
    84            - goos: linux
    85              goarch: arm
    86              goarm: 7
    87            - goos: linux
    88              goarch: arm
    89              goarm: 6
    90            - goos: linux
    91              goarch: arm
    92              goarm: 5
    93            # END Linux ARM 5 6 7
    94        fail-fast: false
    95  
    96      runs-on: ubuntu-latest
    97      env:
    98        GOOS: ${{ matrix.goos }}
    99        GOARCH: ${{ matrix.goarch }}
   100        GOARM: ${{ matrix.goarm }}
   101        CGO_ENABLED: 0
   102      steps:
   103        - name: Checkout codebase
   104          uses: actions/checkout@v4
   105  
   106        - name: Show workflow information 
   107          run: |
   108            export _NAME=$(jq ".[\"$GOOS-$GOARCH$GOARM$GOMIPS\"].friendlyName" -r < .github/build/friendly-filenames.json)
   109            echo "GOOS: $GOOS, GOARCH: $GOARCH, GOARM: $GOARM, GOMIPS: $GOMIPS, RELEASE_NAME: $_NAME"
   110            echo "ASSET_NAME=$_NAME" >> $GITHUB_ENV
   111  
   112        - name: Set up Go
   113          uses: actions/setup-go@v5
   114          with:
   115            go-version-file: go.mod
   116            check-latest: true
   117  
   118        - name: Get project dependencies
   119          run: go mod download
   120        
   121        - name: Build Xray
   122          run: |
   123            mkdir -p build_assets
   124            make
   125            find . -maxdepth 1 -type f -regex '.*\(wxray\|xray\|xray_softfloat\)\(\|.exe\)' -exec mv {} ./build_assets/ \;
   126  
   127        - name: Restore Cache
   128          uses: actions/cache/restore@v4
   129          with:
   130            path: resources
   131            key: xray-geodat-
   132  
   133        - name: Create ZIP archive
   134          shell: bash
   135          run: |
   136            pushd build_assets || exit 1
   137            touch -mt $(date +%Y01010000) *
   138            zip -9vr ../Xray-${{ env.ASSET_NAME }}.zip .
   139            popd || exit 1
   140            FILE=./Xray-${{ env.ASSET_NAME }}.zip
   141            DGST=$FILE.dgst
   142            for METHOD in {"md5","sha1","sha256","sha512"}
   143            do
   144              openssl dgst -$METHOD $FILE | sed 's/([^)]*)//g' >>$DGST
   145            done
   146  
   147        - name: Change the name
   148          run: |
   149            mv build_assets Xray-${{ env.ASSET_NAME }}
   150  
   151        - name: Upload files to Artifacts
   152          uses: actions/upload-artifact@v4
   153          with:
   154            name: Xray-${{ env.ASSET_NAME }}
   155            path: |
   156              ./Xray-${{ env.ASSET_NAME }}/*
   157  
   158        - name: Upload binaries to release
   159          uses: svenstaro/upload-release-action@v2
   160          if: github.event_name == 'release'
   161          with:
   162            repo_token: ${{ secrets.GITHUB_TOKEN }}
   163            file: ./Xray-${{ env.ASSET_NAME }}.zip*
   164            tag: ${{ github.ref }}
   165            file_glob: true