ProxmoxVE/.github/workflows/update_json_date.yml
2025-01-15 15:08:44 +01:00

69 lines
2.0 KiB
YAML

name: Update JSON Date in PR
on:
pull_request:
branches:
- main
types:
- opened
- synchronize
- reopened
jobs:
update_json:
runs-on: ubuntu-latest
steps:
- name: Check out repository
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:
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
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: |
changed_files="${{ steps.files.outputs.changed_files }}"
if [[ -z "$changed_files" ]]; then
echo "No JSON files changed in this PR. Exiting."
exit 0
fi
for file in $changed_files; do
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
run: |
git add *.json
git diff --cached --quiet || git commit -m "Update JSON dates"
- name: Push changes
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git push