Skip to content

Commit 45d6630

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 45d6630

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed

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

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,100 @@ 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+
--jira-url "${JIRA_URL}" \
113+
--jira-user "${JIRA_API_USER}" \
114+
--jira-key "${JIRA_API_TOKEN}" \
115+
--kernel-src-tree .. \
116+
--merge-target ${{ github.base_ref }} \
117+
--pr-branch ${{ github.head_ref }} 2>&1)
118+
EXIT_CODE=$?
119+
120+
# Filter out any potential credential leaks from output
121+
FILTERED_OUTPUT=$(echo "$OUTPUT" | grep -v "jira-user\|jira-key\|basic_auth\|Authorization" || true)
122+
123+
echo "$FILTERED_OUTPUT"
124+
echo "output<<EOF" >> $GITHUB_OUTPUT
125+
echo "$FILTERED_OUTPUT" >> $GITHUB_OUTPUT
126+
echo "EOF" >> $GITHUB_OUTPUT
127+
128+
# Check if there are any issues based on output patterns
129+
if echo "$FILTERED_OUTPUT" | grep -q "❌ Errors:"; then
130+
echo "has_issues=true" >> $GITHUB_OUTPUT
131+
132+
# Check specifically for LTS mismatch errors
133+
if echo "$FILTERED_OUTPUT" | grep -q "expects branch"; then
134+
echo "has_lts_mismatch=true" >> $GITHUB_OUTPUT
135+
else
136+
echo "has_lts_mismatch=false" >> $GITHUB_OUTPUT
137+
fi
138+
elif echo "$FILTERED_OUTPUT" | grep -q "⚠️ Warnings:"; then
139+
echo "has_issues=true" >> $GITHUB_OUTPUT
140+
echo "has_lts_mismatch=false" >> $GITHUB_OUTPUT
141+
else
142+
echo "has_issues=false" >> $GITHUB_OUTPUT
143+
echo "has_lts_mismatch=false" >> $GITHUB_OUTPUT
144+
fi
145+
146+
# Exit with the script's exit code
147+
exit $EXIT_CODE
148+
149+
- name: Comment PR with JIRA issues
150+
if: steps.jira_check.outputs.has_issues == 'true'
151+
uses: actions/github-script@v7
152+
with:
153+
github-token: ${{ secrets.GITHUB_TOKEN }}
154+
script: |
155+
const output = process.env.CHECK_OUTPUT;
156+
157+
github.rest.issues.createComment({
158+
issue_number: context.issue.number,
159+
owner: context.repo.owner,
160+
repo: context.repo.repo,
161+
body: output
162+
});
163+
env:
164+
CHECK_OUTPUT: ${{ steps.jira_check.outputs.output }}
165+
166+
- name: Request changes if LTS mismatch
167+
if: steps.jira_check.outputs.has_lts_mismatch == 'true'
168+
uses: actions/github-script@v7
169+
with:
170+
github-token: ${{ secrets.GITHUB_TOKEN }}
171+
script: |
172+
github.rest.pulls.createReview({
173+
owner: context.repo.owner,
174+
repo: context.repo.repo,
175+
pull_number: context.issue.number,
176+
event: 'REQUEST_CHANGES',
177+
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.'
178+
});
179+
180+
- name: Fail workflow if JIRA errors found
181+
if: steps.jira_check.outcome == 'failure'
182+
run: |
183+
echo "❌ JIRA PR check failed - errors were found in one or more commits"
184+
exit 1

0 commit comments

Comments
 (0)