New version of idanplus #80
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: Remove Old Files and Update | |
| on: | |
| workflow_dispatch: | |
| push: | |
| branches: | |
| - master | |
| paths: | |
| - zips/** | |
| - addons.xml | |
| jobs: | |
| update-versions: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v6 | |
| - name: Find and Remove Old Files | |
| run: | | |
| set -e | |
| excluded_dir="zips/repository.shilonit" | |
| directories=($(find zips -mindepth 1 -maxdepth 1 -type d ! -path "$excluded_dir")) | |
| for dir in "${directories[@]}"; do | |
| if [ -d "$dir" ]; then | |
| ## Find the latest version file | |
| latest_file=$(find "$dir" -maxdepth 1 -name '*.zip' | sort -V | tail -n 1) | |
| ## If no file, skip | |
| if [ -z "$latest_file" ]; then | |
| echo "No zip files found in $dir, skipping..." | |
| continue | |
| fi | |
| latest_version=$(basename "$latest_file" | awk -F'-' '{print $NF}' | sed 's/.zip$//') | |
| echo "Processing: $dir (Latest file: $(basename "$latest_file"), Version: $latest_version)" | |
| ## Iterate over files in the directory | |
| for file in "$dir"/*.zip; do | |
| version=$(basename "$file" | awk -F'-' '{print $NF}' | sed 's/.zip$//') | |
| ## Remove the file if it's not the latest version | |
| if [ "$version" != "$latest_version" ]; then | |
| echo "Removing old file: $file" | |
| rm "$file" || { echo "Error removing $file"; exit 1; } | |
| fi | |
| done | |
| else | |
| echo "Directory $dir does not exist" | |
| fi | |
| done | |
| ## Stage deletions and other changes | |
| git add . || { echo "Error staging files"; exit 1; } | |
| git status --porcelain || { echo "Error checking git status"; exit 1; } | |
| - name: Set up Python | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version: '3.x' | |
| - name: Install dependencies | |
| run: | | |
| pip install lxml | |
| - name: Update XML Files and MD5 | |
| run: | | |
| python .github/scripts/update_addons.py || { echo "Error running update_addons.py"; exit 1; } | |
| git add addons.xml addons.xml.md5 zips/*/addon.xml || { echo "Error staging XML files"; exit 1; } | |
| git status --porcelain || { echo "Error checking git status after updating addons.xml"; exit 1; } | |
| - name: Commit and push changes | |
| run: | | |
| git config user.name "shilonit" | |
| git config user.email "shilonit@users.noreply.github.com" | |
| # Commit if there are changes | |
| if ! git diff --cached --quiet; then | |
| git commit -m "Remove old versions and update XML" || { echo "Error committing changes"; exit 1; } | |
| git push origin master || { echo "Error pushing changes"; exit 1; } | |
| else | |
| echo "No changes to commit" | |
| fi |