mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2025-04-19 21:42:24 +00:00
Update update-dependencies.yml
This commit is contained in:
parent
8669b59f6d
commit
72f40564c4
1 changed files with 43 additions and 78 deletions
113
.github/workflows/update-dependencies.yml
vendored
113
.github/workflows/update-dependencies.yml
vendored
|
@ -2,23 +2,22 @@ name: Update Go Dependencies
|
||||||
|
|
||||||
on:
|
on:
|
||||||
schedule:
|
schedule:
|
||||||
- cron: '0 0 * * 1' # Запуск каждую неделю в понедельник в 00:00 UTC
|
- cron: '0 0 * * 1'
|
||||||
workflow_dispatch: # Возможность ручного запуска
|
workflow_dispatch:
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
contents: write # Явное указание разрешений
|
contents: write
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
update:
|
update:
|
||||||
runs-on: ubuntu-latest # Используем последнюю версию Ubuntu
|
runs-on: ubuntu-latest
|
||||||
|
timeout-minutes: 30
|
||||||
timeout-minutes: 30 # Добавляем таймаут для предотвращения зависания
|
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0 # Загружаем всю историю
|
fetch-depth: 0
|
||||||
token: ${{ secrets.GITHUB_TOKEN }}
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
- name: Setup Go
|
- name: Setup Go
|
||||||
|
@ -26,100 +25,66 @@ jobs:
|
||||||
with:
|
with:
|
||||||
go-version-file: go.mod
|
go-version-file: go.mod
|
||||||
check-latest: true
|
check-latest: true
|
||||||
cache: true # Включаем кэширование модулей
|
cache: true
|
||||||
|
|
||||||
- name: Check go.mod and go.sum exist
|
- name: Check go.mod and go.sum exist
|
||||||
run: |
|
run: |
|
||||||
if [ ! -f go.mod ]; then
|
[ -f go.mod ] || (echo "Error: go.mod not found" && exit 1)
|
||||||
echo "Error: go.mod file not found"
|
[ -f go.sum ] || (go mod tidy && echo "Initialized go.sum")
|
||||||
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
|
- name: Clean Go module cache
|
||||||
run: |
|
run: go clean -modcache && go clean -cache
|
||||||
go clean -modcache
|
|
||||||
go clean -cache
|
|
||||||
|
|
||||||
- name: Update dependencies
|
- name: Update dependencies
|
||||||
id: update
|
id: update
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail # Строгий режим для bash
|
set -euo pipefail
|
||||||
|
|
||||||
echo "Updating standard Go dependencies..."
|
# Обновляем стандартные зависимости
|
||||||
|
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
|
||||||
|
|
||||||
# Обновляем стандартные зависимости с исключением gvisor
|
# Получаем последний релизный тег и его коммит
|
||||||
go list -f '{{if not (or .Main .Indirect)}}{{.Path}}{{end}}' -m all | \
|
echo "Fetching latest xray-core release tag..."
|
||||||
grep -v 'gvisor.dev/gvisor' | \
|
latest_tag=$(git ls-remote --tags https://github.com/xtls/xray-core \
|
||||||
grep -v 'github.com/xtls/xray-core' | \
|
| awk -F'[/ ]' '{print $3}' \
|
||||||
xargs -r go get -u
|
| grep '^v' \
|
||||||
|
| sort -V \
|
||||||
|
| tail -n1)
|
||||||
|
|
||||||
echo "Specifically updating xray-core to latest release tag..."
|
echo "Latest release tag: $latest_tag"
|
||||||
# Получаем последний релизный тег для xray-core
|
|
||||||
latest_tag=$(git ls-remote --tags https://github.com/xtls/xray-core | awk -F/ '{print $3}' | grep -v {} | sort -V | tail -n1)
|
|
||||||
if [ -z "$latest_tag" ]; then
|
|
||||||
echo "Error: Could not find latest release tag for xray-core"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
go get github.com/xtls/xray-core@$latest_tag
|
# Получаем хэш коммита для тега
|
||||||
# Проверяем, какую версию получили
|
commit_hash=$(git ls-remote https://github.com/xtls/xray-core refs/tags/$latest_tag \
|
||||||
echo "Updated xray-core to:"
|
| awk '{print $1}')
|
||||||
go list -m github.com/xtls/xray-core
|
|
||||||
|
echo "Associated commit hash: $commit_hash"
|
||||||
|
|
||||||
|
# Обновляем до конкретного коммита (будет сгенерирована псевдоверсия)
|
||||||
|
go get github.com/xtls/xray-core@$commit_hash
|
||||||
|
|
||||||
|
# Форсируем правильный формат псевдоверсии
|
||||||
|
go mod edit -require github.com/xtls/xray-core@v0.0.0-$(echo $commit_hash | sed 's/\(.\{12\}\).*/\1/')-$(date -d @$(echo $commit_hash | cut -c1-8) +%Y%m%d%H%M%S)
|
||||||
|
|
||||||
# Очистка и проверка
|
|
||||||
go mod tidy
|
go mod tidy
|
||||||
go mod verify || exit 1
|
go mod verify
|
||||||
|
|
||||||
# Выводим изменения для лога
|
|
||||||
echo "Updated dependencies:"
|
|
||||||
go list -m all
|
|
||||||
|
|
||||||
- name: Check for changes
|
- name: Check for changes
|
||||||
id: check
|
id: check
|
||||||
run: |
|
run: |
|
||||||
if git diff --quiet go.mod go.sum; then
|
if git diff --quiet go.mod go.sum; then
|
||||||
echo "changes=false" >> $GITHUB_OUTPUT
|
echo "changes=false" >> $GITHUB_OUTPUT
|
||||||
echo "No changes detected in dependencies"
|
|
||||||
else
|
else
|
||||||
echo "changes=true" >> $GITHUB_OUTPUT
|
echo "changes=true" >> $GITHUB_OUTPUT
|
||||||
echo "Changes detected in dependencies:"
|
git diff go.mod
|
||||||
# Добавляем || true чтобы предотвратить код ошибки, если grep ничего не находит
|
|
||||||
git diff go.mod || true
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
- name: Commit and push changes
|
- name: Commit and push changes
|
||||||
if: steps.check.outputs.changes == 'true'
|
if: steps.check.outputs.changes == 'true'
|
||||||
run: |
|
run: |
|
||||||
git config --global user.name "github-actions[bot]"
|
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 add go.mod go.sum
|
||||||
git commit -m "chore(deps): update Go dependencies
|
git commit -m "chore(deps): update xray-core to pseudo-version"
|
||||||
|
git push origin HEAD:${{ github.ref }}
|
||||||
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
|
|
||||||
|
|
Loading…
Reference in a new issue