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 - name: 🐍 Setup Python uses: actions/setup-python@v5 with: python-version: '3.x' - name: ⚙️ Install required Python modules run: | python -m pip install --upgrade pip pip install requests beautifulsoup4 packaging lxml - name: ⬇️ Setup hactool-linux run: | if [ -f "hactool-linux" ]; then cp hactool-linux hactool chmod +x hactool fi - name: 🔍 Check firmware version id: version_check run: | python3 << 'EOF' import requests import sys import os from bs4 import BeautifulSoup from packaging import version URL = "https://yls8.mtheall.com/ninupdates/feed.php" output_file = os.getenv('GITHUB_OUTPUT') try: r = requests.get(URL, timeout=10) r.raise_for_status() except: open(output_file, "a").write("new_version=false\n") sys.exit(0) soup = BeautifulSoup(r.text, "xml") items = soup.find_all("item") versions = [] for item in items: link = item.find("link").text if item.find("link") else "" title = item.find("title").text if item.find("title") else "" if "sys=hac" in link and title.startswith("Switch "): versions.append(title.replace("Switch ", "").strip()) if not versions: open(output_file, "a").write("new_version=false\n") sys.exit(0) latest = sorted(set(versions), key=version.parse)[-1] if version.parse(latest) < version.parse("21.0.0"): open(output_file, "a").write("new_version=false\n") sys.exit(0) repo = os.environ["GITHUB_REPOSITORY"] token = os.environ["GITHUB_TOKEN"] api = f"https://api.github.com/repos/{repo}/releases/tags/{latest}" res = requests.get(api, headers={"Authorization": f"token {token}"}) if res.status_code == 200: open(output_file, "a").write("new_version=false\n") else: open(output_file, "a").write("new_version=true\n") open(output_file, "a").write(f"firmware_version={latest}\n") EOF env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: 💻 Execute download script id: download if: steps.version_check.outputs.new_version == 'true' run: | python3 firmware_downloader.py | tee firmware_output.txt VERSION="${{ steps.version_check.outputs.firmware_version }}" echo "firmware_version=$VERSION" >> $GITHUB_OUTPUT tail -n 10 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 }}" find . -type f -name "*.nca.*" -delete if [ -d "Firmware $VERSION" ]; then zip -rj "Firmware_$VERSION.zip" "Firmware $VERSION/" -i "*.nca" elif [ -d "Firmware_$VERSION" ]; then zip -rj "Firmware_$VERSION.zip" "Firmware_$VERSION/" -i "*.nca" else echo "ERROR: Aucun dossier firmware trouvé" exit 1 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')) { core.setOutput('body', fs.readFileSync('changelog_body.txt', 'utf8')); } else { core.setOutput('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 }}**. --- **Détails :** ${{ steps.prepare_body.outputs.body }} files: | Firmware_${{ steps.download.outputs.firmware_version }}.zip env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}