2025-01-16 11:12:13 +00:00
|
|
|
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:
|
2025-01-16 11:12:13 +00:00
|
|
|
update-json-date:
|
2025-01-15 10:19:32 +00:00
|
|
|
runs-on: ubuntu-latest
|
|
|
|
|
|
|
|
steps:
|
2025-01-16 11:12:13 +00:00
|
|
|
- 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 }}
|
2025-01-16 11:12:13 +00:00
|
|
|
- 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
|
2025-01-16 11:12:13 +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
|
|
|
|
echo "JSON file $JSON_FILE not found"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2025-01-16 12:44:04 +00:00
|
|
|
git config --global user.name "github-actions[bot]"
|
|
|
|
git config --global user.email "github-actions[bot]@users.noreply.github.com"
|
2025-01-16 11:12:13 +00:00
|
|
|
git diff --exit-code || git commit -am "Updating Dates in affected JSON files."
|
|
|
|
git push
|
2025-01-16 12:44:04 +00:00
|
|
|
env:
|
|
|
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|