mirror of
https://github.com/community-scripts/ProxmoxVE
synced 2025-02-25 09:23:41 +00:00
Update update_json_date.yml
This commit is contained in:
parent
24d24421d1
commit
6c42b5c21a
58
.github/workflows/update_json_date.yml
vendored
58
.github/workflows/update_json_date.yml
vendored
@ -17,41 +17,49 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
ref: ${{ github.head_ref }}
|
ref: ${{ github.head_ref }}
|
||||||
token: ${{ secrets.JSON_APP_KEY }}
|
token: ${{ secrets.JSON_APP_KEY }}
|
||||||
- name: Update Date in JSON-Files
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Check and Update New JSON Files
|
||||||
run: |
|
run: |
|
||||||
BASE_BRANCH=${{ github.event.pull_request.base.ref }}
|
BASE_BRANCH=${{ github.event.pull_request.base.ref }}
|
||||||
HEAD_BRANCH=${{ github.event.pull_request.head.ref }}
|
HEAD_BRANCH=${{ github.event.pull_request.head.ref }}
|
||||||
|
|
||||||
git fetch origin $BASE_BRANCH
|
# Hole die Base-Branch
|
||||||
|
git fetch origin $BASE_BRANCH
|
||||||
|
|
||||||
CHANGED_FILES=$(git diff --name-only origin/$BASE_BRANCH HEAD)
|
# Finde nur neue Dateien im PR
|
||||||
|
NEW_FILES=$(git diff --name-status origin/$BASE_BRANCH HEAD | grep "^A" | awk '{print $2}' | grep '\.json$')
|
||||||
|
|
||||||
echo "Changed files: $CHANGED_FILES"
|
echo "New JSON files found: $NEW_FILES"
|
||||||
|
|
||||||
for FILE in $CHANGED_FILES; do
|
TODAY=$(date +%Y-%m-%d)
|
||||||
if [[ "$FILE" =~ /(.*)\.sh ]]; then
|
|
||||||
echo ${BASH_REMATCH[1]}
|
for FILE in $NEW_FILES; do
|
||||||
NAME="$(echo "${BASH_REMATCH[1]}" | sed 's/-install//')"
|
if [ -f "$FILE" ]; then
|
||||||
elif [[ "$FILE" =~ /(.*)\.json ]]; then
|
echo "Checking $FILE"
|
||||||
NAME="${BASH_REMATCH[1]}"
|
|
||||||
else
|
# Prüfe das date_created Feld
|
||||||
echo "no Match on $FILE"
|
CURRENT_DATE=$(jq -r '.date_created' "$FILE")
|
||||||
continue
|
|
||||||
fi
|
if [ "$CURRENT_DATE" != "$TODAY" ]; then
|
||||||
|
echo "Updating date_created in $FILE from $CURRENT_DATE to $TODAY"
|
||||||
JSON_FILE="json/${NAME}.json"
|
jq --arg date "$TODAY" '.date_created = $date' "$FILE" > tmp.json && mv tmp.json "$FILE"
|
||||||
if [[ -f "$JSON_FILE" ]]; then
|
else
|
||||||
echo "Updating date_created in $JSON_FILE"
|
echo "date_created is already set to today in $FILE"
|
||||||
jq --arg date "$(date +%Y-%m-%d)" '.date_created = $date' "$JSON_FILE" > tmp.json && mv tmp.json "$JSON_FILE"
|
fi
|
||||||
else
|
|
||||||
echo "JSON file $JSON_FILE not found"
|
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# Nur committen wenn es Änderungen gibt
|
||||||
git config --global user.name "json-updater-bot[bot]"
|
git config --global user.name "json-updater-bot[bot]"
|
||||||
git config --global user.email "json-updater-bot[bot]@users.noreply.github.com"
|
git config --global user.email "json-updater-bot[bot]@users.noreply.github.com"
|
||||||
git diff --exit-code || git commit -am "Updating Dates in affected JSON files."
|
|
||||||
git push
|
if [[ -n $(git status -s) ]]; then
|
||||||
|
git commit -am "Update date_created to today's date in new JSON files"
|
||||||
|
git push
|
||||||
|
else
|
||||||
|
echo "No changes needed"
|
||||||
|
fi
|
||||||
env:
|
env:
|
||||||
GH_TOKEN: ${{ secrets.JSON_APP_KEY }}
|
GH_TOKEN: ${{ secrets.JSON_APP_KEY }}
|
||||||
APP_ID: ${{ secrets.JSON_APP_ID }}
|
APP_ID: ${{ secrets.JSON_APP_ID }}
|
||||||
|
Loading…
Reference in New Issue
Block a user