mirror of
https://github.com/community-scripts/ProxmoxVE
synced 2025-02-10 09:49:18 +00:00
Update check_and_update_json_date.yml
This commit is contained in:
parent
4ae131e102
commit
e756c49e50
55
.github/workflows/check_and_update_json_date.yml
vendored
55
.github/workflows/check_and_update_json_date.yml
vendored
@ -1,46 +1,47 @@
|
|||||||
name: Update Pull Request
|
name: Update "date_created" in new JSON files
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
pull_request:
|
||||||
branches-ignore: ["main"]
|
types:
|
||||||
|
- opened
|
||||||
|
- synchronize
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
update-pr:
|
update-date-created:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
permissions:
|
permissions:
|
||||||
contents: write
|
contents: write
|
||||||
pull-requests: write
|
pull-requests: write
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Generate a token
|
- name: Checkout PR branch
|
||||||
id: generate-token
|
|
||||||
uses: actions/create-github-app-token@v1
|
|
||||||
with:
|
|
||||||
app-id: ${{ vars.APP_ID }}
|
|
||||||
private-key: ${{ secrets.APP_PRIVATE_KEY }}
|
|
||||||
|
|
||||||
- name: Checkout code
|
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
|
|
||||||
- name: Update JSON files
|
- name: Identify new JSON files
|
||||||
|
id: new-json-files
|
||||||
run: |
|
run: |
|
||||||
TODAY=$(date +%Y-%m-%d)
|
BASE_BRANCH=$(jq -r '.base.ref' < "$GITHUB_EVENT_PATH")
|
||||||
for file in $(git diff --diff-filter=A --name-only HEAD | grep '^json/.*\.json$'); do
|
git fetch origin $BASE_BRANCH
|
||||||
if jq -e '.date_created' $file > /dev/null 2>&1; then
|
NEW_JSON_FILES=$(git diff --diff-filter=A --name-only origin/$BASE_BRANCH HEAD -- 'json/*.json')
|
||||||
echo "Updating date_created in $file"
|
echo "NEW_JSON_FILES=$NEW_JSON_FILES" >> $GITHUB_ENV
|
||||||
jq --arg date "$TODAY" '.date_created = $date' $file > temp.json && mv temp.json $file
|
|
||||||
git add $file
|
- name: Update date_created in new JSON files
|
||||||
fi
|
if: env.NEW_JSON_FILES != ""
|
||||||
|
run: |
|
||||||
|
TODAY=$(date -u +%Y-%m-%d)
|
||||||
|
for file in $NEW_JSON_FILES; do
|
||||||
|
echo "Updating date_created in $file"
|
||||||
|
jq --arg date "$TODAY" '.date_created = $date' "$file" > temp.json && mv temp.json "$file"
|
||||||
done
|
done
|
||||||
|
|
||||||
- name: Commit and push changes to PR branch
|
- name: Commit and push changes
|
||||||
env:
|
if: env.NEW_JSON_FILES != ""
|
||||||
GH_TOKEN: ${{ steps.generate-token.outputs.token }}
|
|
||||||
run: |
|
run: |
|
||||||
git config user.name "github-actions[bot]"
|
git config --global user.name "github-actions[bot]"
|
||||||
git config user.email "github-actions[bot]@users.noreply.github.com"
|
git config --global user.email "github-actions[bot]@users.noreply.github.com"
|
||||||
git commit -m "Update date_created in JSON files" || echo "No changes to commit"
|
git add $NEW_JSON_FILES
|
||||||
git push origin HEAD:${{ github.event.pull_request.head.ref }} --force
|
git commit -m "Update date_created in new JSON files"
|
||||||
|
git push origin HEAD:${{ github.head_ref }}
|
||||||
|
Loading…
Reference in New Issue
Block a user