Skip to content

Commit 6f76ca0

Browse files
committed
feat: added jira key enforcement for pr
1 parent fbeeb61 commit 6f76ca0

File tree

1 file changed

+47
-1
lines changed

1 file changed

+47
-1
lines changed

.github/workflows/tidy3d-python-client-tests.yml

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,49 @@ jobs:
160160
- name: Run ruff check
161161
run: ruff check tidy3d
162162

163+
lint-branch-name:
164+
needs: determine-test-scope
165+
runs-on: ubuntu-latest
166+
name: lint-branch-name
167+
if: github.event_name == 'pull_request'
168+
steps:
169+
- name: extract-branch-name
170+
id: extract-branch-name
171+
run: |
172+
BRANCH_NAME="${{ github.head_ref }}"
173+
echo "Branch name: $BRANCH_NAME"
174+
echo "branch_name=$BRANCH_NAME" >> $GITHUB_OUTPUT
175+
176+
- name: enforce-jira-key
177+
id: enforce-jira-key
178+
run: |
179+
BRANCH_NAME="${{ steps.extract-branch-name.outputs.branch_name }}"
180+
echo $BRANCH_NAME
181+
JIRA_PATTERN='[A-Z]{2,}-[0-9]+'
182+
183+
# List of exempt prefixes (case-insensitive)
184+
EXEMPT_PREFIXES=("chore" "hotfix")
185+
186+
# Convert branch name to lowercase for comparison
187+
BRANCH_LOWER=$(echo "$BRANCH_NAME" | tr '[:upper:]' '[:lower:]')
188+
189+
# Check if branch starts with any exempt prefix
190+
for prefix in "${EXEMPT_PREFIXES[@]}"; do
191+
if [[ "$BRANCH_LOWER" == $prefix* ]]; then
192+
echo "ℹ️ Branch starts with '$prefix' - Jira key not required"
193+
exit 0
194+
fi
195+
done
196+
197+
if [[ "$BRANCH_NAME" =~ $JIRA_PATTERN ]]; then
198+
echo "✅ Jira key found: ${BASH_REMATCH[0]}"
199+
else
200+
echo "❌ No Jira key found"
201+
exit 1
202+
fi
203+
204+
205+
163206
lint-commit-messages:
164207
needs: determine-test-scope
165208
runs-on: ubuntu-latest
@@ -515,7 +558,7 @@ jobs:
515558
(( needs.determine-test-scope.outputs.pr_approval_state == 'true' ) &&
516559
( needs.determine-test-scope.outputs.local_tests == 'true' ) ||
517560
( needs.determine-test-scope.outputs.remote_tests == 'true' ))
518-
needs: [local-tests, remote-tests, lint, verify-schema-change, lint-commit-messages]
561+
needs: [local-tests, remote-tests, lint, verify-schema-change, lint-commit-messages, lint-branch-name]
519562
runs-on: ubuntu-latest
520563
steps:
521564
- name: check-passing-remote-tests
@@ -540,5 +583,8 @@ jobs:
540583
elif [[ github.event_name == 'merge_group' && "${{ needs.lint-commit-messages.result }}" != 'success' ]]; then
541584
echo "❌ Linting of commit messages failed or was skipped."
542585
exit 1
586+
elif [[ github.event_name == 'pull_request' && "${{ needs.lint-branch-name.result }}" != 'success' ]]; then
587+
echo "❌ Linting of branch name failed."
588+
exit 1
543589
fi
544590
echo "✅ All required test jobs passed!"

0 commit comments

Comments
 (0)