From 2a9d110c44543f70358a3d20a24fea5208db6fe5 Mon Sep 17 00:00:00 2001 From: dugite-git Date: Tue, 23 Jul 2024 00:04:53 +0900 Subject: [PATCH] Update branch-restriction.yaml --- .github/workflows/branch-restriction.yaml | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/.github/workflows/branch-restriction.yaml b/.github/workflows/branch-restriction.yaml index bc04890..fbcd6dc 100644 --- a/.github/workflows/branch-restriction.yaml +++ b/.github/workflows/branch-restriction.yaml @@ -14,16 +14,14 @@ jobs: steps: - name: Check branch creation env: - BRANCH_NAME: ${{ github.ref_name }} - SOURCE_BRANCH: ${{ github.event.before }} + BRANCH_NAME: ${{ github.ref }} run: | ALLOWED_BRANCHES=("main" "develop") - for branch in "${ALLOWED_BRANCHES[@]}"; do - if [[ "$SOURCE_BRANCH" == *"$branch" ]]; then - exit 0 - fi - done - echo "Branch creation from $SOURCE_BRANCH is not allowed." - echo "Allowed branches are: ${ALLOWED_BRANCHES[@]}" - echo "SourceBranch name: $SOURCE_BRANCH" - exit 1 + BRANCH_NAME=${BRANCH_NAME#refs/heads/} + if [[ " ${ALLOWED_BRANCHES[@]} " =~ " ${BRANCH_NAME} " ]]; then + exit 0 + else + echo "Branch creation from $BRANCH_NAME is not allowed." + echo "BRANCH_NAME: $BRANCH_NAME" + exit 1 + fi