Skip to content

Commit cecf288

Browse files
committed
ci: added jira key enforcement for pr
1 parent fbeeb61 commit cecf288

File tree

1 file changed

+50
-1
lines changed

1 file changed

+50
-1
lines changed

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

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,52 @@ 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 in branch name: ${BASH_REMATCH[0]}"
199+
else
200+
echo "❌ No Jira key found in branch name, checking PR name as fallback"
201+
if [[ "${{ github.event.pull_request.title }}" =~ $JIRA_PATTERN]]; then
202+
echo "✅ Jira key found in PR-title: ${BASH_REMATCH[0]}"
203+
else
204+
echo "❌ No Jira key found in branch name and PR title"
205+
exit 1
206+
fi
207+
fi
208+
163209
lint-commit-messages:
164210
needs: determine-test-scope
165211
runs-on: ubuntu-latest
@@ -515,7 +561,7 @@ jobs:
515561
(( needs.determine-test-scope.outputs.pr_approval_state == 'true' ) &&
516562
( needs.determine-test-scope.outputs.local_tests == 'true' ) ||
517563
( needs.determine-test-scope.outputs.remote_tests == 'true' ))
518-
needs: [local-tests, remote-tests, lint, verify-schema-change, lint-commit-messages]
564+
needs: [local-tests, remote-tests, lint, verify-schema-change, lint-commit-messages, lint-branch-name]
519565
runs-on: ubuntu-latest
520566
steps:
521567
- name: check-passing-remote-tests
@@ -540,5 +586,8 @@ jobs:
540586
elif [[ github.event_name == 'merge_group' && "${{ needs.lint-commit-messages.result }}" != 'success' ]]; then
541587
echo "❌ Linting of commit messages failed or was skipped."
542588
exit 1
589+
elif [[ "${{ github.event_name }}" == 'pull_request' && "${{ needs.lint-branch-name.result }}" != 'success' ]]; then
590+
echo "❌ Linting of branch name failed."
591+
exit 1
543592
fi
544593
echo "✅ All required test jobs passed!"

0 commit comments

Comments
 (0)