LoaderSpot/.github/workflows/update_versions.yml
2025-11-18 05:39:35 +03:00

93 lines
3 KiB
YAML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

name: Update Version
on:
workflow_dispatch:
inputs:
datajson:
description: 'Version to update'
required: true
version:
description: 'Another version parameter'
required: true
buildType:
description: 'Build type (e.g., Master, Release)'
required: false
default: 'false'
jobs:
update-version:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v5
with:
token: ${{ secrets.PERSONAL_TOKEN }}
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: 3.12.2
- name: Update version and commit with retry
env:
DATA_JSON: ${{ github.event.inputs.datajson }}
BUILD_TYPE: ${{ github.event.inputs.buildType }}
VERSION: ${{ github.event.inputs.version }}
GITHUB_TOKEN: ${{ secrets.PERSONAL_TOKEN }}
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
MAX_RETRIES=20 # Увеличено с 10 до 20
RETRY_COUNT=0
# Случайная задержка 0-10 секунд в начале
RANDOM_DELAY=$((RANDOM % 10))
echo "Initial random delay: ${RANDOM_DELAY}s"
sleep $RANDOM_DELAY
while [ $RETRY_COUNT -lt $MAX_RETRIES ]; do
echo "Attempt $((RETRY_COUNT + 1)) of $MAX_RETRIES"
# Fetch latest changes
git fetch origin main
# Reset to remote state (discard local commits)
git reset --hard origin/main
# Re-checkout to ensure clean state
git checkout main
# Run Python script on fresh data
# Передаём JSON через stdin (самый надёжный способ)
echo "$DATA_JSON" | python3 update_version.py "$BUILD_TYPE"
# Check if there are changes
if ! git diff --quiet versions.json; then
git add versions.json
git commit -m "Added version $VERSION"
# Try to push
if git push "https://$GITHUB_TOKEN@github.com/${{ github.repository }}.git" HEAD:main; then
echo "✅ Successfully pushed version $VERSION"
exit 0
else
echo "⚠️ Push failed, retrying..."
RETRY_COUNT=$((RETRY_COUNT + 1))
# Экспоненциальная задержка с jitter (случайностью)
BASE_DELAY=$((RETRY_COUNT * 2))
JITTER=$((RANDOM % 5))
TOTAL_DELAY=$((BASE_DELAY + JITTER))
echo "Waiting ${TOTAL_DELAY}s before retry..."
sleep $TOTAL_DELAY
fi
else
echo " No changes detected in versions.json"
exit 0
fi
done
echo "❌ Failed to push after $MAX_RETRIES attempts"
exit 1