diff --git a/.github/workflows/update-dependencies.yml b/.github/workflows/update-dependencies.yml index 17879ac9..78840775 100644 --- a/.github/workflows/update-dependencies.yml +++ b/.github/workflows/update-dependencies.yml @@ -1,113 +1,82 @@ name: Update Go Dependencies + on: schedule: - - cron: '0 0 * * 1' # Запуск каждую неделю в понедельник в 00:00 UTC - workflow_dispatch: # Возможность ручного запуска + - cron: '0 0 * * 1' + workflow_dispatch: + permissions: - contents: write # Явное указание разрешений + contents: write + jobs: update: - runs-on: ubuntu-latest # Используем последнюю версию Ubuntu - - timeout-minutes: 30 # Добавляем таймаут для предотвращения зависания + runs-on: ubuntu-latest + timeout-minutes: 30 + steps: - name: Checkout repository uses: actions/checkout@v4 with: - fetch-depth: 0 # Загружаем всю историю + 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: Check go.mod and go.sum exist + cache: true + + - name: Install coreutils + run: sudo apt-get install -y coreutils + + - name: Check and initialize go.mod run: | - if [ ! -f go.mod ]; then - echo "Error: go.mod file not found" - exit 1 - fi - - # Проверка наличия go.sum и создание, если отсутствует + [ -f go.mod ] || (echo "Error: go.mod not found" && exit 1) if [ ! -f go.sum ]; then - echo "go.sum file not found, initializing it..." + echo "Initializing go.sum..." go mod tidy fi + - name: Clean Go module cache - run: | - go clean -modcache - go clean -cache + run: go clean -modcache && go clean -cache + - name: Update dependencies id: update run: | - set -euo pipefail # Строгий режим для bash - - echo "Updating standard Go dependencies..." - - # Обновляем стандартные зависимости с исключением gvisor - go list -f '{{if not (or .Main .Indirect)}}{{.Path}}{{end}}' -m all | \ - grep -v 'gvisor.dev/gvisor' | \ - grep -v 'github.com/xtls/xray-core' | \ - xargs -r go get -u - - echo "Specifically updating xray-core to latest release..." - # Получаем последний тег релиза - LATEST_RELEASE=$(curl -s https://api.github.com/repos/xtls/xray-core/releases/latest | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/') - - # Обновляем xray-core с учетом мажорной версии - go get github.com/xtls/xray-core/v25@$LATEST_RELEASE - - # Проверяем, какую версию получили - echo "Updated xray-core to:" - go list -m github.com/xtls/xray-core/v25 - + set -euo pipefail + + # Обновляем стандартные зависимости + go list -f '{{if not (or .Main .Indirect)}}{{.Path}}{{end}}' -m all \ + | grep -v -e 'gvisor.dev/gvisor' -e 'github.com/xtls/xray-core' \ + | xargs -r go get -u + + # Получаем последний релизный тег через GitHub API + release_info=$(curl -s https://api.github.com/repos/xtls/xray-core/releases/latest) + tag_name=$(echo "$release_info" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/') + + # Обновляем xray-core/v25 до последнего релизного тега + go get github.com/xtls/xray-core/v25@$tag_name + # Очистка и проверка go mod tidy - go mod verify || exit 1 - - # Выводим изменения для лога - echo "Updated dependencies:" - go list -m all + go mod verify + - 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:" - # Добавляем || true чтобы предотвратить код ошибки, если grep ничего не находит - git diff go.mod || true + git diff go.mod 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 config --global user.email "41898282+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 stable version" - - # Попытка 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 + git commit -m "chore(deps): update xray-core/v25 to $tag_name" + git push origin HEAD:${{ github.ref }}