[core] Recreate Update JSON Workflow (#1523)

This commit is contained in:
Michel Roegl-Brunner 2025-01-16 12:12:13 +01:00 committed by GitHub
parent 5977f8f936
commit 85387563f0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,4 +1,4 @@
name: Update JSON Date in PR name: Update JSON Date on PR
on: on:
pull_request: pull_request:
@ -10,59 +10,49 @@ on:
- reopened - reopened
jobs: jobs:
update_json: update-json-date:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Check out repository - name: Checkout PR Branch
uses: actions/checkout@v4 uses: actions/checkout@v4
- name: Configure Git user
run: |
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
- name: Get list of changed files in PR
id: files
uses: actions/github-script@v7
with: with:
script: | ref: ${{ github.head_ref }}
const prNumber = context.payload.pull_request.number; - name: Update Date in JSON-Files
const prFiles = await github.rest.pulls.listFiles({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber,
});
// Filter for JSON files only
const changedJsonFiles = prFiles.data
.filter(file => file.filename.endsWith('.json'))
.map(file => file.filename);
core.setOutput('changed_files', changedJsonFiles.join('\n'));
console.log('Changed JSON files:', changedJsonFiles);
- name: Update dates in changed JSON files
run: | run: |
changed_files="${{ steps.files.outputs.changed_files }}"
if [[ -z "$changed_files" ]]; then BASE_BRANCH=${{ github.event.pull_request.base.ref }}
echo "No JSON files changed in this PR. Exiting." HEAD_BRANCH=${{ github.event.pull_request.head.ref }}
exit 0
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
fi fi
for file in $changed_files; do JSON_FILE="json/${NAME}.json"
echo "Updating $file with current date."
# Your logic to update the file if [[ -f "$JSON_FILE" ]]; then
jq '.date_created = "'"$(date +%Y-%m-%d)"'"' "$file" > tmp.$$.json && mv tmp.$$.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"
else
echo "JSON file $JSON_FILE not found"
fi
done done
- name: Commit changes if updated git config user.name "github-actions[bot]"
run: | git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add *.json git diff --exit-code || git commit -am "Updating Dates in affected JSON files."
git diff --cached --quiet || git commit -m "Update JSON dates"
- name: Push changes
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git push git push