diff --git a/.github/workflows/datastructures-algorithms-validate.yaml b/.github/workflows/datastructures-algorithms-validate.yaml index 6ade440..8dd9835 100644 --- a/.github/workflows/datastructures-algorithms-validate.yaml +++ b/.github/workflows/datastructures-algorithms-validate.yaml @@ -1,27 +1,44 @@ name: datastructures-algorithms-validate -# Triggers when a PR is opened or updated, targeting the 'release' branch +# Triggers when a PR is opened or updated, targeting 'release' OR 'main' on: pull_request: types: [opened, synchronize] - branches: - - 'release' - - 'main' + branches: + - release + - main jobs: - # --- Job 1: Lint, Build, and Test --- + # --- Job 1: The "Gate" Job --- + # This job runs first to validate the PR path. + enforce-branch-strategy: + runs-on: ubuntu-latest + steps: + - name: Block invalid PR path + # This step ONLY runs if the path is INVALID + # Wrap the entire logical operation in ${{...}} + if: ${{ !((startsWith(github.event.pull_request.head.ref, 'feature-') && github.event.pull_request.base.ref == 'release') || (github.event.pull_request.head.ref == 'release' && github.event.pull_request.base.ref == 'main')) }} + run: | + echo "::error:: This PR path (${{ github.event.pull_request.head.ref }} -> ${{ github.event.pull_request.base.ref }}) is not allowed." + echo "::error:: Allowed paths are: 'feature-*' -> 'release' OR 'release' -> 'main'." + exit 1 + + - name: Approve valid PR path + # This step ONLY runs if the path is VALID (for logging) + if: (startsWith(github.event.pull_request.head.ref, 'feature-') && github.event.pull_request.base.ref == 'release') || (github.event.pull_request.head.ref == 'release' && github.event.pull_request.base.ref == 'main') + run: | + echo "Valid PR path. Proceeding to build and test..." + + # --- Job 2: Lint, Build, and Test --- lint-build-test: - - # This job will ONLY run if: - # 1. (Source is 'feature-*' AND Target is 'release') - # OR - # 2. (Source is 'release' AND Target is 'main') - if: (startsWith(github.event.pull_request.head.ref, 'feature-') && github.event.pull_request.base.ref == 'release') || (github.event.pull_request.head.ref == 'release' && github.event.pull_request.base.ref == 'main') + # This job WAITS for 'enforce-branch-strategy' to succeed + needs: enforce-branch-strategy + runs-on: windows-latest steps: - name: Checkout code - uses: actions/checkout@v4 # Use v4 + uses: actions/checkout@v4 - name: Setup MSVC uses: ilammy/msvc-dev-cmd@v1