mirror of
https://github.com/community-scripts/ProxmoxVE
synced 2025-02-25 01:13:40 +00:00
[core] Recreate Update JSON Workflow (#1523)
This commit is contained in:
parent
5977f8f936
commit
85387563f0
92
.github/workflows/update_json_date.yml
vendored
92
.github/workflows/update_json_date.yml
vendored
@ -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:
|
||||||
- name: Configure Git user
|
ref: ${{ github.head_ref }}
|
||||||
run: |
|
- name: Update Date in JSON-Files
|
||||||
git config --global user.email "github-actions[bot]@users.noreply.github.com"
|
run: |
|
||||||
git config --global user.name "github-actions[bot]"
|
|
||||||
|
BASE_BRANCH=${{ github.event.pull_request.base.ref }}
|
||||||
- name: Get list of changed files in PR
|
HEAD_BRANCH=${{ github.event.pull_request.head.ref }}
|
||||||
id: files
|
|
||||||
uses: actions/github-script@v7
|
git fetch origin $BASE_BRANCH
|
||||||
with:
|
|
||||||
script: |
|
CHANGED_FILES=$(git diff --name-only origin/$BASE_BRANCH HEAD)
|
||||||
const prNumber = context.payload.pull_request.number;
|
|
||||||
const prFiles = await github.rest.pulls.listFiles({
|
echo "Changed files: $CHANGED_FILES"
|
||||||
owner: context.repo.owner,
|
|
||||||
repo: context.repo.repo,
|
for FILE in $CHANGED_FILES; do
|
||||||
pull_number: prNumber,
|
if [[ "$FILE" =~ /(.*)\.sh ]]; then
|
||||||
});
|
echo ${BASE_REAMTCH[1]}
|
||||||
|
NAME="$(echo "${BASH_REMATCH[1]}" | sed 's/-install//')"
|
||||||
// Filter for JSON files only
|
elif [[ "$FILE" =~ /(.*)\.json ]]; then
|
||||||
const changedJsonFiles = prFiles.data
|
NAME="${BASH_REMATCH[1]}"
|
||||||
.filter(file => file.filename.endsWith('.json'))
|
else
|
||||||
.map(file => file.filename);
|
echo "no Match on $FILE"
|
||||||
|
continue
|
||||||
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
|
fi
|
||||||
|
|
||||||
|
JSON_FILE="json/${NAME}.json"
|
||||||
|
|
||||||
for file in $changed_files; do
|
if [[ -f "$JSON_FILE" ]]; then
|
||||||
echo "Updating $file with current date."
|
echo "Updating date_created in $JSON_FILE"
|
||||||
# Your logic to update the file
|
jq --arg date "$(date +%Y-%m-%d)" '.date_created = $date' "$JSON_FILE" > tmp.json && mv tmp.json "$JSON_FILE"
|
||||||
jq '.date_created = "'"$(date +%Y-%m-%d)"'"' "$file" > tmp.$$.json && mv tmp.$$.json "$file"
|
else
|
||||||
done
|
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: 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
|
|
||||||
|
Loading…
Reference in New Issue
Block a user