name: Enforce Branch Policy

on:
  pull_request:
    branches:
      - main
  push:
    branches:
      - main
  workflow_dispatch:
jobs:
  enforce-branch-policy:
    runs-on: ubuntu-latest
    steps:
      - name: Enforce main branch pull request policy
        if: github.event_name == 'pull_request' && github.ref == 'refs/heads/main'
        run: |
          echo "Pull requests to the main branch are not allowed."
          exit 1
      - name: Enforce main branch push policy
        run: |
          echo "Push events to the main branch are allowed."
          exit 0