Update .gitea/workflows/update-factorio-modlist.yml

This commit is contained in:
2025-11-23 18:36:46 +00:00
parent 5114dd430e
commit 514002bcb8

View File

@@ -7,8 +7,10 @@ jobs:
update-mods:
runs-on: ubuntu-latest
steps:
- name: Install jq
run: sudo apt-get update && sudo apt-get install -y jq
- name: Get list of .zip files via API
- name: Get list of .zip files in Factorio
env:
GITEA_TOKEN: ${{ secrets.gamerarena }}
GITEA_API_URL: https://git.garpnet.it/api/v1
@@ -16,20 +18,16 @@ jobs:
REPO: FastDL
BRANCH: main
run: |
# Prende la lista di file nella root del repo
response=$(curl -s -H "Authorization: token $GITEA_TOKEN" \
"$GITEA_API_URL/repos/$OWNER/$REPO/contents/Factorio?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 "$json_array" > mods.json
echo "Lista file .zip: $json_array"
# Scrive mods.json
echo "$json_array" > mods.json
- name: Delete mods.json if exists
- name: Get current mods.json SHA
id: getsha
env:
GITEA_TOKEN: ${{ secrets.gamerarena }}
GITEA_API_URL: https://git.garpnet.it/api/v1
@@ -40,26 +38,28 @@ jobs:
response=$(curl -s -H "Authorization: token $GITEA_TOKEN" \
"$GITEA_API_URL/repos/$OWNER/$REPO/contents/Factorio/mods.json?ref=$BRANCH")
sha=$(echo "$response" | jq -r '.sha // empty')
if [ -n "$sha" ]; then
curl -X DELETE -H "Authorization: token $GITEA_TOKEN" \
-H "Content-Type: application/json" \
-d "{\"sha\":\"$sha\",\"branch\":\"$BRANCH\",\"message\":\"Delete mods.json\"}" \
"$GITEA_API_URL/repos/$OWNER/$REPO/contents/mods.json"
echo "mods.json deleted"
else
echo "mods.json does not exist, skipping delete"
fi
echo "sha=$sha" >> $GITHUB_OUTPUT
- name: Upload mods.json via API
- name: Update mods.json via API
env:
GITEA_TOKEN: ${{ secrets.gamerarena }}
GITEA_API_URL: https://git.garpnet.it/api/v1
OWNER: GamerArena
REPO: FastDL
BRANCH: main
SHA: ${{ steps.getsha.outputs.sha }}
run: |
content=$(base64 -w 0 mods.json)
if [ -n "$SHA" ]; then
# Aggiorna il file esistente
curl -X PUT -H "Authorization: token $GITEA_TOKEN" \
-H "Content-Type: application/json" \
-d "{\"content\":\"$content\",\"branch\":\"$BRANCH\",\"message\":\"Update mods.json\"}" \
-d "{\"content\":\"$content\",\"sha\":\"$SHA\",\"branch\":\"$BRANCH\",\"message\":\"Update mods.json\"}" \
"$GITEA_API_URL/repos/$OWNER/$REPO/contents/Factorio/mods.json"
else
# Crea il file se non esiste
curl -X PUT -H "Authorization: token $GITEA_TOKEN" \
-H "Content-Type: application/json" \
-d "{\"content\":\"$content\",\"branch\":\"$BRANCH\",\"message\":\"Create mods.json\"}" \
"$GITEA_API_URL/repos/$OWNER/$REPO/contents/Factorio/mods.json"
fi