Update .gitea/workflows/update-factorio-modlist.yml
This commit is contained in:
@@ -7,8 +7,10 @@ jobs:
|
|||||||
update-mods:
|
update-mods:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
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:
|
env:
|
||||||
GITEA_TOKEN: ${{ secrets.gamerarena }}
|
GITEA_TOKEN: ${{ secrets.gamerarena }}
|
||||||
GITEA_API_URL: https://git.garpnet.it/api/v1
|
GITEA_API_URL: https://git.garpnet.it/api/v1
|
||||||
@@ -16,20 +18,16 @@ jobs:
|
|||||||
REPO: FastDL
|
REPO: FastDL
|
||||||
BRANCH: main
|
BRANCH: main
|
||||||
run: |
|
run: |
|
||||||
# Prende la lista di file nella root del repo
|
|
||||||
response=$(curl -s -H "Authorization: token $GITEA_TOKEN" \
|
response=$(curl -s -H "Authorization: token $GITEA_TOKEN" \
|
||||||
"$GITEA_API_URL/repos/$OWNER/$REPO/contents/Factorio?ref=$BRANCH")
|
"$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')
|
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]')
|
json_array=$(echo "$zip_files" | jq -R -s -c 'split("\n")[:-1]')
|
||||||
|
echo "$json_array" > mods.json
|
||||||
echo "Lista file .zip: $json_array"
|
echo "Lista file .zip: $json_array"
|
||||||
|
|
||||||
# Scrive mods.json
|
- name: Get current mods.json SHA
|
||||||
echo "$json_array" > mods.json
|
id: getsha
|
||||||
|
|
||||||
- name: Delete mods.json if exists
|
|
||||||
env:
|
env:
|
||||||
GITEA_TOKEN: ${{ secrets.gamerarena }}
|
GITEA_TOKEN: ${{ secrets.gamerarena }}
|
||||||
GITEA_API_URL: https://git.garpnet.it/api/v1
|
GITEA_API_URL: https://git.garpnet.it/api/v1
|
||||||
@@ -40,26 +38,28 @@ jobs:
|
|||||||
response=$(curl -s -H "Authorization: token $GITEA_TOKEN" \
|
response=$(curl -s -H "Authorization: token $GITEA_TOKEN" \
|
||||||
"$GITEA_API_URL/repos/$OWNER/$REPO/contents/Factorio/mods.json?ref=$BRANCH")
|
"$GITEA_API_URL/repos/$OWNER/$REPO/contents/Factorio/mods.json?ref=$BRANCH")
|
||||||
sha=$(echo "$response" | jq -r '.sha // empty')
|
sha=$(echo "$response" | jq -r '.sha // empty')
|
||||||
if [ -n "$sha" ]; then
|
echo "sha=$sha" >> $GITHUB_OUTPUT
|
||||||
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
|
|
||||||
|
|
||||||
- name: Upload mods.json via API
|
- name: Update mods.json via API
|
||||||
env:
|
env:
|
||||||
GITEA_TOKEN: ${{ secrets.gamerarena }}
|
GITEA_TOKEN: ${{ secrets.gamerarena }}
|
||||||
GITEA_API_URL: https://git.garpnet.it/api/v1
|
GITEA_API_URL: https://git.garpnet.it/api/v1
|
||||||
OWNER: GamerArena
|
OWNER: GamerArena
|
||||||
REPO: FastDL
|
REPO: FastDL
|
||||||
BRANCH: main
|
BRANCH: main
|
||||||
|
SHA: ${{ steps.getsha.outputs.sha }}
|
||||||
run: |
|
run: |
|
||||||
content=$(base64 -w 0 mods.json)
|
content=$(base64 -w 0 mods.json)
|
||||||
|
if [ -n "$SHA" ]; then
|
||||||
|
# Aggiorna il file esistente
|
||||||
curl -X PUT -H "Authorization: token $GITEA_TOKEN" \
|
curl -X PUT -H "Authorization: token $GITEA_TOKEN" \
|
||||||
-H "Content-Type: application/json" \
|
-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"
|
"$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
|
||||||
|
|||||||
Reference in New Issue
Block a user