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: Compare with main and commit changes - name: Compare with main and commit changes run: | git fetch origin DIFF=$(git diff --quiet origin/main..origin/update-app-headers -- .app-headers || echo "Changes detected") if [[ "$DIFF" == "Changes detected" ]]; then 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 else echo "No changes in .app-headers. Skipping commit." fi # Step 5: 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 6: Final status output - name: Output final status run: | echo "Workflow completed successfully. Branch and PR status updated."