mirror of
https://github.com/community-scripts/ProxmoxVE.git
synced 2025-02-23 21:21:38 +01:00
Update update_json_date.yml
This commit is contained in:
parent
2aed45fa61
commit
5da06e75e7
53
.github/workflows/update_json_date.yml
vendored
53
.github/workflows/update_json_date.yml
vendored
@ -2,9 +2,12 @@ name: Update JSON Date in PR
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
pull_request:
|
pull_request:
|
||||||
paths:
|
branches:
|
||||||
- 'json/*.json'
|
- main
|
||||||
types: [opened, synchronize, reopened]
|
types:
|
||||||
|
- opened
|
||||||
|
- synchronize
|
||||||
|
- reopened
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
update_json:
|
update_json:
|
||||||
@ -13,29 +16,53 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Check out repository
|
- name: Check out repository
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
with:
|
|
||||||
ref: ${{ github.head_ref }}
|
|
||||||
|
|
||||||
- name: Configure Git user
|
- name: Configure Git user
|
||||||
run: |
|
run: |
|
||||||
git config --global user.email "github-actions[bot]@users.noreply.github.com"
|
git config --global user.email "github-actions[bot]@users.noreply.github.com"
|
||||||
git config --global user.name "github-actions[bot]"
|
git config --global user.name "github-actions[bot]"
|
||||||
|
|
||||||
- name: Make script executable
|
- name: Get list of changed files in PR
|
||||||
run: chmod +x .github/workflows/scripts/update_json_date.sh
|
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,
|
||||||
|
});
|
||||||
|
|
||||||
- name: Run the update script
|
// Filter for JSON files only
|
||||||
run: ./.github/workflows/scripts/update_json_date.sh
|
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
|
- name: Commit changes if updated
|
||||||
run: |
|
run: |
|
||||||
git add *.json
|
git add *.json
|
||||||
git diff --cached --quiet || git commit -m "Update JSON dates"
|
git diff --cached --quiet || git commit -m "Update JSON dates"
|
||||||
|
|
||||||
- name: Push changes with API keys
|
- name: Push changes
|
||||||
env:
|
env:
|
||||||
JSON_API_ID: ${{ secrets.JSON_API_ID }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
JSON_API_KEY: ${{ secrets.JSON_API_KEY }}
|
|
||||||
run: |
|
run: |
|
||||||
git remote set-url origin https://$JSON_API_ID:$JSON_API_KEY@github.com/${{ github.repository }}.git
|
|
||||||
git push
|
git push
|
||||||
|
Loading…
Reference in New Issue
Block a user