# Template for whenever I refresh the main branch. and even need to re-add the submodules afterwards.

name: Update Submodules

on:
  workflow_dispatch:

jobs:
  update-submodules:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout code
        uses: actions/checkout@v4.1.7

      - name: Set up Git
        run: |
           git config --global user.email "actions@github.com"
           git config --global user.name "GitHub Actions"

      - name: Add uYouEnhanced submodules
        run: |
          git submodule add https://github.com/dayanch96/uYouLocalization.git Tweaks/uYouLocalization
          git submodule add https://github.com/arichornloverALT/YTHoldForSpeed.git Tweaks/YTHoldForSpeed
          git submodule add https://github.com/arichornloverALT/YouGroupSettings.git Tweaks/YouGroupSettings
          git submodule add https://github.com/arichornloverALT/YouTimeStamp.git Tweaks/YouTimeStamp
          git submodule add https://github.com/protocolbuffers/protobuf.git Tweaks/protobuf
          git add .
          git commit -m "added uYouEnhanced submodules"
          git push origin

# ⬇️ this is for updating the submodules all at once. it's not recommended for use due to errors.

#     - name: Update submodules
#       run: |
#         git submodule update --init --recursive --remote
#         git add .
#         git commit -m "updated submodules"
#         git push origin
#       continue-on-error: true

# ⬇️ this is the current method of updating the submodules for uYouEnhanced

      - name: Update submodules
        run: |
          git submodule update --init --recursive --remote Tweaks/Alderis
          git add .
          git submodule update --init --recursive --remote Tweaks/DontEatMyContent
          git add .
          git submodule update --init --recursive --remote Tweaks/YTHoldForSpeed
          git add .
          git submodule update --init --recursive --remote Tweaks/PSHeader
          git add .
          git submodule update --init --recursive --remote Tweaks/Return-YouTube-Dislikes
          git add .
          git submodule update --init --recursive --remote Tweaks/uYouLocalization
          git add .
          git submodule update --init --recursive --remote Tweaks/YTABConfig
          git add .
          git submodule update --init --recursive --remote Tweaks/YTClassicVideoQuality
          git add .
          git submodule update --init --recursive --remote Tweaks/YTUHD
          git add .
          git submodule update --init --recursive --remote Tweaks/YTVideoOverlay
          git add .
          git submodule update --init --recursive --remote Tweaks/YouMute
          git add .
          git submodule update --init --recursive --remote Tweaks/YouPiP
          git add .
          git submodule update --init --recursive --remote Tweaks/YouQuality
          git add .
          git submodule update --init --recursive --remote Tweaks/YouGroupSettings
          git add .
          git submodule update --init --recursive --remote Tweaks/YouTubeHeader
          git add .
          git submodule update --init --recursive --remote Tweaks/iSponsorBlock
          git add .
          git commit -m "updated submodules"
          git push origin
        continue-on-error: true

# ⬇️ this is required for adding custom submodule(s) that include a .bundle file. it is recommended for use.

      - name: Make .bundle files
        run: |
          cd Bundles
          ln -s ../Tweaks/uYouLocalization/layout/Library/Application\ Support/uYouLocalization.bundle uYouLocalization.bundle
          ln -s ../Tweaks/YTHoldForSpeed/layout/Library/Application\ Support/YTHoldForSpeed.bundle YTHoldForSpeed.bundle
          ln -s ../Tweaks/YouGroupSettings/layout/Library/Application\ Support/YouGroupSettings.bundle YouGroupSettings.bundle
          ln -s ../Tweaks/YouTimeStamp/layout/Library/Application\ Support/YouTimeStamp.bundle YouTimeStamp.bundle
          git add .
          git commit -m "Added bundles"
          git push origin

# ⬇️ this is only necessary if you want to delete .bundle files if you planned on removing submodule(s) or your custom submodule(s).

#     - name: Delete .bundle files
#       run: |
#         cd Bundles
#         rm -f uYouLocalization.bundle
#         rm -f YTHoldForSpeed.bundle
#         rm -f YouGroupSettings.bundle
#         rm -f YouTimeStamp.bundle
#         git add .
#         git commit -m "Deleted bundles"
#         git push origin

      - name: Check exit code
        run: |
          exit_code=$?
          if [ $exit_code -ne 0 ]; then
            echo "Submodule update failed with exit code $exit_code"
            exit 1
          fi
