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: | if [ -f "hactool-linux" ]; then cp hactool-linux hactool chmod +x hactool else echo "Warning: hactool-linux non trouvé." fi - name: 🔍 Check firmware version (Switch 1 only, >=21.0.0) id: version_check shell: bash run: | set +e RSS=$(curl -sL --fail https://yls8.mtheall.com/ninupdates/feed.php) if [ $? -ne 0 ] || [ -z "$RSS" ]; then echo "new_version=false" >> $GITHUB_OUTPUT exit 0 fi # Extraction stricte Switch 1 (hac) + Tri version LATEST_VERSION=$(echo "$RSS" | tr -d '\n' | sed 's//\n/g' | \ grep 'sys=hac' | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | sort -V | tail -n 1) if [ -z "$LATEST_VERSION" ]; then echo "new_version=false" >> $GITHUB_OUTPUT exit 0 fi MAJOR=$(echo "$LATEST_VERSION" | cut -d. -f1) if [ "$MAJOR" -lt 21 ]; then echo "new_version=false" >> $GITHUB_OUTPUT exit 0 fi # Check si la Release existe 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/$LATEST_VERSION") if [ "$HTTP_STATUS" = "200" ]; then echo "new_version=false" >> $GITHUB_OUTPUT else echo "new_version=true" >> $GITHUB_OUTPUT echo "firmware_version=$LATEST_VERSION" >> $GITHUB_OUTPUT fi set -e - name: 💻 Execute download script & Extract Release Notes id: download if: steps.version_check.outputs.new_version == 'true' run: | VERSION="${{ steps.version_check.outputs.firmware_version }}" # Exécution SANS paramètre pour que le script interroge lui-même l'API Nintendo python3 firmware_downloader.py | tee script_output.log echo "firmware_version=$VERSION" >> $GITHUB_OUTPUT # Extraction stricte des dernières lignes générées par le script Python sed -n '/Archive created:/,$p' script_output.log > changelog_body.txt # Stockage sécurisé et multi-lignes du texte pour GitHub Actions EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64) echo "CHANGELOG_CONTENT<<$EOF" >> $GITHUB_ENV cat changelog_body.txt >> $GITHUB_ENV echo "$EOF" >> $GITHUB_ENV - 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: ${{ env.CHANGELOG_CONTENT }} files: | Firmware ${{ steps.download.outputs.firmware_version }}.zip env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}