0
0
镜像自地址 https://github.com/THZoria/NX_Firmware.git 已同步 2026-04-09 10:41:13 +00:00

Refactor firmware autodl workflow for improved checks

这个提交包含在:
Zoria
2026-03-17 07:04:25 +01:00
提交者 GitHub
父节点 bf849d454d
当前提交 a3b5ff8eea

查看文件

@@ -14,6 +14,8 @@ jobs:
steps: steps:
- name: ⬇️ Checkout code - name: ⬇️ Checkout code
uses: actions/checkout@v4 uses: actions/checkout@v4
with:
fetch-depth: 0
- name: 🐍 Setup Python - name: 🐍 Setup Python
uses: actions/setup-python@v5 uses: actions/setup-python@v5
@@ -22,94 +24,109 @@ jobs:
- name: ⚙️ Install required Python modules - name: ⚙️ Install required Python modules
run: | run: |
python -m pip install --upgrade pip pip install requests anynet beautifulsoup4
pip install requests beautifulsoup4 packaging lxml
- name: ⬇️ Setup hactool-linux - name: ⬇️ Setup hactool-linux
run: | run: |
# Vérifie si le fichier existe avant de tenter de le copier
if [ -f "hactool-linux" ]; then if [ -f "hactool-linux" ]; then
cp hactool-linux hactool cp hactool-linux hactool
chmod +x hactool chmod +x hactool
else
echo "Warning: hactool-linux non trouvé dans le dépôt."
fi fi
- name: 🔍 Check firmware version - name: 🔍 Check firmware version (Switch 1 only, >=21.0.0 strict)
id: version_check id: version_check
shell: bash
run: | run: |
python3 << 'EOF' set +e
import requests
import sys
import os
from bs4 import BeautifulSoup
from packaging import version
URL = "https://yls8.mtheall.com/ninupdates/feed.php" # Récupération du flux RSS
output_file = os.getenv('GITHUB_OUTPUT') RSS=$(curl -sL --fail https://yls8.mtheall.com/ninupdates/feed.php)
if [ $? -ne 0 ] || [ -z "$RSS" ]; then
echo "ERROR: Impossible de récupérer le flux RSS."
echo "new_version=false" >> $GITHUB_OUTPUT
exit 0
fi
try: # Extraction et tri :
r = requests.get(URL, timeout=10) # 1. On cherche les balises Switch (ignore Switch 2)
r.raise_for_status() # 2. On extrait uniquement les numéros de version
except: # 3. On trie par ordre de version (sort -V) pour mettre la plus haute en dernier
open(output_file, "a").write("new_version=false\n") VERSIONS=$(echo "$RSS" | grep -oE '<description>Switch [0-9]+\.[0-9]+\.[0-9]+' | \
sys.exit(0) grep -v 'Switch 2' | \
grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | \
sort -V)
soup = BeautifulSoup(r.text, "xml") # On récupère la version la plus élevée de la liste
items = soup.find_all("item") LATEST_VERSION=$(echo "$VERSIONS" | tail -n 1)
versions = [] if [ -z "$LATEST_VERSION" ]; then
for item in items: echo "INFO: Aucun firmware valide trouvé."
link = item.find("link").text if item.find("link") else "" echo "new_version=false" >> $GITHUB_OUTPUT
title = item.find("title").text if item.find("title") else "" exit 0
fi
if "sys=hac" in link and title.startswith("Switch "): echo "Dernière version trouvée sur NinUpdates : $LATEST_VERSION"
versions.append(title.replace("Switch ", "").strip())
if not versions: # Vérification du numéro de version majeure (>= 21)
open(output_file, "a").write("new_version=false\n") MAJOR=$(echo "$LATEST_VERSION" | cut -d. -f1)
sys.exit(0) if [ "$MAJOR" -lt 21 ]; then
echo "INFO: Firmware $LATEST_VERSION ignoré (inférieur à 21.0.0)."
echo "new_version=false" >> $GITHUB_OUTPUT
exit 0
fi
latest = sorted(set(versions), key=version.parse)[-1] # Vérification si la Release existe déjà sur votre GitHub
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 version.parse(latest) < version.parse("21.0.0"): if [ "$HTTP_STATUS" = "200" ]; then
open(output_file, "a").write("new_version=false\n") echo "INFO: La version $LATEST_VERSION a déjà été publiée."
sys.exit(0) echo "new_version=false" >> $GITHUB_OUTPUT
else
echo "ACTION: Nouvelle version $LATEST_VERSION détectée !"
echo "new_version=true" >> $GITHUB_OUTPUT
echo "firmware_version=$LATEST_VERSION" >> $GITHUB_OUTPUT
fi
repo = os.environ["GITHUB_REPOSITORY"] set -e
token = os.environ["GITHUB_TOKEN"]
api = f"https://api.github.com/repos/{repo}/releases/tags/{latest}" - name: 💻 Execute download script and capture changelog
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 id: download
if: steps.version_check.outputs.new_version == 'true' if: steps.version_check.outputs.new_version == 'true'
run: | run: |
# On lance le script Python et on enregistre la sortie
python3 firmware_downloader.py | tee firmware_output.txt python3 firmware_downloader.py | tee firmware_output.txt
VERSION="${{ steps.version_check.outputs.firmware_version }}"
echo "firmware_version=$VERSION" >> $GITHUB_OUTPUT # On tente d'extraire la version confirmée par le script Python
FIRMWARE_VERSION=$(grep 'Folder: Firmware ' firmware_output.txt | awk '{print $NF}' | tr -d '\r')
# Si le script Python n'a pas renvoyé de dossier, on utilise la version du RSS
if [ -z "$FIRMWARE_VERSION" ]; then
FIRMWARE_VERSION="${{ steps.version_check.outputs.firmware_version }}"
fi
echo "firmware_version=$FIRMWARE_VERSION" >> $GITHUB_OUTPUT
# Capture les dernières lignes pour le changelog de la release
tail -n 10 firmware_output.txt > changelog_body.txt tail -n 10 firmware_output.txt > changelog_body.txt
- name: 🧹 Clean and zip firmware - name: 🧹 Clean and zip firmware
if: steps.version_check.outputs.new_version == 'true' if: steps.version_check.outputs.new_version == 'true'
run: | run: |
VERSION="${{ steps.download.outputs.firmware_version }}" VERSION="${{ steps.download.outputs.firmware_version }}"
# Nettoyage des fichiers temporaires .nca split
find . -type f -name "*.nca.*" -delete find . -type f -name "*.nca.*" -delete
# Création de l'archive ZIP si le dossier existe
if [ -d "Firmware $VERSION" ]; then if [ -d "Firmware $VERSION" ]; then
zip -rj "Firmware_$VERSION.zip" "Firmware $VERSION/" -i "*.nca" rm -f "Firmware $VERSION.zip"
elif [ -d "Firmware_$VERSION" ]; then zip -rj "Firmware $VERSION.zip" "Firmware $VERSION/" -i "*.nca"
zip -rj "Firmware_$VERSION.zip" "Firmware_$VERSION/" -i "*.nca"
else else
echo "ERROR: Aucun dossier firmware trouvé" echo "ERROR: Le dossier 'Firmware $VERSION' est introuvable."
exit 1 exit 1
fi fi
@@ -120,11 +137,12 @@ jobs:
with: with:
script: | script: |
const fs = require('fs'); const fs = require('fs');
let body = "Automatic download of the official Nintendo Switch firmware.";
if (fs.existsSync('changelog_body.txt')) { if (fs.existsSync('changelog_body.txt')) {
core.setOutput('body', fs.readFileSync('changelog_body.txt', 'utf8')); const changelog = fs.readFileSync('changelog_body.txt', 'utf8');
} else { body += "\n\n**Details:**\n```\n" + changelog + "\n```";
core.setOutput('body', 'No changelog available.');
} }
core.setOutput('release_body', body);
- name: 📦 Create Tag and Release - name: 📦 Create Tag and Release
if: steps.version_check.outputs.new_version == 'true' if: steps.version_check.outputs.new_version == 'true'
@@ -132,15 +150,8 @@ jobs:
with: with:
tag_name: ${{ steps.download.outputs.firmware_version }} tag_name: ${{ steps.download.outputs.firmware_version }}
name: Firmware ${{ steps.download.outputs.firmware_version }} name: Firmware ${{ steps.download.outputs.firmware_version }}
body: | body: ${{ steps.prepare_body.outputs.release_body }}
Automatic download of the official Nintendo Switch firmware version **${{ steps.download.outputs.firmware_version }}**.
---
**Détails :**
${{ steps.prepare_body.outputs.body }}
files: | files: |
Firmware_${{ steps.download.outputs.firmware_version }}.zip Firmware ${{ steps.download.outputs.firmware_version }}.zip
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}