Update .gitea/workflows/update-factorio-modlist.yml
This commit is contained in:
@@ -1,40 +1,51 @@
|
||||
name: Update Factorio Mod List
|
||||
name: Update mods.json
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
push:
|
||||
branches: [ main ]
|
||||
paths:
|
||||
- 'Factorio/**'
|
||||
|
||||
jobs:
|
||||
update-modlist:
|
||||
update-mods:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Clone repository manually
|
||||
run: |
|
||||
export GIT_HTTP_MAX_REQUEST_BUFFER=524288000
|
||||
git init
|
||||
git remote add origin https://git.garpnet.it/GamerArena/FastDL.git
|
||||
git fetch --no-tags --no-recurse-submodules origin main
|
||||
git checkout main
|
||||
|
||||
- name: Generate mod list
|
||||
- name: Setup Git
|
||||
run: |
|
||||
cd Factorio
|
||||
echo "[" > mods.json
|
||||
for f in *.zip; do
|
||||
[ -f "$f" ] || continue
|
||||
echo " \"${f}\"," >> mods.json
|
||||
done
|
||||
# remove trailing comma and close JSON array
|
||||
sed -i '$ s/,$//' mods.json
|
||||
echo "]" >> mods.json
|
||||
git config --global user.name "Gitea Action"
|
||||
git config --global user.email "action@gitea.local"
|
||||
|
||||
- name: Commit and push updated mod list
|
||||
- name: Get list of .zip files via API
|
||||
env:
|
||||
GITEA_TOKEN: ${{ secrets.gamerarena }}
|
||||
GITEA_API_URL: https://git.garpnet.it/api/v1
|
||||
OWNER: GamerArena
|
||||
REPO: FastDL
|
||||
BRANCH: main
|
||||
run: |
|
||||
git config user.name "Gitea Bot"
|
||||
git config user.email "actions@local"
|
||||
git add -f Factorio/mods.json
|
||||
git commit -m "Auto-update Factorio mod list" || exit 0
|
||||
git push
|
||||
# Prende la lista di file nella root del repo
|
||||
response=$(curl -s -H "Authorization: token $GITEA_TOKEN" \
|
||||
"$GITEA_API_URL/repos/$OWNER/$REPO/contents?ref=$BRANCH")
|
||||
|
||||
# Filtra solo i file .zip e crea array JSON
|
||||
zip_files=$(echo "$response" | jq -r '.[] | select(.type=="file") | select(.name|endswith(".zip")) | .name')
|
||||
json_array=$(echo "$zip_files" | jq -R -s -c 'split("\n")[:-1]')
|
||||
|
||||
echo "Lista file .zip: $json_array"
|
||||
|
||||
# Scrive mods.json
|
||||
echo "$json_array" > mods.json
|
||||
|
||||
- name: Commit and push mods.json
|
||||
env:
|
||||
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||
run: |
|
||||
# Clona repo temporaneamente
|
||||
git clone https://${GITEA_TOKEN}@gitea.example.com/my-user/my-repo.git repo
|
||||
cd repo
|
||||
|
||||
# Sovrascrive o crea mods.json
|
||||
cp ../mods.json ./mods.json
|
||||
|
||||
# Commit e push
|
||||
git add mods.json
|
||||
git commit -m "Update mods.json with .zip files"
|
||||
git push origin main
|
||||
Reference in New Issue
Block a user