name: Update .app-headers in /misc on: push: branches: ["main"] workflow_dispatch: jobs: update-and-create-pr: runs-on: ubuntu-latest permissions: contents: write pull-requests: write steps: # Step 1: Checkout repository - name: Checkout repository uses: actions/checkout@v4 with: fetch-depth: 0 # Ensure we have full access to all branches # Step 2: 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 echo "Switching to 'update-app-headers' branch." git checkout update-app-headers fi # Step 3: 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 else echo ".app-headers already exists." fi # Step 4: Check for changes in the .app-headers file content - name: Check if .app-headers has changes id: check_changes run: | git diff --quiet origin/main..HEAD -- .app-headers echo "Changes detected: $?" continue-on-error: true # So the workflow continues even if no changes are detected # Step 5: Commit changes if detected - name: Commit changes if detected if: steps.check_changes.outcome == 'failure' run: | echo "Changes detected in .app-headers. Committing changes." git commit -am "[core]: update .app-headers to latest version" git push origin update-app-headers --force # Step 6: Create Pull Request if changes detected - name: Create Pull Request if changes detected env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | PR_EXISTS=$(gh pr list --head "update-app-headers" --json number --jq '.[].number') if [ -z "$PR_EXISTS" ]; then echo "Creating a new PR." 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 7: Final status output - name: Output final status run: | echo "Workflow completed successfully. Branch and PR status updated."