From 31162d44bd6af57c40e1212591ad4897dad5a1cf Mon Sep 17 00:00:00 2001 From: Mykola Baibuz Date: Sat, 20 Jan 2024 07:57:42 -0500 Subject: [PATCH] Build binaries for Xray protocol [xray] [tun2socks] --- .github/workflows/build_tun2socks.yml | 79 +++++++++ .github/workflows/build_xray.yml | 239 ++++++++++++++++++++++++++ 2 files changed, 318 insertions(+) create mode 100644 .github/workflows/build_tun2socks.yml create mode 100644 .github/workflows/build_xray.yml diff --git a/.github/workflows/build_tun2socks.yml b/.github/workflows/build_tun2socks.yml new file mode 100644 index 0000000..28ffa27 --- /dev/null +++ b/.github/workflows/build_tun2socks.yml @@ -0,0 +1,79 @@ +name: Build Tun2Socks + +on: [push] + +jobs: + Build-Tun2Socks: + permissions: + contents: write + runs-on: ubuntu-latest + if: | + contains(github.event.head_commit.message, '[all]') || + contains(github.event.head_commit.message, '[windows]') || + contains(github.event.head_commit.message, '[linux]') || + contains(github.event.head_commit.message, '[macos]') || + contains(github.event.head_commit.message, '[android]') || + contains(github.event.head_commit.message, '[tun2socks]') + + steps: + - name: Checkout codebase + uses: actions/checkout@v4 + + - name: 'Get Tun2Socks' + uses: actions/checkout@v3 + with: + repository: xjasonlyu/tun2socks + ref: main + path: tun2socks + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.21' + check-latest: true + + - name: Get project dependencies + run: | + cd tun2socks + go mod download + + - name: Build Tun2Socks + run: | + cd tun2socks + make -j releases + cd build + unzip \*.zip + rm *.zip + + - name: Upload files to Artifacts + uses: actions/upload-artifact@v4 + with: + name: tun2socks + path: tun2socks/build + + - name: Setup | Checksums + run: for file in $(find ./tun2socks/build -name '*' ); do openssl dgst -sha256 -r "$file" | awk '{print $1}' > "${file}.sha256"; done + + - name: Create ZIP archive + shell: bash + run: | + cd tun2socks + pushd build || exit 1 + touch -mt $(date +%Y01010000) * + zip -9vr ../tun2socks.zip . + popd || exit 1 + FILE=./tun2socks.zip + DGST=$FILE.dgst + for METHOD in {"md5","sha1","sha256","sha512"} + do + openssl dgst -$METHOD $FILE | sed 's/([^)]*)//g' >>$DGST + done + + - name: Upload binaries to release + uses: svenstaro/upload-release-action@v2 + if: startsWith(github.ref, 'refs/tags/') + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: tun2socks/tun2socks.zip* + tag: ${{ github.ref }} + file_glob: true diff --git a/.github/workflows/build_xray.yml b/.github/workflows/build_xray.yml new file mode 100644 index 0000000..92591c5 --- /dev/null +++ b/.github/workflows/build_xray.yml @@ -0,0 +1,239 @@ +name: Build Xray + +on: [push] + +jobs: + Prepare-Xray: + runs-on: ubuntu-latest + if: | + contains(github.event.head_commit.message, '[all]') || + contains(github.event.head_commit.message, '[windows]') || + contains(github.event.head_commit.message, '[linux]') || + contains(github.event.head_commit.message, '[macos]') || + contains(github.event.head_commit.message, '[android]') || + contains(github.event.head_commit.message, '[xray]') + steps: + - name: Restore Cache + uses: actions/cache/restore@v3 + with: + path: resources + key: xray-geodat- + + - name: Update Geodat + id: update + uses: nick-fields/retry@v2 + with: + timeout_minutes: 60 + retry_wait_seconds: 60 + max_attempts: 60 + command: | + [ -d 'resources' ] || mkdir resources + LIST=('geoip geoip geoip' 'domain-list-community dlc geosite') + for i in "${LIST[@]}" + do + INFO=($(echo $i | awk 'BEGIN{FS=" ";OFS=" "} {print $1,$2,$3}')) + FILE_NAME="${INFO[2]}.dat" + echo -e "Verifying HASH key..." + HASH="$(curl -sL "https://raw.githubusercontent.com/v2fly/${INFO[0]}/release/${INFO[1]}.dat.sha256sum" | awk -F ' ' '{print $1}')" + if [ -s "./resources/${FILE_NAME}" ] && [ "$(sha256sum "./resources/${FILE_NAME}" | awk -F ' ' '{print $1}')" == "${HASH}" ]; then + continue + else + echo -e "Downloading https://raw.githubusercontent.com/v2fly/${INFO[0]}/release/${INFO[1]}.dat..." + curl -L "https://raw.githubusercontent.com/v2fly/${INFO[0]}/release/${INFO[1]}.dat" -o ./resources/${FILE_NAME} + echo -e "Verifying HASH key..." + [ "$(sha256sum "./resources/${FILE_NAME}" | awk -F ' ' '{print $1}')" == "${HASH}" ] || { echo -e "The HASH key of ${FILE_NAME} does not match cloud one."; exit 1; } + echo "unhit=true" >> $GITHUB_OUTPUT + fi + done + + - name: Save Cache + uses: actions/cache/save@v3 + if: ${{ steps.update.outputs.unhit }} + with: + path: resources + key: xray-geodat-${{ github.sha }}-${{ github.run_number }} + + Build-Xray: + needs: Prepare-Xray + permissions: + contents: write + strategy: + matrix: + # Include amd64 on all platforms. + goos: [windows, linux, darwin] + goarch: [amd64, 386] + exclude: + # Exclude i386 on darwin + - goarch: 386 + goos: darwin + include: + # BEIGIN MacOS ARM64 + - goos: darwin + goarch: arm64 + # END MacOS ARM64 + # BEGIN Linux ARM 5 6 7 + # - goos: linux + # goarch: arm + # goarm: 7 + # - goos: linux + # goarch: arm + # goarm: 6 + # - goos: linux + # goarch: arm + # goarm: 5 + # END Linux ARM 5 6 7 + # BEGIN Android ARM 8 + - goos: android + goarch: arm64 + # END Android ARM 8 + # Windows ARM + #- goos: windows + # goarch: arm64 + # - goos: windows + # goarch: arm + # goarm: 7 + # BEGIN Other architectures + # BEGIN riscv64 & ARM64 & LOONG64 + # - goos: linux + # goarch: arm64 + # - goos: linux + # goarch: riscv64 + # - goos: linux + # goarch: loong64 + # END riscv64 & ARM64 & LOONG64 + # BEGIN MIPS + # - goos: linux + # goarch: mips64 + # - goos: linux + # goarch: mips64le + # - goos: linux + # goarch: mipsle + # - goos: linux + # goarch: mips + # END MIPS + # BEGIN PPC + #- goos: linux + # goarch: ppc64 + # - goos: linux + # goarch: ppc64le + # END PPC + # BEGIN FreeBSD ARM + # - goos: freebsd + # goarch: arm64 + # - goos: freebsd + # goarch: arm + # goarm: 7 + # END FreeBSD ARM + # BEGIN S390X + # - goos: linux + # goarch: s390x + # END S390X + # END Other architectures + # BEGIN OPENBSD ARM + # - goos: openbsd + # goarch: arm64 + # - goos: openbsd + # goarch: arm + # goarm: 7 + # END OPENBSD ARM + fail-fast: false + + runs-on: ubuntu-latest + if: | + contains(github.event.head_commit.message, '[all]') || + contains(github.event.head_commit.message, '[windows]') || + contains(github.event.head_commit.message, '[linux]') || + contains(github.event.head_commit.message, '[macos]') || + contains(github.event.head_commit.message, '[android]') || + contains(github.event.head_commit.message, '[xray]') + env: + GOOS: ${{ matrix.goos }} + GOARCH: ${{ matrix.goarch }} + GOARM: ${{ matrix.goarm }} + CGO_ENABLED: 0 + steps: + - name: Checkout codebase + uses: actions/checkout@v4 + + - name: 'Get Xray-core' + uses: actions/checkout@v3 + with: + repository: XTLS/Xray-core + ref: main + path: xray-core + + - name: Show workflow information + run: | + export _NAME=$(jq ".[\"$GOOS-$GOARCH$GOARM$GOMIPS\"].friendlyName" -r < .github/build/friendly-filenames.json) + echo "GOOS: $GOOS, GOARCH: $GOARCH, GOARM: $GOARM, GOMIPS: $GOMIPS, RELEASE_NAME: $_NAME" + echo "ASSET_NAME=$_NAME" >> $GITHUB_ENV + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.21' + check-latest: true + + - name: Get project dependencies + run: | + cd xray-core + go mod download + + - name: Build Xray + run: | + cd xray-core + mkdir -p build_assets + make + find . -maxdepth 1 -type f -regex '.*\(wxray\|xray\|xray_softfloat\)\(\|.exe\)' -exec mv {} ./build_assets/ \; + + - name: Restore Cache + uses: actions/cache/restore@v3 + with: + path: resources + key: xray-geodat- + + - name: Copy README.md & LICENSE + run: | + cd xray-core + mv -f ../resources/* build_assets + cp ${GITHUB_WORKSPACE}/xray-core/README.md ./build_assets/README.md + cp ${GITHUB_WORKSPACE}/xray-core/LICENSE ./build_assets/LICENSE + + - name: Setup | Checksums + run: for file in $(find ./xray-core/build_assets -name '*' ); do openssl dgst -sha256 -r "$file" | awk '{print $1}' > "${file}.sha256"; done + + - name: Create ZIP archive + shell: bash + run: | + cd xray-core + pushd build_assets || exit 1 + touch -mt $(date +%Y01010000) * + zip -9vr ../Xray-${{ env.ASSET_NAME }}.zip . + popd || exit 1 + FILE=./Xray-${{ env.ASSET_NAME }}.zip + DGST=$FILE.dgst + for METHOD in {"md5","sha1","sha256","sha512"} + do + openssl dgst -$METHOD $FILE | sed 's/([^)]*)//g' >>$DGST + done + + - name: Change the name + run: | + cd xray-core + mv build_assets Xray-${{ env.ASSET_NAME }} + + - name: Upload files to Artifacts + uses: actions/upload-artifact@v4 + with: + name: Xray-${{ env.ASSET_NAME }} + path: | + ./xray-core/Xray-${{ env.ASSET_NAME }}/* + + - name: Upload binaries to release + uses: svenstaro/upload-release-action@v2 + if: startsWith(github.ref, 'refs/tags/') + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: ./xray-core/Xray-${{ env.ASSET_NAME }}.zip* + tag: ${{ github.ref }} + file_glob: true