Skip to content

Commit 5e1adeb

Browse files
committed
github actions: Add JIRA PR Check
We will be reaching into our JIRA to check the state of each commits jira. In this we want to ensure that the target branch matches the defined branch for that product and validate that the CVE ID is also correct for the ticket. It will also check to confirm that the tickets are in progress and have time logged, if either are untrue then it will produce a warning. In the event there are Product or CVE mis matches it will block the PR and request changes.
1 parent f338545 commit 5e1adeb

File tree

1 file changed

+94
-0
lines changed

1 file changed

+94
-0
lines changed

.github/workflows/validate-kernel-commits.yml

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,97 @@ jobs:
8585
gh pr comment ${{ github.event.pull_request.number }} \
8686
--body "$(cat interdiff_result.txt)" \
8787
--repo ${{ github.repository }}
88+
89+
- name: Install JIRA PR Check dependencies
90+
run: |
91+
python -m pip install --upgrade pip
92+
pip install jira
93+
94+
- name: Mask JIRA credentials
95+
run: |
96+
echo "::add-mask::${{ secrets.JIRA_API_USER }}"
97+
echo "::add-mask::${{ secrets.JIRA_API_TOKEN }}"
98+
99+
- name: Run JIRA PR Check
100+
id: jira_check
101+
continue-on-error: true
102+
env:
103+
JIRA_URL: ${{ secrets.JIRA_URL }}
104+
JIRA_API_USER: ${{ secrets.JIRA_API_USER }}
105+
JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }}
106+
working-directory: kernel-src-tree-tools
107+
run: |
108+
# Run script and capture output, ensuring credentials are never echoed
109+
set +x # Disable command echo to prevent credential exposure
110+
set +e # Don't exit on error, we want to capture the output
111+
OUTPUT=$(python3 jira_pr_check.py \
112+
--kernel-src-tree .. \
113+
--merge-target ${{ github.base_ref }} \
114+
--pr-branch ${{ github.head_ref }} 2>&1)
115+
EXIT_CODE=$?
116+
117+
# Filter out any potential credential leaks from output
118+
FILTERED_OUTPUT=$(echo "$OUTPUT" | grep -v "jira-user\|jira-key\|basic_auth\|Authorization" || true)
119+
120+
echo "$FILTERED_OUTPUT"
121+
echo "output<<EOF" >> $GITHUB_OUTPUT
122+
echo "$FILTERED_OUTPUT" >> $GITHUB_OUTPUT
123+
echo "EOF" >> $GITHUB_OUTPUT
124+
125+
# Check if there are any issues based on output patterns
126+
if echo "$FILTERED_OUTPUT" | grep -q "❌ Errors:"; then
127+
echo "has_issues=true" >> $GITHUB_OUTPUT
128+
129+
# Check specifically for LTS mismatch errors
130+
if echo "$FILTERED_OUTPUT" | grep -q "expects branch"; then
131+
echo "has_lts_mismatch=true" >> $GITHUB_OUTPUT
132+
else
133+
echo "has_lts_mismatch=false" >> $GITHUB_OUTPUT
134+
fi
135+
elif echo "$FILTERED_OUTPUT" | grep -q "⚠️ Warnings:"; then
136+
echo "has_issues=true" >> $GITHUB_OUTPUT
137+
echo "has_lts_mismatch=false" >> $GITHUB_OUTPUT
138+
else
139+
echo "has_issues=false" >> $GITHUB_OUTPUT
140+
echo "has_lts_mismatch=false" >> $GITHUB_OUTPUT
141+
fi
142+
143+
# Exit with the script's exit code
144+
exit $EXIT_CODE
145+
146+
- name: Comment PR with JIRA issues
147+
if: steps.jira_check.outputs.has_issues == 'true'
148+
uses: actions/github-script@v7
149+
with:
150+
github-token: ${{ secrets.GITHUB_TOKEN }}
151+
script: |
152+
const output = process.env.CHECK_OUTPUT;
153+
154+
github.rest.issues.createComment({
155+
issue_number: context.issue.number,
156+
owner: context.repo.owner,
157+
repo: context.repo.repo,
158+
body: output
159+
});
160+
env:
161+
CHECK_OUTPUT: ${{ steps.jira_check.outputs.output }}
162+
163+
- name: Request changes if LTS mismatch
164+
if: steps.jira_check.outputs.has_lts_mismatch == 'true'
165+
uses: actions/github-script@v7
166+
with:
167+
github-token: ${{ secrets.GITHUB_TOKEN }}
168+
script: |
169+
github.rest.pulls.createReview({
170+
owner: context.repo.owner,
171+
repo: context.repo.repo,
172+
pull_number: context.issue.number,
173+
event: 'REQUEST_CHANGES',
174+
body: '⚠️ This PR contains VULN tickets that do not match the target LTS product. Please review the JIRA ticket assignments and ensure they match the merge target branch.'
175+
});
176+
177+
- name: Fail workflow if JIRA errors found
178+
if: steps.jira_check.outcome == 'failure'
179+
run: |
180+
echo "❌ JIRA PR check failed - errors were found in one or more commits"
181+
exit 1

0 commit comments

Comments
 (0)