|
| 1 | +name: JIRA PR Check |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [opened, synchronize, reopened] |
| 6 | + |
| 7 | +jobs: |
| 8 | + jira-pr-check: |
| 9 | + runs-on: ubuntu-latest |
| 10 | + permissions: |
| 11 | + contents: read |
| 12 | + pull-requests: write |
| 13 | + |
| 14 | + steps: |
| 15 | + - name: Checkout kernel-src-tree |
| 16 | + uses: actions/checkout@v4 |
| 17 | + with: |
| 18 | + path: kernel-src-tree |
| 19 | + fetch-depth: 0 |
| 20 | + |
| 21 | + - name: Checkout kernel-src-tree-tools |
| 22 | + uses: actions/checkout@v4 |
| 23 | + with: |
| 24 | + repository: ctrliq/kernel-src-tree-tools |
| 25 | + ref: '{jmaple}_pr_jira_test' |
| 26 | + path: kernel-src-tree-tools |
| 27 | + |
| 28 | + - name: Set up Python |
| 29 | + uses: actions/setup-python@v5 |
| 30 | + with: |
| 31 | + python-version: '3.x' |
| 32 | + |
| 33 | + - name: Install dependencies |
| 34 | + run: | |
| 35 | + python -m pip install --upgrade pip |
| 36 | + pip install jira |
| 37 | +
|
| 38 | + - name: Mask JIRA credentials |
| 39 | + run: | |
| 40 | + echo "::add-mask::${{ secrets.JIRA_API_USER }}" |
| 41 | + echo "::add-mask::${{ secrets.JIRA_API_TOKEN }}" |
| 42 | +
|
| 43 | + - name: Run JIRA PR Check |
| 44 | + id: jira_check |
| 45 | + env: |
| 46 | + JIRA_URL: ${{ secrets.JIRA_URL }} |
| 47 | + JIRA_API_USER: ${{ secrets.JIRA_API_USER }} |
| 48 | + JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }} |
| 49 | + run: | |
| 50 | + cd kernel-src-tree-tools |
| 51 | +
|
| 52 | + # Run script and capture output, ensuring credentials are never echoed |
| 53 | + set +x # Disable command echo to prevent credential exposure |
| 54 | + OUTPUT=$(python3 jira_pr_check.py \ |
| 55 | + --jira-url "${JIRA_URL}" \ |
| 56 | + --jira-user "${JIRA_API_USER}" \ |
| 57 | + --jira-key "${JIRA_API_TOKEN}" \ |
| 58 | + --kernel-src-tree ../kernel-src-tree \ |
| 59 | + --merge-target ${{ github.base_ref }} \ |
| 60 | + --pr-branch ${{ github.head_ref }} 2>&1) |
| 61 | + EXIT_CODE=$? |
| 62 | +
|
| 63 | + # Filter out any potential credential leaks from output |
| 64 | + FILTERED_OUTPUT=$(echo "$OUTPUT" | grep -v "jira-user\|jira-key\|basic_auth\|Authorization" || true) |
| 65 | +
|
| 66 | + echo "$FILTERED_OUTPUT" |
| 67 | + echo "output<<EOF" >> $GITHUB_OUTPUT |
| 68 | + echo "$FILTERED_OUTPUT" >> $GITHUB_OUTPUT |
| 69 | + echo "EOF" >> $GITHUB_OUTPUT |
| 70 | +
|
| 71 | + # Check if there are any issues |
| 72 | + if echo "$OUTPUT" | grep -E "^✗|^⚠|^!|^ERROR"; then |
| 73 | + echo "has_issues=true" >> $GITHUB_OUTPUT |
| 74 | +
|
| 75 | + # Check specifically for LTS mismatch errors |
| 76 | + if echo "$OUTPUT" | grep -q "✗.*LTS product.*expects branch"; then |
| 77 | + echo "has_lts_mismatch=true" >> $GITHUB_OUTPUT |
| 78 | + else |
| 79 | + echo "has_lts_mismatch=false" >> $GITHUB_OUTPUT |
| 80 | + fi |
| 81 | + else |
| 82 | + echo "has_issues=false" >> $GITHUB_OUTPUT |
| 83 | + echo "has_lts_mismatch=false" >> $GITHUB_OUTPUT |
| 84 | + fi |
| 85 | +
|
| 86 | + - name: Comment PR with issues |
| 87 | + if: steps.jira_check.outputs.has_issues == 'true' |
| 88 | + uses: actions/github-script@v7 |
| 89 | + with: |
| 90 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 91 | + script: | |
| 92 | + const output = `${{ steps.jira_check.outputs.output }}`; |
| 93 | + const body = `## JIRA PR Check Results |
| 94 | +
|
| 95 | + Issues were found with the VULN tickets in this PR: |
| 96 | +
|
| 97 | + \`\`\` |
| 98 | + ${output} |
| 99 | + \`\`\` |
| 100 | +
|
| 101 | + Please review and address the issues above before merging.`; |
| 102 | +
|
| 103 | + github.rest.issues.createComment({ |
| 104 | + issue_number: context.issue.number, |
| 105 | + owner: context.repo.owner, |
| 106 | + repo: context.repo.repo, |
| 107 | + body: body |
| 108 | + }); |
| 109 | +
|
| 110 | + - name: Request changes if LTS mismatch |
| 111 | + if: steps.jira_check.outputs.has_lts_mismatch == 'true' |
| 112 | + uses: actions/github-script@v7 |
| 113 | + with: |
| 114 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 115 | + script: | |
| 116 | + github.rest.pulls.createReview({ |
| 117 | + owner: context.repo.owner, |
| 118 | + repo: context.repo.repo, |
| 119 | + pull_number: context.issue.number, |
| 120 | + event: 'REQUEST_CHANGES', |
| 121 | + 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.' |
| 122 | + }); |
| 123 | +
|
| 124 | + - name: Fail workflow if LTS mismatch |
| 125 | + if: steps.jira_check.outputs.has_lts_mismatch == 'true' |
| 126 | + run: | |
| 127 | + echo "❌ JIRA PR check failed due to LTS product mismatch" |
| 128 | + exit 1 |
0 commit comments