Skip to content

Commit 128931d

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

File tree

1 file changed

+52
-1
lines changed

1 file changed

+52
-1
lines changed

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

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,54 @@ 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+
env:
168+
PR_TITLE: ${{ github.event.pull_request.title }}
169+
if: github.event_name == 'pull_request'
170+
steps:
171+
- name: extract-branch-name
172+
id: extract-branch-name
173+
run: |
174+
BRANCH_NAME="${{ github.head_ref }}"
175+
echo "Branch name: $BRANCH_NAME"
176+
echo "branch_name=$BRANCH_NAME" >> $GITHUB_OUTPUT
177+
178+
- name: enforce-jira-key
179+
id: enforce-jira-key
180+
run: |
181+
BRANCH_NAME="${{ steps.extract-branch-name.outputs.branch_name }}"
182+
echo $BRANCH_NAME
183+
JIRA_PATTERN='[A-Z]{2,}-[0-9]+'
184+
185+
# List of exempt prefixes (case-insensitive)
186+
EXEMPT_PREFIXES=("chore" "hotfix" "daily-chore")
187+
188+
# Convert branch name to lowercase for comparison
189+
BRANCH_LOWER=$(echo "$BRANCH_NAME" | tr '[:upper:]' '[:lower:]')
190+
191+
# Check if branch starts with any exempt prefix
192+
for prefix in "${EXEMPT_PREFIXES[@]}"; do
193+
if [[ "$BRANCH_LOWER" == $prefix* ]]; then
194+
echo "ℹ️ Branch starts with '$prefix' - Jira key not required"
195+
exit 0
196+
fi
197+
done
198+
199+
if [[ "$BRANCH_NAME" =~ $JIRA_PATTERN ]]; then
200+
echo "✅ Jira key found in branch name: ${BASH_REMATCH[0]}"
201+
else
202+
echo "❌ No Jira key found in branch name, checking PR name as fallback"
203+
if [[ "$PR_TITLE" =~ $JIRA_PATTERN ]]; then
204+
echo "✅ Jira key found in PR-title: ${BASH_REMATCH[0]}"
205+
else
206+
echo "❌ No Jira key found in branch name and PR title"
207+
exit 1
208+
fi
209+
fi
210+
163211
lint-commit-messages:
164212
needs: determine-test-scope
165213
runs-on: ubuntu-latest
@@ -515,7 +563,7 @@ jobs:
515563
(( needs.determine-test-scope.outputs.pr_approval_state == 'true' ) &&
516564
( needs.determine-test-scope.outputs.local_tests == 'true' ) ||
517565
( needs.determine-test-scope.outputs.remote_tests == 'true' ))
518-
needs: [local-tests, remote-tests, lint, verify-schema-change, lint-commit-messages]
566+
needs: [local-tests, remote-tests, lint, verify-schema-change, lint-commit-messages, lint-branch-name]
519567
runs-on: ubuntu-latest
520568
steps:
521569
- name: check-passing-remote-tests
@@ -540,5 +588,8 @@ jobs:
540588
elif [[ github.event_name == 'merge_group' && "${{ needs.lint-commit-messages.result }}" != 'success' ]]; then
541589
echo "❌ Linting of commit messages failed or was skipped."
542590
exit 1
591+
elif [[ "${{ github.event_name }}" == 'pull_request' && "${{ needs.lint-branch-name.result }}" != 'success' ]]; then
592+
echo "❌ Linting of branch name failed."
593+
exit 1
543594
fi
544595
echo "✅ All required test jobs passed!"

0 commit comments

Comments
 (0)