Update update_json_date.yml

This commit is contained in:
CanbiZ 2025-01-16 13:52:03 +01:00 committed by GitHub
parent 9e4c627323
commit 24d24421d1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,5 +1,4 @@
name: Update JSON Date on PR name: Update JSON Date on PR
on: on:
pull_request: pull_request:
branches: branches:
@ -8,23 +7,18 @@ on:
- opened - opened
- synchronize - synchronize
- reopened - reopened
permissions:
contents: write
pull-requests: write
jobs: jobs:
update-json-date: update-json-date:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout PR Branch - name: Checkout PR Branch
uses: actions/checkout@v4 uses: actions/checkout@v4
with: with:
ref: ${{ github.head_ref }} ref: ${{ github.head_ref }}
token: ${{ secrets.GITHUB_TOKEN }} token: ${{ secrets.JSON_APP_KEY }}
- name: Update Date in JSON-Files - name: Update Date in JSON-Files
run: | run: |
BASE_BRANCH=${{ github.event.pull_request.base.ref }} BASE_BRANCH=${{ github.event.pull_request.base.ref }}
HEAD_BRANCH=${{ github.event.pull_request.head.ref }} HEAD_BRANCH=${{ github.event.pull_request.head.ref }}
@ -36,7 +30,7 @@ jobs:
for FILE in $CHANGED_FILES; do for FILE in $CHANGED_FILES; do
if [[ "$FILE" =~ /(.*)\.sh ]]; then if [[ "$FILE" =~ /(.*)\.sh ]]; then
echo ${BASE_REAMTCH[1]} echo ${BASH_REMATCH[1]}
NAME="$(echo "${BASH_REMATCH[1]}" | sed 's/-install//')" NAME="$(echo "${BASH_REMATCH[1]}" | sed 's/-install//')"
elif [[ "$FILE" =~ /(.*)\.json ]]; then elif [[ "$FILE" =~ /(.*)\.json ]]; then
NAME="${BASH_REMATCH[1]}" NAME="${BASH_REMATCH[1]}"
@ -46,7 +40,6 @@ jobs:
fi fi
JSON_FILE="json/${NAME}.json" JSON_FILE="json/${NAME}.json"
if [[ -f "$JSON_FILE" ]]; then if [[ -f "$JSON_FILE" ]]; then
echo "Updating date_created in $JSON_FILE" 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" jq --arg date "$(date +%Y-%m-%d)" '.date_created = $date' "$JSON_FILE" > tmp.json && mv tmp.json "$JSON_FILE"
@ -55,9 +48,10 @@ jobs:
fi fi
done done
git config --global user.name "github-actions[bot]" git config --global user.name "json-updater-bot[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com" git config --global user.email "json-updater-bot[bot]@users.noreply.github.com"
git diff --exit-code || git commit -am "Updating Dates in affected JSON files." git diff --exit-code || git commit -am "Updating Dates in affected JSON files."
git push git push
env: env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} GH_TOKEN: ${{ secrets.JSON_APP_KEY }}
APP_ID: ${{ secrets.JSON_APP_ID }}