ProxmoxVE/.github/workflows/check_and_update_json_date.yml

48 lines
1.4 KiB
YAML
Raw Normal View History

2025-01-15 09:25:38 +00:00
name: Update "date_created" in new JSON files
on:
2025-01-15 09:25:38 +00:00
pull_request:
types:
- opened
- synchronize
2025-01-15 08:58:13 +00:00
workflow_dispatch:
jobs:
2025-01-15 09:25:38 +00:00
update-date-created:
runs-on: ubuntu-latest
2025-01-15 09:21:44 +00:00
permissions:
contents: write
pull-requests: write
steps:
2025-01-15 09:25:38 +00:00
- name: Checkout PR branch
2025-01-15 09:21:44 +00:00
uses: actions/checkout@v4
with:
2025-01-15 09:21:44 +00:00
fetch-depth: 0
2025-01-15 09:25:38 +00:00
- 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 != ""
run: |
2025-01-15 09:25:38 +00:00
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
2025-01-15 09:25:38 +00:00
- name: Commit and push changes
if: env.NEW_JSON_FILES != ""
run: |
2025-01-15 09:25:38 +00:00
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 }}