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
6cc4244f70
commit
786e8963b9
77
.github/workflows/update_json_date.yml
vendored
77
.github/workflows/update_json_date.yml
vendored
@ -1,61 +1,42 @@
|
|||||||
name: Update JSON Date on PR
|
name: Update JSON Date
|
||||||
on:
|
on:
|
||||||
pull_request:
|
pull_request:
|
||||||
branches:
|
types: [opened, synchronize, reopened]
|
||||||
- main
|
|
||||||
types:
|
|
||||||
- opened
|
|
||||||
- synchronize
|
|
||||||
- reopened
|
|
||||||
|
|
||||||
permissions:
|
|
||||||
contents: write
|
|
||||||
pull-requests: write
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
update-json-date:
|
list-files:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- name: Checkout PR Branch
|
||||||
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
token: ${{ secrets.JSON_APP_KEY }}
|
ref: ${{ github.head_ref }}
|
||||||
fetch-depth: 0
|
|
||||||
|
|
||||||
- run: |
|
- name: Update JSON
|
||||||
echo "https://x-access-token:${GH_TOKEN}@github.com" > ~/.git-credentials
|
id: changed-files
|
||||||
git config --global credential.helper store
|
run: |
|
||||||
git config --global url."https://x-access-token:${GH_TOKEN}@github.com/".insteadOf "https://github.com/"
|
FILES=$(gh api repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/files --jq '.[].filename' | tr '\n' ' ')
|
||||||
|
echo "changed_files=${FILES}"
|
||||||
BASE_BRANCH=${{ github.event.pull_request.base.ref }}
|
for FILE in $FILES; do
|
||||||
HEAD_BRANCH=${{ github.event.pull_request.head.ref }}
|
if [[ "$FILE" =~ /(.*)\.json ]]; then
|
||||||
|
NAME="${BASH_REMATCH[1]}"
|
||||||
git fetch origin $BASE_BRANCH
|
else
|
||||||
|
echo "no new JSON in ${FILES}"
|
||||||
NEW_FILES=$(git diff --name-status origin/$BASE_BRANCH HEAD | grep "^A" | awk '{print $2}' | grep '\.json$')
|
continue
|
||||||
|
|
||||||
echo "New JSON files found: $NEW_FILES"
|
|
||||||
|
|
||||||
TODAY=$(date +%Y-%m-%d)
|
|
||||||
|
|
||||||
for FILE in $NEW_FILES; do
|
|
||||||
if [ -f "$FILE" ]; then
|
|
||||||
echo "Checking $FILE"
|
|
||||||
CURRENT_DATE=$(jq -r '.date_created' "$FILE")
|
|
||||||
if [ "$CURRENT_DATE" != "$TODAY" ]; then
|
|
||||||
echo "Updating date_created in $FILE from $CURRENT_DATE to $TODAY"
|
|
||||||
jq --arg date "$TODAY" '.date_created = $date' "$FILE" > tmp.json && mv tmp.json "$FILE"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
JSON_FILE="json/${NAME}.json"
|
||||||
|
if [[ -f "$JSON_FILE" ]]; then
|
||||||
|
echo "Updating date_created in $JSON_FILE"
|
||||||
|
jq --arg date "$(date +%Y-%m-%d)" '.date_created = $date' "$JSON_FILE" > tmp.json && mv tmp.json "$JSON_FILE"
|
||||||
|
else
|
||||||
|
echo "JSON file $FILES not found"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
git config --global user.name "json-updater-bot[bot]"
|
git config --global user.name "github-actions[bot]"
|
||||||
git config --global user.email "json-updater-bot[bot]@users.noreply.github.com"
|
git config --global user.email "github-actions[bot]@users.noreply.github.com"
|
||||||
|
git diff --exit-code || git commit -am "Updating Dates in affected JSON files."
|
||||||
if [[ -n $(git status -s) ]]; then
|
git push
|
||||||
git commit -am "Update date_created to today's date in new JSON files"
|
|
||||||
git push origin HEAD
|
|
||||||
fi
|
|
||||||
env:
|
env:
|
||||||
GH_TOKEN: ${{ secrets.JSON_APP_KEY }}
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
GITHUB_TOKEN: ${{ secrets.JSON_APP_KEY }}
|
|
||||||
APP_ID: ${{ secrets.JSON_APP_ID }}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user