Build latest Xray with V2Root #44
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build latest Xray with V2Root | |
| on: | |
| schedule: | |
| - cron: "17 2 * * *" | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| concurrency: | |
| group: release-latest-xray | |
| cancel-in-progress: false | |
| jobs: | |
| discover: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| should_build: ${{ steps.release.outputs.should_build }} | |
| xray_tag: ${{ steps.release.outputs.xray_tag }} | |
| release_tag: ${{ steps.release.outputs.release_tag }} | |
| build_code_version: ${{ steps.release.outputs.build_code_version }} | |
| build_time_tehran: ${{ steps.release.outputs.build_time_tehran }} | |
| telegram_message_id: ${{ steps.telegram.outputs.message_id }} | |
| steps: | |
| - name: Check out notification tooling | |
| uses: actions/checkout@v4 | |
| - name: Find latest stable Xray release | |
| id: release | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| xray_tag="$( | |
| gh api repos/XTLS/Xray-core/releases/latest --jq '.tag_name' | |
| )" | |
| release_tag="v2root-${xray_tag}" | |
| should_build=true | |
| if gh api "repos/${GITHUB_REPOSITORY}/releases/tags/${release_tag}" \ | |
| >/dev/null 2>&1; then | |
| should_build=false | |
| fi | |
| build_time_tehran="$(TZ=Asia/Tehran date '+%Y-%m-%d %H:%M:%S %z')" | |
| build_code_version="$GITHUB_RUN_NUMBER" | |
| { | |
| echo "xray_tag=$xray_tag" | |
| echo "release_tag=$release_tag" | |
| echo "should_build=$should_build" | |
| echo "build_code_version=$build_code_version" | |
| echo "build_time_tehran=$build_time_tehran" | |
| } >> "$GITHUB_OUTPUT" | |
| echo "Latest Xray: $xray_tag" | |
| echo "V2Root release: $release_tag" | |
| echo "Build required: $should_build" | |
| - name: Send Telegram start notification | |
| id: telegram | |
| env: | |
| TG_TOKEN_BOT: ${{ secrets.TG_TOKEN_BOT }} | |
| TG_CHAT_ID: ${{ secrets.TG_CHAT_ID }} | |
| XRAY_TAG: ${{ steps.release.outputs.xray_tag }} | |
| RELEASE_TAG: ${{ steps.release.outputs.release_tag }} | |
| SHOULD_BUILD: ${{ steps.release.outputs.should_build }} | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| if [[ "$SHOULD_BUILD" == "true" ]]; then | |
| status="New Xray version found; build is starting" | |
| else | |
| status="Skipped; this Xray version already has a release" | |
| fi | |
| text="V2Root release check | |
| Repository: ${GITHUB_REPOSITORY} | |
| Xray: ${XRAY_TAG} | |
| Release: ${RELEASE_TAG} | |
| Run: #${GITHUB_RUN_NUMBER} | |
| Trigger: ${GITHUB_EVENT_NAME} | |
| Status: ${status} | |
| ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}" | |
| message_id="$( | |
| python3 scripts/telegram_notify.py send --text "$text" | |
| )" | |
| echo "message_id=$message_id" >> "$GITHUB_OUTPUT" | |
| build: | |
| needs: discover | |
| if: needs.discover.outputs.should_build == 'true' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Check out V2Root sources | |
| uses: actions/checkout@v4 | |
| with: | |
| path: v2root-core | |
| - name: Update Telegram build status | |
| env: | |
| TG_TOKEN_BOT: ${{ secrets.TG_TOKEN_BOT }} | |
| TG_CHAT_ID: ${{ secrets.TG_CHAT_ID }} | |
| shell: bash | |
| run: | | |
| python3 v2root-core/scripts/telegram_notify.py edit \ | |
| --message-id "${{ needs.discover.outputs.telegram_message_id }}" \ | |
| --text "V2Root build in progress | |
| Xray: ${{ needs.discover.outputs.xray_tag }} | |
| Release: ${{ needs.discover.outputs.release_tag }} | |
| Status: compiling Linux and Windows targets | |
| Run: ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}" | |
| - name: Check out Xray source | |
| uses: actions/checkout@v4 | |
| with: | |
| repository: XTLS/Xray-core | |
| ref: ${{ needs.discover.outputs.xray_tag }} | |
| path: xray-core | |
| fetch-depth: 1 | |
| - name: Set up Go from Xray go.mod | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version-file: xray-core/go.mod | |
| cache-dependency-path: xray-core/go.sum | |
| - name: Install cross compilers and packaging tools | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install --yes --no-install-recommends \ | |
| gcc-aarch64-linux-gnu \ | |
| gcc-i686-linux-gnu \ | |
| libc6-dev-arm64-cross \ | |
| libc6-dev-i386-cross \ | |
| mingw-w64 | |
| - name: Add V2Root package to Xray | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| rm -rf xray-core/v2root | |
| cp -R v2root-core/v2root xray-core/v2root | |
| - name: Build all supported shared libraries | |
| working-directory: xray-core | |
| env: | |
| CGO_ENABLED: "1" | |
| BUILD_VERSION: ${{ needs.discover.outputs.xray_tag }} | |
| BUILD_RELEASE_DATE: ${{ needs.discover.outputs.build_time_tehran }} | |
| BUILD_CODE_VERSION: ${{ needs.discover.outputs.build_code_version }} | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| exec > >(tee -a ../v2root-core-build.log) 2>&1 | |
| echo "V2Root complete build log" | |
| echo "Run ID: ${GITHUB_RUN_ID}" | |
| echo "Commit: ${GITHUB_SHA}" | |
| echo "Xray: ${BUILD_VERSION}" | |
| echo "Release date Tehran: ${BUILD_RELEASE_DATE}" | |
| echo "Code version: ${BUILD_CODE_VERSION}" | |
| go version | |
| mkdir -p dist | |
| build_ldflags="-s -w \ | |
| -X 'main.version=${BUILD_VERSION}' \ | |
| -X 'main.releaseDate=${BUILD_RELEASE_DATE}' \ | |
| -X 'main.buildCodeVersion=${BUILD_CODE_VERSION}'" | |
| GOOS=linux GOARCH=amd64 \ | |
| go build -trimpath -buildmode=c-shared \ | |
| -ldflags="$build_ldflags" -o dist/xray-linux-amd64.so ./v2root | |
| GOOS=linux GOARCH=arm64 CC=aarch64-linux-gnu-gcc \ | |
| go build -trimpath -buildmode=c-shared \ | |
| -ldflags="$build_ldflags" -o dist/xray-linux-arm64.so ./v2root | |
| GOOS=linux GOARCH=386 CC=i686-linux-gnu-gcc \ | |
| go build -trimpath -buildmode=c-shared \ | |
| -ldflags="$build_ldflags" -o dist/xray-linux-386.so ./v2root | |
| GOOS=windows GOARCH=amd64 CC=x86_64-w64-mingw32-gcc \ | |
| go build -trimpath -buildmode=c-shared \ | |
| -ldflags="$build_ldflags" -o dist/xray-windows-amd64.dll ./v2root | |
| GOOS=windows GOARCH=386 CC=i686-w64-mingw32-gcc \ | |
| go build -trimpath -buildmode=c-shared \ | |
| -ldflags="$build_ldflags" -o dist/xray-windows-386.dll ./v2root | |
| - name: Exercise every exported API function | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| python3 v2root-core/tests/smoke_shared_library.py \ | |
| xray-core/dist/xray-linux-amd64.so \ | |
| --expected-version "${{ needs.discover.outputs.xray_tag }}" \ | |
| --expected-release-date "${{ needs.discover.outputs.build_time_tehran }}" \ | |
| --expected-code-version "${{ needs.discover.outputs.build_code_version }}" \ | |
| 2>&1 | tee -a v2root-core-build.log | |
| - name: Verify Windows export tables | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| python3 v2root-core/tests/verify_windows_exports.py \ | |
| xray-core/dist/xray-windows-amd64.dll \ | |
| 2>&1 | tee -a v2root-core-build.log | |
| OBJDUMP=i686-w64-mingw32-objdump \ | |
| python3 v2root-core/tests/verify_windows_exports.py \ | |
| xray-core/dist/xray-windows-386.dll \ | |
| 2>&1 | tee -a v2root-core-build.log | |
| - name: Package platform archives and checksums | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| python3 v2root-core/scripts/package_release.py \ | |
| --dist xray-core/dist \ | |
| --version "${{ needs.discover.outputs.xray_tag }}" \ | |
| 2>&1 | tee -a v2root-core-build.log | |
| - name: Validate release artifacts | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| python3 v2root-core/tests/validate_release_artifacts.py \ | |
| --dist xray-core/dist \ | |
| --version "${{ needs.discover.outputs.xray_tag }}" \ | |
| 2>&1 | tee -a v2root-core-build.log | |
| - name: Upload complete build log | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: build-log-${{ github.run_id }} | |
| path: v2root-core-build.log | |
| if-no-files-found: warn | |
| - name: Upload build artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: v2root-${{ needs.discover.outputs.xray_tag }} | |
| path: xray-core/dist/*.zip | |
| if-no-files-found: error | |
| release: | |
| needs: [discover, build] | |
| if: needs.discover.outputs.should_build == 'true' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Check out repository | |
| uses: actions/checkout@v4 | |
| - name: Download build artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: v2root-${{ needs.discover.outputs.xray_tag }} | |
| path: dist | |
| - name: Update README release metadata | |
| env: | |
| XRAY_TAG: ${{ needs.discover.outputs.xray_tag }} | |
| RELEASE_TAG: ${{ needs.discover.outputs.release_tag }} | |
| TZ: Asia/Tehran | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| python3 scripts/update_release_metadata.py \ | |
| --xray-version "$XRAY_TAG" \ | |
| --release-tag "$RELEASE_TAG" \ | |
| --build-time-tehran "${{ needs.discover.outputs.build_time_tehran }}" | |
| if ! git diff --quiet -- README.md; then | |
| git config user.name "v2rayroot" | |
| git config user.email "v2rayroot@users.noreply.github.com" | |
| git add README.md | |
| git commit -m "docs: record ${RELEASE_TAG} build" | |
| git push | |
| fi | |
| - name: Publish GitHub release | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| RELEASE_TAG: ${{ needs.discover.outputs.release_tag }} | |
| XRAY_TAG: ${{ needs.discover.outputs.xray_tag }} | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| notes="$( | |
| cat <<EOF | |
| Automated V2Root shared-library build based on XTLS/Xray-core ${XRAY_TAG}. | |
| Upstream source: https://github.com/XTLS/Xray-core/releases/tag/${XRAY_TAG} | |
| EOF | |
| )" | |
| gh release create "$RELEASE_TAG" dist/*.zip \ | |
| --repo "$GITHUB_REPOSITORY" \ | |
| --title "V2Root for Xray ${XRAY_TAG}" \ | |
| --notes "$notes" \ | |
| --latest | |
| telegram: | |
| needs: [discover, build, release] | |
| if: always() && needs.discover.result == 'success' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Check out notification tooling | |
| uses: actions/checkout@v4 | |
| - name: Download complete build log | |
| uses: actions/download-artifact@v4 | |
| continue-on-error: true | |
| with: | |
| name: build-log-${{ github.run_id }} | |
| path: telegram-report | |
| - name: Build final workflow report | |
| env: | |
| DISCOVER_RESULT: ${{ needs.discover.result }} | |
| BUILD_RESULT: ${{ needs.build.result }} | |
| RELEASE_RESULT: ${{ needs.release.result }} | |
| SHOULD_BUILD: ${{ needs.discover.outputs.should_build }} | |
| XRAY_TAG: ${{ needs.discover.outputs.xray_tag }} | |
| RELEASE_TAG: ${{ needs.discover.outputs.release_tag }} | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| mkdir -p telegram-report | |
| report="telegram-report/V2Root-${GITHUB_RUN_ID}-complete.log" | |
| { | |
| echo "V2Root complete workflow report" | |
| echo "Repository: ${GITHUB_REPOSITORY}" | |
| echo "Run ID: ${GITHUB_RUN_ID}" | |
| echo "Run number: ${GITHUB_RUN_NUMBER}" | |
| echo "Commit: ${GITHUB_SHA}" | |
| echo "Event: ${GITHUB_EVENT_NAME}" | |
| echo "Actor: ${GITHUB_ACTOR}" | |
| echo "Xray version: ${XRAY_TAG}" | |
| echo "Release tag: ${RELEASE_TAG}" | |
| echo "Build required: ${SHOULD_BUILD}" | |
| echo "Discover: ${DISCOVER_RESULT}" | |
| echo "Build and tests: ${BUILD_RESULT}" | |
| echo "Release: ${RELEASE_RESULT}" | |
| echo "Run URL: ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}" | |
| echo | |
| echo "===== BUILD OUTPUT =====" | |
| if [[ -f telegram-report/v2root-core-build.log ]]; then | |
| cat telegram-report/v2root-core-build.log | |
| else | |
| echo "Build output artifact was not available." | |
| fi | |
| } > "$report" | |
| - name: Edit Telegram status and send full report | |
| env: | |
| TG_TOKEN_BOT: ${{ secrets.TG_TOKEN_BOT }} | |
| TG_CHAT_ID: ${{ secrets.TG_CHAT_ID }} | |
| BUILD_RESULT: ${{ needs.build.result }} | |
| RELEASE_RESULT: ${{ needs.release.result }} | |
| SHOULD_BUILD: ${{ needs.discover.outputs.should_build }} | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| if [[ "$SHOULD_BUILD" != "true" ]]; then | |
| status="SKIPPED - release already exists" | |
| elif [[ "$BUILD_RESULT" == "success" && "$RELEASE_RESULT" == "success" ]]; then | |
| status="SUCCESS" | |
| else | |
| status="FAILED" | |
| fi | |
| text="V2Root workflow ${status} | |
| Xray: ${{ needs.discover.outputs.xray_tag }} | |
| Release: ${{ needs.discover.outputs.release_tag }} | |
| Build/tests: ${BUILD_RESULT} | |
| Release: ${RELEASE_RESULT} | |
| Run: ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}" | |
| python3 scripts/telegram_notify.py edit \ | |
| --message-id "${{ needs.discover.outputs.telegram_message_id }}" \ | |
| --text "$text" | |
| python3 scripts/telegram_notify.py document \ | |
| --path "telegram-report/V2Root-${GITHUB_RUN_ID}-complete.log" \ | |
| --caption "Complete V2Root workflow log: ${{ needs.discover.outputs.release_tag }}" |