mirror of
				https://github.com/community-scripts/ProxmoxVE.git
				synced 2025-11-04 10:22:50 +00:00 
			
		
		
		
	Update and rename update_json_date.yml.bak to update_json_date.yml
This commit is contained in:
		
							
								
								
									
										58
									
								
								.github/workflows/update_json_date.yml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										58
									
								
								.github/workflows/update_json_date.yml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,58 @@
 | 
			
		||||
name: Update JSON Date
 | 
			
		||||
on:
 | 
			
		||||
  schedule:
 | 
			
		||||
    - cron: "0 */6 * * *"
 | 
			
		||||
  workflow_dispatch:
 | 
			
		||||
  pull_request:
 | 
			
		||||
    types: [opened, synchronize, reopened]
 | 
			
		||||
 | 
			
		||||
jobs:
 | 
			
		||||
  check-and-update-json:
 | 
			
		||||
    runs-on: ubuntu-latest
 | 
			
		||||
    steps:
 | 
			
		||||
      - name: Checkout PR Branch
 | 
			
		||||
        uses: actions/checkout@v4
 | 
			
		||||
        with:
 | 
			
		||||
          ref: ${{ github.event.pull_request.head.ref || github.head_ref }}
 | 
			
		||||
 | 
			
		||||
      - name: List changed files
 | 
			
		||||
        id: changed-files
 | 
			
		||||
        run: |
 | 
			
		||||
          PR_NUMBER="${{ github.event.pull_request.number }}"
 | 
			
		||||
          if [[ -n "$PR_NUMBER" ]]; then
 | 
			
		||||
            FILES=$(gh api repos/${{ github.repository }}/pulls/$PR_NUMBER/files --jq '.[].filename' | tr '\n' ' ')
 | 
			
		||||
          else
 | 
			
		||||
            FILES=$(git diff --name-status HEAD~1 | awk '$1 == "A" {print $2}')
 | 
			
		||||
          fi
 | 
			
		||||
          
 | 
			
		||||
          echo "FILES=$FILES" >> $GITHUB_ENV
 | 
			
		||||
        env:
 | 
			
		||||
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
 | 
			
		||||
 | 
			
		||||
      - name: Process JSON files
 | 
			
		||||
        run: |
 | 
			
		||||
          TODAY=$(date -u +"%Y-%m-%d")
 | 
			
		||||
          UPDATED=false
 | 
			
		||||
 | 
			
		||||
          for FILE in $FILES; do
 | 
			
		||||
            if [[ "$FILE" =~ ^json/.*\.json$ ]]; then
 | 
			
		||||
              DATE_IN_JSON=$(jq -r '.date_created' "$FILE")
 | 
			
		||||
 | 
			
		||||
              if [[ "$DATE_IN_JSON" != "$TODAY" ]]; then
 | 
			
		||||
                echo "Updating $FILE: $DATE_IN_JSON -> $TODAY"
 | 
			
		||||
                jq --arg date "$TODAY" '.date_created = $date' "$FILE" > tmp.json && mv tmp.json "$FILE"
 | 
			
		||||
                UPDATED=true
 | 
			
		||||
              fi
 | 
			
		||||
            fi
 | 
			
		||||
          done
 | 
			
		||||
 | 
			
		||||
          if [[ "$UPDATED" == "true" ]]; then
 | 
			
		||||
            git config --global user.name "github-actions[bot]"
 | 
			
		||||
            git config --global user.email "github-actions[bot]@users.noreply.github.com"
 | 
			
		||||
            git commit -am "Update date_created in new JSON files"
 | 
			
		||||
            git push
 | 
			
		||||
          else
 | 
			
		||||
            echo "No updates needed."
 | 
			
		||||
          fi
 | 
			
		||||
        env:
 | 
			
		||||
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
 | 
			
		||||
							
								
								
									
										48
									
								
								.github/workflows/update_json_date.yml.bak
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										48
									
								
								.github/workflows/update_json_date.yml.bak
									
									
									
									
										vendored
									
									
								
							@@ -1,48 +0,0 @@
 | 
			
		||||
name: Update JSON Date
 | 
			
		||||
on:
 | 
			
		||||
  pull_request:
 | 
			
		||||
    types: [opened, synchronize, reopened]
 | 
			
		||||
        
 | 
			
		||||
jobs:
 | 
			
		||||
  list-files:
 | 
			
		||||
    runs-on: ubuntu-latest
 | 
			
		||||
    steps:
 | 
			
		||||
    - name: Checkout PR Branch
 | 
			
		||||
      uses: actions/checkout@v4
 | 
			
		||||
      with:
 | 
			
		||||
        ref: ${{ github.event.pull_request.head.ref }}
 | 
			
		||||
 | 
			
		||||
    - name: Fetch PR changes
 | 
			
		||||
      run: |
 | 
			
		||||
          git remote add fork https://github.com/${{ github.event.pull_request.head.repo.full_name }}.git
 | 
			
		||||
          git fetch fork ${{ github.event.pull_request.head.ref }}:pullreq
 | 
			
		||||
          git checkout pullreq
 | 
			
		||||
 | 
			
		||||
    - name: Update JSON
 | 
			
		||||
      id: changed-files
 | 
			
		||||
      run: |
 | 
			
		||||
          FILES=$(gh api repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/files --jq '.[].filename' | tr '\n' ' ')
 | 
			
		||||
          echo "changed_files=${FILES}"
 | 
			
		||||
          for FILE in $FILES; do
 | 
			
		||||
            if [[ "$FILE" =~ /(.*)\.json ]]; then
 | 
			
		||||
              NAME="${BASH_REMATCH[1]}"
 | 
			
		||||
            else
 | 
			
		||||
              echo "no new JSON in ${FILES}"
 | 
			
		||||
              continue
 | 
			
		||||
            fi
 | 
			
		||||
          
 | 
			
		||||
            JSON_FILE="json/${NAME}.json"
 | 
			
		||||
            if [[ -f "$JSON_FILE" ]]; then
 | 
			
		||||
              echo "Updating date_created in $JSON_FILE"
 | 
			
		||||
              jq --arg date "$(date +%Y-%m-%d)" '.date_created = $date' "$JSON_FILE" > tmp.json && mv tmp.json "$JSON_FILE"
 | 
			
		||||
            else
 | 
			
		||||
              echo "JSON file $FILES not found"
 | 
			
		||||
            fi
 | 
			
		||||
          done
 | 
			
		||||
             
 | 
			
		||||
          git config --global user.name "github-actions[bot]"
 | 
			
		||||
          git config --global user.email "github-actions[bot]@users.noreply.github.com"
 | 
			
		||||
          git diff --exit-code || git commit -am "Updating Dates in affected JSON files."
 | 
			
		||||
          git push 
 | 
			
		||||
      env:
 | 
			
		||||
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
 | 
			
		||||
		Reference in New Issue
	
	Block a user