github.com/xraypb/Xray-core@v1.8.1/.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@v3 28 with: 29 path: resources 30 key: xray-geodat- 31 32 - name: Update Geodat 33 id: update 34 uses: nick-fields/retry@v2 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@v3 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: [windows, freebsd, openbsd, linux, dragonfly, darwin] 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 # BEIGIN MacOS ARM64 83 - goos: darwin 84 goarch: arm64 85 # END MacOS ARM64 86 # BEGIN Linux ARM 5 6 7 87 - goos: linux 88 goarch: arm 89 goarm: 7 90 - goos: linux 91 goarch: arm 92 goarm: 6 93 - goos: linux 94 goarch: arm 95 goarm: 5 96 # END Linux ARM 5 6 7 97 # BEGIN Android ARM 8 98 - goos: android 99 goarch: arm64 100 # END Android ARM 8 101 # Windows ARM 102 - goos: windows 103 goarch: arm64 104 - goos: windows 105 goarch: arm 106 goarm: 7 107 # BEGIN Other architectures 108 # BEGIN riscv64 & ARM64 109 - goos: linux 110 goarch: arm64 111 - goos: linux 112 goarch: riscv64 113 # END riscv64 & ARM64 114 # BEGIN MIPS 115 - goos: linux 116 goarch: mips64 117 - goos: linux 118 goarch: mips64le 119 - goos: linux 120 goarch: mipsle 121 - goos: linux 122 goarch: mips 123 # END MIPS 124 # BEGIN PPC 125 - goos: linux 126 goarch: ppc64 127 - goos: linux 128 goarch: ppc64le 129 # END PPC 130 # BEGIN FreeBSD ARM 131 - goos: freebsd 132 goarch: arm64 133 - goos: freebsd 134 goarch: arm 135 goarm: 7 136 # END FreeBSD ARM 137 # BEGIN S390X 138 - goos: linux 139 goarch: s390x 140 # END S390X 141 # END Other architectures 142 # BEGIN OPENBSD ARM 143 - goos: openbsd 144 goarch: arm64 145 - goos: openbsd 146 goarch: arm 147 goarm: 7 148 # END OPENBSD ARM 149 fail-fast: false 150 151 runs-on: ubuntu-latest 152 env: 153 GOOS: ${{ matrix.goos }} 154 GOARCH: ${{ matrix.goarch }} 155 GOARM: ${{ matrix.goarm }} 156 CGO_ENABLED: 0 157 steps: 158 - name: Checkout codebase 159 uses: actions/checkout@v3 160 161 - name: Show workflow information 162 run: | 163 export _NAME=$(jq ".[\"$GOOS-$GOARCH$GOARM$GOMIPS\"].friendlyName" -r < .github/build/friendly-filenames.json) 164 echo "GOOS: $GOOS, GOARCH: $GOARCH, GOARM: $GOARM, GOMIPS: $GOMIPS, RELEASE_NAME: $_NAME" 165 echo "ASSET_NAME=$_NAME" >> $GITHUB_ENV 166 167 - name: Set up Go 168 uses: actions/setup-go@v4 169 with: 170 go-version: '1.20' 171 check-latest: true 172 173 - name: Get project dependencies 174 run: go mod download 175 176 - name: Replace Custom to Commit ID 177 if: github.event_name != 'release' 178 run: | 179 ID=$(git rev-parse --short ${{ github.sha }}) 180 if [ "${{ github.event_name }}" == 'pull_request' ] 181 then 182 ID=$(git rev-parse --short ${{ github.event.pull_request.head.sha }}) 183 fi 184 sed -i '/build/ s/Custom/'$ID'/' ./core/core.go 185 186 - name: Build Xray 187 run: | 188 mkdir -p build_assets 189 go build -v -o build_assets/xray -trimpath -ldflags "-s -w -buildid=" ./main 190 191 - name: Build background Xray on Windows 192 if: matrix.goos == 'windows' 193 run: | 194 go build -v -o build_assets/wxray.exe -trimpath -ldflags "-s -w -H windowsgui -buildid=" ./main 195 196 - name: Build Mips softfloat Xray 197 if: matrix.goarch == 'mips' || matrix.goarch == 'mipsle' 198 run: | 199 GOMIPS=softfloat go build -v -o build_assets/xray_softfloat -trimpath -ldflags "-s -w -buildid=" ./main 200 201 - name: Rename Windows Xray 202 if: matrix.goos == 'windows' 203 run: | 204 cd ./build_assets || exit 1 205 mv xray xray.exe 206 207 - name: Restore Cache 208 uses: actions/cache/restore@v3 209 with: 210 path: resources 211 key: xray-geodat- 212 213 - name: Copy README.md & LICENSE 214 run: | 215 mv -f resources/* build_assets 216 cp ${GITHUB_WORKSPACE}/README.md ./build_assets/README.md 217 cp ${GITHUB_WORKSPACE}/LICENSE ./build_assets/LICENSE 218 219 - name: Create ZIP archive 220 shell: bash 221 run: | 222 pushd build_assets || exit 1 223 touch -mt $(date +%Y01010000) * 224 zip -9vr ../Xray-${{ env.ASSET_NAME }}.zip . 225 popd || exit 1 226 FILE=./Xray-${{ env.ASSET_NAME }}.zip 227 DGST=$FILE.dgst 228 for METHOD in {"md5","sha1","sha256","sha512"} 229 do 230 openssl dgst -$METHOD $FILE | sed 's/([^)]*)//g' >>$DGST 231 done 232 233 - name: Change the name 234 run: | 235 mv build_assets Xray-${{ env.ASSET_NAME }} 236 237 - name: Upload files to Artifacts 238 uses: actions/upload-artifact@v3 239 with: 240 name: Xray-${{ env.ASSET_NAME }} 241 path: | 242 ./Xray-${{ env.ASSET_NAME }}/* 243 244 - name: Upload binaries to release 245 uses: svenstaro/upload-release-action@v2 246 if: github.event_name == 'release' 247 with: 248 repo_token: ${{ secrets.GITHUB_TOKEN }} 249 file: ./Xray-${{ env.ASSET_NAME }}.zip* 250 tag: ${{ github.ref }} 251 file_glob: true