mirror of
https://github.com/community-scripts/ProxmoxVE
synced 2025-02-10 17:59:17 +00:00
Update update_json_date.yml
This commit is contained in:
parent
f5a260a399
commit
6cc4244f70
99
.github/workflows/update_json_date.yml
vendored
99
.github/workflows/update_json_date.yml
vendored
@ -1,62 +1,61 @@
|
|||||||
name: Update JSON Date on PR
|
name: Update JSON Date on PR
|
||||||
on:
|
on:
|
||||||
pull_request:
|
pull_request:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
types:
|
types:
|
||||||
- opened
|
- opened
|
||||||
- synchronize
|
- synchronize
|
||||||
- reopened
|
- reopened
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
pull-requests: write
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
update-json-date:
|
update-json-date:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout PR Branch
|
- uses: actions/checkout@v4
|
||||||
uses: actions/checkout@v4
|
with:
|
||||||
with:
|
token: ${{ secrets.JSON_APP_KEY }}
|
||||||
ref: ${{ github.head_ref }}
|
fetch-depth: 0
|
||||||
token: ${{ secrets.JSON_APP_KEY }}
|
|
||||||
fetch-depth: 0
|
|
||||||
persist-credentials: true
|
|
||||||
|
|
||||||
- name: Check and Update New JSON Files
|
- run: |
|
||||||
run: |
|
echo "https://x-access-token:${GH_TOKEN}@github.com" > ~/.git-credentials
|
||||||
git config --global url."https://x-access-token:${GH_TOKEN}@github.com/".insteadOf "https://github.com/"
|
git config --global credential.helper store
|
||||||
BASE_BRANCH=${{ github.event.pull_request.base.ref }}
|
git config --global url."https://x-access-token:${GH_TOKEN}@github.com/".insteadOf "https://github.com/"
|
||||||
HEAD_BRANCH=${{ github.event.pull_request.head.ref }}
|
|
||||||
git fetch origin $BASE_BRANCH
|
|
||||||
NEW_FILES=$(git diff --name-status origin/$BASE_BRANCH HEAD | grep "^A" | awk '{print $2}' | grep '\.json$')
|
|
||||||
|
|
||||||
echo "New JSON files found: $NEW_FILES"
|
BASE_BRANCH=${{ github.event.pull_request.base.ref }}
|
||||||
|
HEAD_BRANCH=${{ github.event.pull_request.head.ref }}
|
||||||
|
|
||||||
TODAY=$(date +%Y-%m-%d)
|
git fetch origin $BASE_BRANCH
|
||||||
|
|
||||||
for FILE in $NEW_FILES; do
|
NEW_FILES=$(git diff --name-status origin/$BASE_BRANCH HEAD | grep "^A" | awk '{print $2}' | grep '\.json$')
|
||||||
if [ -f "$FILE" ]; then
|
|
||||||
echo "Checking $FILE"
|
|
||||||
|
|
||||||
CURRENT_DATE=$(jq -r '.date_created' "$FILE")
|
echo "New JSON files found: $NEW_FILES"
|
||||||
|
|
||||||
if [ "$CURRENT_DATE" != "$TODAY" ]; then
|
TODAY=$(date +%Y-%m-%d)
|
||||||
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"
|
|
||||||
else
|
|
||||||
echo "date_created is already set to today in $FILE"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
git config --global user.name "json-updater-bot[bot]"
|
for FILE in $NEW_FILES; do
|
||||||
git config --global user.email "json-updater-bot[bot]@users.noreply.github.com"
|
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
|
||||||
|
done
|
||||||
|
|
||||||
if [[ -n $(git status -s) ]]; then
|
git config --global user.name "json-updater-bot[bot]"
|
||||||
git commit -am "Update date_created to today's date in new JSON files"
|
git config --global user.email "json-updater-bot[bot]@users.noreply.github.com"
|
||||||
git push origin HEAD
|
|
||||||
else
|
if [[ -n $(git status -s) ]]; then
|
||||||
echo "No changes needed"
|
git commit -am "Update date_created to today's date in new JSON files"
|
||||||
fi
|
git push origin HEAD
|
||||||
env:
|
fi
|
||||||
GH_TOKEN: ${{ secrets.JSON_APP_KEY }}
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.JSON_APP_KEY }}
|
GH_TOKEN: ${{ secrets.JSON_APP_KEY }}
|
||||||
APP_ID: ${{ secrets.JSON_APP_ID }}
|
GITHUB_TOKEN: ${{ secrets.JSON_APP_KEY }}
|
||||||
|
APP_ID: ${{ secrets.JSON_APP_ID }}
|
||||||
|
Loading…
Reference in New Issue
Block a user