ProxmoxVE/.github/workflows/update_json_date.yml

64 lines
1.8 KiB
YAML
Raw Normal View History

name: Update JSON Date on PR
2025-01-15 10:19:32 +00:00
on:
pull_request:
2025-01-15 14:08:44 +00:00
branches:
- main
types:
- opened
- synchronize
- reopened
2025-01-16 12:49:56 +00:00
permissions:
contents: write
pull-requests: write
2025-01-15 10:27:53 +00:00
2025-01-15 10:19:32 +00:00
jobs:
update-json-date:
2025-01-15 10:19:32 +00:00
runs-on: ubuntu-latest
steps:
- name: Checkout PR Branch
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
2025-01-16 12:49:56 +00:00
token: ${{ secrets.GITHUB_TOKEN }}
- name: Update Date in JSON-Files
run: |
BASE_BRANCH=${{ github.event.pull_request.base.ref }}
HEAD_BRANCH=${{ github.event.pull_request.head.ref }}
git fetch origin $BASE_BRANCH
CHANGED_FILES=$(git diff --name-only origin/$BASE_BRANCH HEAD)
echo "Changed files: $CHANGED_FILES"
for FILE in $CHANGED_FILES; do
if [[ "$FILE" =~ /(.*)\.sh ]]; then
echo ${BASE_REAMTCH[1]}
NAME="$(echo "${BASH_REMATCH[1]}" | sed 's/-install//')"
elif [[ "$FILE" =~ /(.*)\.json ]]; then
NAME="${BASH_REMATCH[1]}"
else
echo "no Match on $FILE"
continue
2025-01-15 14:08:44 +00:00
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 $JSON_FILE not found"
fi
done
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."
git push
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}