mirror of
				https://github.com/community-scripts/ProxmoxVE.git
				synced 2025-11-04 10:22:50 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			89 lines
		
	
	
		
			2.8 KiB
		
	
	
	
		
			YAML
		
	
	
	
	
	
			
		
		
	
	
			89 lines
		
	
	
		
			2.8 KiB
		
	
	
	
		
			YAML
		
	
	
	
	
	
name: Auto Update JSON-Dateien (new files only)
 | 
						|
 | 
						|
on:
 | 
						|
  push:
 | 
						|
    branches:
 | 
						|
      - main
 | 
						|
  workflow_dispatch:
 | 
						|
 | 
						|
jobs:
 | 
						|
  update-json-dates:
 | 
						|
    runs-on: ubuntu-latest
 | 
						|
 | 
						|
    permissions:
 | 
						|
      contents: write
 | 
						|
      pull-requests: write
 | 
						|
 | 
						|
    steps:
 | 
						|
      - name: Generate a token
 | 
						|
        id: generate-token
 | 
						|
        uses: actions/create-github-app-token@v1
 | 
						|
        with:
 | 
						|
          app-id: ${{ vars.APP_ID }}
 | 
						|
          private-key: ${{ secrets.APP_PRIVATE_KEY }}
 | 
						|
 | 
						|
      - name: Checkout repository
 | 
						|
        uses: actions/checkout@v4
 | 
						|
        with:
 | 
						|
          fetch-depth: 0  # Full history to check commit timestamps
 | 
						|
 | 
						|
      - name: Set up Git
 | 
						|
        run: |
 | 
						|
          git config --global user.name "GitHub Actions"
 | 
						|
          git config --global user.email "github-actions[bot]@users.noreply.github.com"
 | 
						|
 | 
						|
      - name: Find newly created JSON files from today
 | 
						|
        id: find_new_json
 | 
						|
        run: |
 | 
						|
          TODAY=$(date -u +"%Y-%m-%d")
 | 
						|
          git fetch origin main --depth=1
 | 
						|
          LATEST_COMMIT=$(git rev-parse origin/main)
 | 
						|
 | 
						|
          > new_json_files.txt
 | 
						|
 | 
						|
          for FILE in $(git diff --diff-filter=A --name-only $LATEST_COMMIT -- json/); do
 | 
						|
            COMMIT_DATE=$(git log --format=%cI -- "$FILE" | tail -n 1 | cut -dT -f1)
 | 
						|
            if [[ "$COMMIT_DATE" == "$TODAY" ]]; then
 | 
						|
              echo "$FILE" >> new_json_files.txt
 | 
						|
            fi
 | 
						|
          done
 | 
						|
 | 
						|
          if [[ -s new_json_files.txt ]]; then
 | 
						|
            echo "CHANGED=true" >> $GITHUB_ENV
 | 
						|
          else
 | 
						|
            echo "CHANGED=false" >> $GITHUB_ENV
 | 
						|
          fi
 | 
						|
 | 
						|
      - name: Run update script
 | 
						|
        if: env.CHANGED == 'true'
 | 
						|
        run: |
 | 
						|
          chmod +x .github/scripts/update-json.sh
 | 
						|
          while read -r FILE; do
 | 
						|
            .github/scripts/update-json.sh "$FILE"
 | 
						|
          done < new_json_files.txt
 | 
						|
 | 
						|
      - name: Commit and create PR if changes exist
 | 
						|
        if: env.CHANGED == 'true'
 | 
						|
        run: |
 | 
						|
          git add json/*.json
 | 
						|
          git commit -m "Auto-update date_created in new JSON files"
 | 
						|
          git checkout -b pr-update-json-dates
 | 
						|
          git push origin pr-update-json-dates --force
 | 
						|
          gh pr create --title "[core] Auto-update new JSON files" \
 | 
						|
                       --body "This PR is auto-generated to update the `date_created` field in newly created JSON files." \
 | 
						|
                       --head pr-update-json-dates \
 | 
						|
                       --base main \
 | 
						|
                       --label "automated pr"
 | 
						|
        env:
 | 
						|
          GH_TOKEN: ${{ steps.generate-token.outputs.token }}
 | 
						|
 | 
						|
      - name: Approve pull request
 | 
						|
        if: env.CHANGED == 'true'
 | 
						|
        env:
 | 
						|
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
 | 
						|
        run: |
 | 
						|
          PR_NUMBER=$(gh pr list --head "pr-update-json-dates" --json number --jq '.[].number')
 | 
						|
          if [ -n "$PR_NUMBER" ]; then
 | 
						|
            gh pr review $PR_NUMBER --approve
 | 
						|
          fi
 |