Skip to content

Commit 17cede0

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 61e6050 commit 17cede0

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
@@ -138,3 +138,97 @@ jobs:
138138
exit 1
139139
fi
140140
141+
- name: Install JIRA PR Check dependencies
142+
run: |
143+
python -m pip install --upgrade pip
144+
pip install jira
145+
146+
- name: Mask JIRA credentials
147+
run: |
148+
echo "::add-mask::${{ secrets.JIRA_API_TOKEN }}"
149+
echo "::add-mask::${{ secrets.JIRA_API_USER }}"
150+
echo "::add-mask::${{ secrets.JIRA_URL }}"
151+
152+
- name: Run JIRA PR Check
153+
id: jira_check
154+
continue-on-error: true # Allow PR comments to be posted before failing workflow
155+
env:
156+
JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }}
157+
JIRA_API_USER: ${{ secrets.JIRA_API_USER }}
158+
JIRA_URL: ${{ secrets.JIRA_URL }}
159+
working-directory: kernel-src-tree-tools
160+
run: |
161+
# Run script and capture output, ensuring credentials are never echoed
162+
set +x # Disable command echo to prevent credential exposure
163+
set +e # Don't exit on error, we want to capture the output
164+
OUTPUT=$(python3 jira_pr_check.py \
165+
--kernel-src-tree .. \
166+
--merge-target ${{ github.base_ref }} \
167+
--pr-branch ${{ github.head_ref }} 2>&1)
168+
EXIT_CODE=$?
169+
170+
# Filter out any potential credential leaks from output
171+
FILTERED_OUTPUT=$(echo "$OUTPUT" | grep -v "jira-user\|jira-key\|basic_auth\|Authorization\|$JIRA_API_TOKEN")
172+
173+
echo "$FILTERED_OUTPUT"
174+
echo "output<<'EOF'" >> $GITHUB_OUTPUT
175+
echo "$FILTERED_OUTPUT" >> $GITHUB_OUTPUT
176+
echo "EOF" >> $GITHUB_OUTPUT
177+
178+
# Check if there are any issues based on output patterns
179+
if echo "$FILTERED_OUTPUT" | grep -q "❌ Errors:"; then
180+
echo "has_issues=true" >> $GITHUB_OUTPUT
181+
182+
# Check specifically for LTS mismatch errors
183+
if echo "$FILTERED_OUTPUT" | grep -q "expects branch"; then
184+
echo "has_lts_mismatch=true" >> $GITHUB_OUTPUT
185+
else
186+
echo "has_lts_mismatch=false" >> $GITHUB_OUTPUT
187+
fi
188+
elif echo "$FILTERED_OUTPUT" | grep -q "⚠️ Warnings:"; then
189+
echo "has_issues=true" >> $GITHUB_OUTPUT
190+
echo "has_lts_mismatch=false" >> $GITHUB_OUTPUT
191+
else
192+
echo "has_issues=false" >> $GITHUB_OUTPUT
193+
echo "has_lts_mismatch=false" >> $GITHUB_OUTPUT
194+
fi
195+
196+
# Exit with the script's exit code
197+
exit $EXIT_CODE
198+
199+
- name: Comment PR with JIRA issues
200+
if: steps.jira_check.outputs.has_issues == 'true'
201+
uses: actions/github-script@v7
202+
with:
203+
github-token: ${{ secrets.GITHUB_TOKEN }}
204+
script: |
205+
const output = process.env.CHECK_OUTPUT;
206+
207+
github.rest.issues.createComment({
208+
issue_number: context.issue.number,
209+
owner: context.repo.owner,
210+
repo: context.repo.repo,
211+
body: output
212+
});
213+
env:
214+
CHECK_OUTPUT: ${{ steps.jira_check.outputs.output }}
215+
216+
- name: Request changes if LTS mismatch
217+
if: steps.jira_check.outputs.has_lts_mismatch == 'true'
218+
uses: actions/github-script@v7
219+
with:
220+
github-token: ${{ secrets.GITHUB_TOKEN }}
221+
script: |
222+
github.rest.pulls.createReview({
223+
owner: context.repo.owner,
224+
repo: context.repo.repo,
225+
pull_number: context.issue.number,
226+
event: 'REQUEST_CHANGES',
227+
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.'
228+
});
229+
230+
- name: Fail workflow if JIRA errors found
231+
if: steps.jira_check.outcome == 'failure'
232+
run: |
233+
echo "❌ JIRA PR check failed - errors were found in one or more commits"
234+
exit 1

0 commit comments

Comments
 (0)