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

132 行
4.5 KiB
YAML

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/<item>/\n<item>/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
id: download
if: steps.version_check.outputs.new_version == 'true'
run: |
python3 firmware_downloader.py
VERSION="${{ steps.version_check.outputs.firmware_version }}"
echo "firmware_version=$VERSION" >> $GITHUB_OUTPUT
- name: 🧹 Clean and Generate Changelog
id: cleanup
if: steps.version_check.outputs.new_version == 'true'
run: |
VERSION="${{ steps.download.outputs.firmware_version }}"
DIR="Firmware $VERSION"
if [ -d "$DIR" ]; then
# Suppression des fichiers .1.nca et fragments
find "$DIR" -type f -name "*.[0-9].nca" -delete
find "$DIR" -type f -name "*.nca.*" -delete
# Extraction des SystemVersion NCA (fichiers de ~128KB)
# On cherche les fichiers NCA et on les trie par taille pour identifier les SystemVersion
SV_FAT=$(ls -S "$DIR"/*.nca | tail -n 2 | head -n 1 | xargs basename)
SV_EXFAT=$(ls -S "$DIR"/*.nca | tail -n 1 | xargs basename)
# Création du changelog personnalisé
echo "Archive created: Firmware $VERSION.zip" > changelog_body.txt
echo "SystemVersion NCA FAT: $SV_FAT" >> changelog_body.txt
echo "SystemVersion NCA exFAT: $SV_EXFAT" >> changelog_body.txt
echo "Verify hashes before installation!" >> changelog_body.txt
# Compression
zip -rj "Firmware $VERSION.zip" "$DIR/" -i "*.nca"
else
echo "Dossier non trouvé"
exit 1
fi
- 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:**
```text
$(cat changelog_body.txt)
```
files: |
Firmware ${{ steps.download.outputs.firmware_version }}.zip
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}