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

This commit is contained in:
2025-11-23 18:51:43 +00:00
parent e42c2ae1b1
commit 8cc8eec78d

View File

@@ -7,60 +7,45 @@ 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 in Factorio
- name: Get list of .zip files via API
env:
GITEA_TOKEN: ${{ secrets.gamerarena }}
GITEA_TOKEN: ${{ secrets.GAMERARENA }}
GITEA_API_URL: https://git.garpnet.it/api/v1
OWNER: GamerArena
REPO: FastDL
BRANCH: main
run: |
echo "Token length: ${#GITEA_TOKEN}" # debug
response=$(curl -s -H "Authorization: token $GITEA_TOKEN" \
"$GITEA_API_URL/repos/$OWNER/$REPO/contents/Factorio?ref=$BRANCH")
zip_files=$(echo "$response" | jq -r '.[] | select(.type=="file") | select(.name|endswith(".zip")) | .name')
echo "API Response: $response" # debug
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"
echo "Token length: ${#GITEA_TOKEN}"
- name: Get current mods.json SHA
id: getsha
- name: Upload mods.json via API
env:
GITEA_TOKEN: ${{ secrets.gamerarena }}
GITEA_TOKEN: ${{ secrets.GAMERARENA }}
GITEA_API_URL: https://git.garpnet.it/api/v1
OWNER: GamerArena
REPO: FastDL
BRANCH: main
run: |
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')
echo "sha=$sha" >> $GITHUB_OUTPUT
# recupera SHA del vecchio file
sha=$(curl -s -H "Authorization: token $GITEA_TOKEN" \
"$GITEA_API_URL/repos/$OWNER/$REPO/contents/Factorio/mods.json?ref=$BRANCH" | jq -r '.sha // empty')
- 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\",\"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
curl -X PUT -H "Authorization: token $GITEA_TOKEN" \
-H "Content-Type: application/json" \
-d "{\"content\":\"$content\",\"branch\":\"$BRANCH\",\"message\":\"Update mods.json\",\"sha\":\"$sha\"}" \
"$GITEA_API_URL/repos/$OWNER/$REPO/contents/Factorio/mods.json"