name: 🎮 Firmware Auto Downloader on: schedule: - cron: '0 * * * *' workflow_dispatch: jobs: download_and_release: runs-on: ubuntu-latest permissions: contents: write steps: - name: ⬇️ Checkout code uses: actions/checkout@v4 with: fetch-depth: 0 - name: 🐍 Setup Python uses: actions/setup-python@v5 with: python-version: '3.x' - name: ⚙️ Install required Python modules run: | pip install requests anynet beautifulsoup4 - name: ⬇️ Setup hactool-linux run: | cp hactool-linux hactool chmod +x hactool - name: 🔍 Check firmware version (Switch 1 only, >=21.0.0 strict) id: version_check run: | RSS=$(curl -s 'https://yls8.mtheall.com/ninupdates/feed.php') # Extraire le premier Switch (pas Switch 2) ITEM=$(echo "$RSS" | awk ' //,/<\/item>/ { if ($0 ~ /Switch / && $0 !~ /Switch 2 /) print }') DESCRIPTION=$(echo "$ITEM" | grep -oP '<description>\K[^<]+') if [ -z "$DESCRIPTION" ]; then echo "INFO: Aucun firmware Switch valide trouvé." echo "new_version=false" >> $GITHUB_OUTPUT exit 0 fi echo "Description détectée : $DESCRIPTION" # Extraire version VERSION=$(echo "$DESCRIPTION" | grep -oP '^Switch \K[0-9]+\.[0-9]+\.[0-9]+') if [ -z "$VERSION" ]; then echo "INFO: Impossible d'extraire la version." echo "new_version=false" >> $GITHUB_OUTPUT exit 0 fi MAJOR=$(echo "$VERSION" | cut -d. -f1) # 🔒 Bloque tout < 21 if [ "$MAJOR" -lt 21 ]; then echo "INFO: Firmware $VERSION ignoré (<21.x)." echo "new_version=false" >> $GITHUB_OUTPUT exit 0 fi echo "Version valide détectée : $VERSION" # Vérifier si la release existe déjà HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" \ -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ "https://api.github.com/repos/${{ github.repository }}/releases/tags/$VERSION") if [ "$HTTP_STATUS" == "200" ]; then echo "INFO: La release $VERSION existe déjà." echo "new_version=false" >> $GITHUB_OUTPUT else echo "INFO: Nouvelle version $VERSION détectée !" echo "new_version=true" >> $GITHUB_OUTPUT echo "firmware_version=$VERSION" >> $GITHUB_OUTPUT fi shell: bash - name: 💻 Execute download script and capture changelog id: download if: steps.version_check.outputs.new_version == 'true' run: | python3 firmware_downloader.py | tee firmware_output.txt FIRMWARE_VERSION=$(grep 'Folder: Firmware ' firmware_output.txt | awk '{print $NF}') echo "firmware_version=$FIRMWARE_VERSION" >> $GITHUB_OUTPUT tail -n 4 firmware_output.txt > changelog_body.txt - name: 🧹 Clean and zip firmware if: steps.version_check.outputs.new_version == 'true' run: | VERSION="${{ steps.download.outputs.firmware_version }}" # Supprimer fichiers temporaires .nca.* find . -type f -name "*.nca.*" -delete if [ -d "Firmware $VERSION" ]; then rm -f "Firmware $VERSION.zip" zip -rj "Firmware $VERSION.zip" "Firmware $VERSION/" -i "*.nca" fi - name: 📝 Prepare Release Body id: prepare_body if: steps.version_check.outputs.new_version == 'true' uses: actions/github-script@v7 with: script: | const fs = require('fs'); if (fs.existsSync('changelog_body.txt')) { const changelogBody = fs.readFileSync('changelog_body.txt', 'utf8'); core.setOutput('release_body', changelogBody); } else { core.setOutput('release_body', 'No changelog available.'); } - name: 📦 Create Tag and Release if: steps.version_check.outputs.new_version == 'true' uses: softprops/action-gh-release@v2 with: tag_name: ${{ steps.download.outputs.firmware_version }} name: Firmware ${{ steps.download.outputs.firmware_version }} body: | Automatic download of the official Nintendo Switch firmware version **${{ steps.download.outputs.firmware_version }}**. --- **Downloaded file details:** ${{ steps.prepare_body.outputs.release_body }} files: | Firmware ${{ steps.download.outputs.firmware_version }}.zip env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}