name: Update Go Dependencies on: schedule: - cron: '0 0 * * 1' # Запуск каждую неделю в понедельник в 00:00 UTC workflow_dispatch: # Возможность ручного запуска permissions: contents: write # Явное указание разрешений jobs: update: runs-on: ubuntu-latest # Используем последнюю версию Ubuntu timeout-minutes: 30 # Добавляем таймаут для предотвращения зависания steps: - name: Checkout repository uses: actions/checkout@v4 with: fetch-depth: 0 # Загружаем всю историю token: ${{ secrets.GITHUB_TOKEN }} - name: Setup Go uses: actions/setup-go@v5 with: go-version-file: go.mod check-latest: true cache: true # Включаем кэширование модулей - name: Fetch latest Xray-core release id: get_latest_release run: | # Получаем список релизов API_RESPONSE=$(curl -s https://api.github.com/repos/XTLS/Xray-core/releases) # Извлекаем последний стабильный тег (например, v25.2.21) LATEST_TAG=$(echo "$API_RESPONSE" | jq -r 'map(select(.prerelease == false)) | .[0].tag_name') # Находим конкретный commit SHA для этого тега COMMIT_HASH=$(curl -s "https://api.github.com/repos/XTLS/Xray-core/git/ref/tags/${LATEST_TAG}" | jq -r .object.sha) # Генерируем псевдоверсию Go (v1.8.25-0.-) GO_VERSION="v1.8.25-0.$(date -u +%Y%m%d%H%M%S)-$COMMIT_HASH" echo "Latest release: $LATEST_TAG (commit: $COMMIT_HASH, go version: $GO_VERSION)" echo "latest_tag=$LATEST_TAG" >> $GITHUB_ENV echo "commit_hash=$COMMIT_HASH" >> $GITHUB_ENV echo "go_version=$GO_VERSION" >> $GITHUB_ENV - name: Check go.mod and go.sum exist run: | if [ ! -f go.mod ]; then echo "Error: go.mod file not found" exit 1 fi # Проверка наличия go.sum и создание, если отсутствует if [ ! -f go.sum ]; then echo "go.sum file not found, initializing it..." go mod tidy fi - name: Clean Go module cache run: | go clean -modcache go clean -cache - name: Update dependencies id: update run: | set -euo pipefail # Строгий режим для bash echo "Updating standard Go dependencies..." go list -f '{{if not (or .Main .Indirect)}}{{.Path}}{{end}}' -m all | \ grep -v 'gvisor.dev/gvisor' | \ grep -v 'github.com/mymmrac/telego' | \ grep -v 'github.com/xtls/xray-core' | \ xargs -r go get -u echo "Updating Xray-core to release ${{ env.latest_tag }} (Go version: ${{ env.go_version }})" go get github.com/xtls/xray-core@${{ env.commit_hash }} echo "Updated Xray-core to:" go list -m github.com/xtls/xray-core go mod tidy go mod verify || exit 1 echo "Updated dependencies:" go list -m all - name: Check for changes id: check run: | if git diff --quiet go.mod go.sum; then echo "changes=false" >> $GITHUB_OUTPUT echo "No changes detected in dependencies" else echo "changes=true" >> $GITHUB_OUTPUT echo "Changes detected in dependencies:" git diff go.mod || true fi - name: Commit and push changes if: steps.check.outputs.changes == 'true' run: | git config --global user.name "github-actions[bot]" git config --global user.email "github-actions[bot]@users.noreply.github.com" git add go.mod go.sum git commit -m "chore(deps): update Go dependencies Automated update of Go dependencies including xray-core to latest release ${{ env.latest_tag }}" # Попытка push с повторами при ошибках max_attempts=3 attempt=1 while [ $attempt -le $max_attempts ]; do if git push origin ${{ github.ref }}; then echo "Successfully pushed changes on attempt $attempt" break else if [ $attempt -eq $max_attempts ]; then echo "Failed to push after $max_attempts attempts" exit 1 fi echo "Push failed on attempt $attempt, retrying..." attempt=$((attempt + 1)) git pull --rebase sleep 5 fi done