diff --git a/.github/workflows/generate-app-headers.yaml b/.github/workflows/generate-app-headers.yaml index efe3bd6c..66efc59d 100644 --- a/.github/workflows/generate-app-headers.yaml +++ b/.github/workflows/generate-app-headers.yaml @@ -17,37 +17,48 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 with: - fetch-depth: 0 # Ensure we have full access to all branches + fetch-depth: 0 # Fetch all branches for full context - # Step 2: Check or Create update-app-headers branch - - name: Check or Create update-app-headers branch + # Step 2: Set up Git user + - name: Configure Git user + run: | + git config --global user.name "GitHub Actions" + git config --global user.email "actions@github.com" + + # Step 3: Check or create update-app-headers branch + - name: Check or create update-app-headers branch run: | git fetch origin - if ! git show-ref --quiet refs/heads/update-app-headers; then - echo "Creating 'update-app-headers' branch." - git checkout -b update-app-headers origin/main - else + if git show-ref --quiet refs/heads/update-app-headers; then echo "Switching to 'update-app-headers' branch." git checkout update-app-headers + else + echo "Creating 'update-app-headers' branch." + git checkout -b update-app-headers origin/main fi - # Step 3: Ensure .app-headers file exists and verify content - - name: Ensure .app-headers file exists and verify content + # Step 4: Merge main into update-app-headers + - name: Merge main into update-app-headers + run: | + git merge origin/main --no-edit || echo "No changes to merge from main." + + # Step 5: Ensure .app-headers file exists + - name: Ensure .app-headers file exists run: | if [ ! -f ".app-headers" ]; then - echo "The .app-headers file does not exist. Creating it." - echo "Generated by CI" > .app-headers + echo "Creating .app-headers file." + echo "Generated by CI on $(date)" > .app-headers else - echo ".app-headers already exists." + echo ".app-headers file already exists." fi - # Step 4: Commit and push changes (if any) - - name: Commit and push changes (if any) + # Step 6: Commit and push changes (if any) + - name: Commit and push changes run: | git diff --quiet -- .app-headers || git commit -am "[core]: update .app-headers to latest version" git push origin update-app-headers --force - # Step 5: Create Pull Request if changes detected + # Step 7: Create Pull Request if changes detected - name: Create Pull Request if changes detected env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -55,16 +66,15 @@ jobs: PR_EXISTS=$(gh pr list --head "update-app-headers" | grep -o '[0-9]\+') if [ -z "$PR_EXISTS" ]; then echo "Creating a new PR." - PR_URL=$(gh pr create --title "[core]: update .app-headers to latest version" \ - --body "This PR automatically updates the .app-headers file." \ - --head update-app-headers \ - --base main -q .url) - echo "PR created: $PR_URL" + gh pr create --title "[core]: update .app-headers to latest version" \ + --body "This PR automatically updates the .app-headers file." \ + --head update-app-headers \ + --base main else echo "PR already exists." fi - # Step 6: Automatically merge PR + # Step 8: Automatically merge PR - name: Automatically merge PR env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -78,7 +88,7 @@ jobs: echo "No PR found to merge." fi - # Step 7: Final status output + # Step 9: Final status output - name: Output final status run: | echo "Workflow completed successfully. Branch and PR status updated."