ProxmoxVE/.github/workflows/update_json_date.yml.bak

49 lines
1.7 KiB
YAML
Raw Normal View History

2025-01-16 13:16:09 +00:00
name: Update JSON Date
2025-01-15 10:19:32 +00:00
on:
2025-01-16 13:16:09 +00:00
pull_request:
types: [opened, synchronize, reopened]
2025-01-15 10:19:32 +00:00
jobs:
2025-01-16 13:16:09 +00:00
list-files:
runs-on: ubuntu-latest
steps:
2025-01-16 15:04:54 +00:00
- name: Checkout PR Branch
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}
2025-01-16 14:58:37 +00:00
2025-01-16 15:04:54 +00:00
- name: Fetch PR changes
run: |
2025-01-16 14:58:37 +00:00
git remote add fork https://github.com/${{ github.event.pull_request.head.repo.full_name }}.git
git fetch fork ${{ github.event.pull_request.head.ref }}:pullreq
git checkout pullreq
2025-01-16 13:16:09 +00:00
2025-01-16 15:04:54 +00:00
- name: Update JSON
id: changed-files
run: |
2025-01-16 13:16:09 +00:00
FILES=$(gh api repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/files --jq '.[].filename' | tr '\n' ' ')
echo "changed_files=${FILES}"
for FILE in $FILES; do
if [[ "$FILE" =~ /(.*)\.json ]]; then
NAME="${BASH_REMATCH[1]}"
else
2025-01-16 15:04:54 +00:00
echo "no new JSON in ${FILES}"
2025-01-16 13:16:09 +00:00
continue
fi
2025-01-16 15:04:54 +00:00
2025-01-16 13:16:09 +00:00
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
2025-01-16 15:04:54 +00:00
echo "JSON file $FILES not found"
2025-01-16 13:16:09 +00:00
fi
done
2025-01-16 15:04:54 +00:00
2025-01-16 13:16:09 +00:00
git config --global user.name "github-actions[bot]"
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."
2025-01-16 15:04:54 +00:00
git push
env:
2025-01-16 13:16:09 +00:00
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}