[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
with:
ref: ${{ github.head_ref }}
- name: Update Date in JSON-Files
run: |
- name: Configure Git user BASE_BRANCH=${{ github.event.pull_request.base.ref }}
run: | HEAD_BRANCH=${{ github.event.pull_request.head.ref }}
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 git fetch origin $BASE_BRANCH
id: files
uses: actions/github-script@v7
with:
script: |
const prNumber = context.payload.pull_request.number;
const prFiles = await github.rest.pulls.listFiles({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber,
});
// Filter for JSON files only CHANGED_FILES=$(git diff --name-only origin/$BASE_BRANCH HEAD)
const changedJsonFiles = prFiles.data
.filter(file => file.filename.endsWith('.json'))
.map(file => file.filename);
core.setOutput('changed_files', changedJsonFiles.join('\n')); echo "Changed files: $CHANGED_FILES"
console.log('Changed JSON files:', changedJsonFiles);
- name: Update dates in changed JSON files for FILE in $CHANGED_FILES; do
run: | if [[ "$FILE" =~ /(.*)\.sh ]]; then
changed_files="${{ steps.files.outputs.changed_files }}" echo ${BASE_REAMTCH[1]}
if [[ -z "$changed_files" ]]; then NAME="$(echo "${BASH_REMATCH[1]}" | sed 's/-install//')"
echo "No JSON files changed in this PR. Exiting." elif [[ "$FILE" =~ /(.*)\.json ]]; then
exit 0 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
jq '.date_created = "'"$(date +%Y-%m-%d)"'"' "$file" > tmp.$$.json && mv tmp.$$.json "$file"
done
- name: Commit changes if updated if [[ -f "$JSON_FILE" ]]; then
run: | echo "Updating date_created in $JSON_FILE"
git add *.json jq --arg date "$(date +%Y-%m-%d)" '.date_created = $date' "$JSON_FILE" > tmp.json && mv tmp.json "$JSON_FILE"
git diff --cached --quiet || git commit -m "Update JSON dates" else
echo "JSON file $JSON_FILE not found"
fi
done
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git diff --exit-code || git commit -am "Updating Dates in affected JSON files."
git push
- name: Push changes
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git push