mirror of
https://github.com/community-scripts/ProxmoxVE
synced 2025-01-26 18:46:18 +00:00
Update check_and_update_json_date.yml
This commit is contained in:
parent
e756c49e50
commit
dbfb72807a
63
.github/workflows/check_and_update_json_date.yml
vendored
63
.github/workflows/check_and_update_json_date.yml
vendored
@ -1,47 +1,42 @@
|
||||
name: Update "date_created" in new JSON files
|
||||
name: Update JSON and Push Changes
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
types:
|
||||
- opened
|
||||
- synchronize
|
||||
workflow_dispatch:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
|
||||
jobs:
|
||||
update-date-created:
|
||||
update-json:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: write
|
||||
pull-requests: write
|
||||
|
||||
steps:
|
||||
- name: Checkout PR branch
|
||||
uses: actions/checkout@v4
|
||||
- name: Check out repository
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Authenticate with GitHub App
|
||||
uses: tibdex/github-app-token@v1
|
||||
with:
|
||||
fetch-depth: 0
|
||||
app_id: ${{ secrets.JSON_APP_ID }}
|
||||
private_key: ${{ secrets.JSON_APP_KEY }}
|
||||
|
||||
- name: Identify new JSON files
|
||||
id: new-json-files
|
||||
run: |
|
||||
BASE_BRANCH=$(jq -r '.base.ref' < "$GITHUB_EVENT_PATH")
|
||||
git fetch origin $BASE_BRANCH
|
||||
NEW_JSON_FILES=$(git diff --diff-filter=A --name-only origin/$BASE_BRANCH HEAD -- 'json/*.json')
|
||||
echo "NEW_JSON_FILES=$NEW_JSON_FILES" >> $GITHUB_ENV
|
||||
|
||||
- name: Update date_created in new JSON files
|
||||
if: env.NEW_JSON_FILES != ""
|
||||
- name: Modify JSON file
|
||||
run: |
|
||||
JSON_FILE="json/mailrise.json"
|
||||
TODAY=$(date -u +%Y-%m-%d)
|
||||
for file in $NEW_JSON_FILES; do
|
||||
echo "Updating date_created in $file"
|
||||
jq --arg date "$TODAY" '.date_created = $date' "$file" > temp.json && mv temp.json "$file"
|
||||
done
|
||||
|
||||
if [ -f "$JSON_FILE" ]; then
|
||||
echo "Updating date_created in $JSON_FILE to $TODAY"
|
||||
jq --arg today "$TODAY" '.date_created = $today' $JSON_FILE > tmp.json && mv tmp.json $JSON_FILE
|
||||
else
|
||||
echo "File $JSON_FILE does not exist."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
- name: Commit and push changes
|
||||
if: env.NEW_JSON_FILES != ""
|
||||
- name: Commit changes
|
||||
run: |
|
||||
git config --global user.name "github-actions[bot]"
|
||||
git config --global user.email "github-actions[bot]@users.noreply.github.com"
|
||||
git add $NEW_JSON_FILES
|
||||
git commit -m "Update date_created in new JSON files"
|
||||
git push origin HEAD:${{ github.head_ref }}
|
||||
git config user.name "github-actions[bot]"
|
||||
git config user.email "github-actions[bot]@users.noreply.github.com"
|
||||
git add json/mailrise.json
|
||||
git commit -m "Update date_created in mailrise.json to $TODAY"
|
||||
git push origin main
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user