From e3ccf502497cd2ae0e55cf99ba964582cc39c1ce Mon Sep 17 00:00:00 2001 From: devzeeh <148837352+devzeeh@users.noreply.github.com> Date: Tue, 11 Aug 2026 10:40:55 +0800 Subject: [PATCH] feat: add CI workflow to enforce PR branch flow and run Go tests --- .github/workflows/pr-flow.yml | 57 +++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 .github/workflows/pr-flow.yml diff --git a/.github/workflows/pr-flow.yml b/.github/workflows/pr-flow.yml new file mode 100644 index 0000000..621553d --- /dev/null +++ b/.github/workflows/pr-flow.yml @@ -0,0 +1,57 @@ +name: Enforce PR Branch Flow + +on: + pull_request: + types: [opened, synchronize, reopened] + +jobs: + enforce-flow: + runs-on: ubuntu-latest + steps: + - name: Check PR targeting main + if: github.base_ref == 'main' + run: | + HEAD_REF="${{ github.head_ref }}" + + # Allow 'development' or branches containing '-rc', starting with 'rc-', or 'release/' + if [[ "$HEAD_REF" == "development" ]] || [[ "$HEAD_REF" == *-rc* ]] || [[ "$HEAD_REF" == rc-* ]] || [[ "$HEAD_REF" == release/* ]]; then + echo "Valid source branch ($HEAD_REF) targeting main." + else + echo "ERROR: Invalid source branch for main." + echo "Pull requests targeting 'main' must originate from 'development' or a release candidate branch (e.g., *-rc)." + echo "Your source branch: $HEAD_REF" + exit 1 + fi + + - name: Check PR targeting development + if: github.base_ref == 'development' + run: | + HEAD_REF="${{ github.head_ref }}" + + # Block PRs from main back to development (typically handled by fast-forward or standard git flow differently) + if [[ "$HEAD_REF" == "main" ]]; then + echo "ERROR: Pull requests from 'main' to 'development' are restricted." + exit 1 + fi + echo "Valid source branch ($HEAD_REF) targeting development." + + test: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v6 + + - name: Setup Go + uses: actions/setup-go@v6 + with: + go-version-file: 'go.mod' + + - name: Download Dependencies + run: go mod download + + - name: Run go vet + run: go vet ./... + + - name: Run Go Tests + # go test ./... will gracefully pass (exit 0) even if no _test.go files exist + run: go test ./... -v -race -cover