diff --git a/.github/main.yml b/.github/main.yml new file mode 100644 index 0000000..e3a3b92 --- /dev/null +++ b/.github/main.yml @@ -0,0 +1,43 @@ +name: Merge Protection + +on: + pull_request: + branches: [main, release, doc] + +jobs: + check-branch-rules: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Check branch merge rules + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + base_branch="${{ github.base_ref }}" + head_branch="${{ github.head_ref }}" + + case $base_branch in + main) + if [[ $head_branch != "release" && $head_branch != "doc" ]]; then + echo "Error: main can only be merged from release or doc branches." + exit 1 + fi + ;; + release) + if [[ $head_branch != feature/* ]]; then + echo "Error: release can only be merged from feature/* branches." + exit 1 + fi + ;; + doc) + echo "Error: doc branch cannot be merged from any other branch." + exit 1 + ;; + *) + if [[ $head_branch == test/* ]]; then + echo "Error: test/ branches cannot be merged into any other branch." + exit 1 + fi + ;; + esac diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5187106..87b5e37 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -49,4 +49,4 @@ jobs: - name: Prevent merge run: | echo "Branch merge rules check failed. Preventing merge." - exit 1 + exit 1 \ No newline at end of file