Add Qodana workflow with manual cleanup option #35
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Qodana | |
| on: | |
| workflow_dispatch: | |
| pull_request: | |
| push: | |
| branches: | |
| - develop | |
| jobs: | |
| qodana: | |
| runs-on: ubuntu-latest | |
| if: github.event_name != 'pull_request' || github.event.pull_request.user.login != 'qodana-bot[bot]' | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| checks: write | |
| env: | |
| SHOULD_COMMIT: ${{ github.event_name == 'pull_request' || (github.event_name == 'push' && github.ref == 'refs/heads/develop') }} | |
| steps: | |
| - uses: actions/checkout@v6 | |
| with: | |
| ref: ${{ github.event.pull_request.head.sha }} | |
| fetch-depth: 0 | |
| lfs: true | |
| # Use PAT to allow pushed commits to trigger other workflows | |
| # GITHUB_TOKEN doesn't trigger workflows (security feature to prevent loops) | |
| token: ${{ secrets.QODANA_PUSH_TOKEN }} | |
| - name: 'Qodana Scan' | |
| uses: JetBrains/[email protected] | |
| with: | |
| args: --linter, jetbrains/qodana-jvm:2025.3, --baseline, .github/workflows/qodana.sarif.json, --cleanup | |
| pr-mode: 'true' | |
| push-fixes: none | |
| env: | |
| QODANA_TOKEN: ${{ secrets.QODANA_TOKEN }} | |
| - name: Extract issue number from branch name | |
| if: env.SHOULD_COMMIT == 'true' && github.event_name == 'pull_request' | |
| id: extract-issue | |
| run: | | |
| BRANCH_NAME="${{ github.head_ref }}" | |
| BRANCH_NAME_LOWER="${BRANCH_NAME,,}" | |
| # Pattern: ytdb + optional non-alphanumeric + digits (case-insensitive) | |
| if [[ $BRANCH_NAME_LOWER =~ ^(ytdb)([^a-zA-Z0-9]?)([0-9]+) ]]; then | |
| ISSUE_PREFIX="YTDB-${BASH_REMATCH[3]}" | |
| echo "issue_prefix=${ISSUE_PREFIX}" >> $GITHUB_OUTPUT | |
| echo "has_issue=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "has_issue=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Commit cleanup changes (PR) | |
| if: env.SHOULD_COMMIT == 'true' && github.event_name == 'pull_request' | |
| run: | | |
| # Check if there are changes to commit | |
| if git diff --quiet && git diff --staged --quiet; then | |
| echo "No changes to commit" | |
| exit 0 | |
| fi | |
| git config user.name "qodana-bot[bot]" | |
| git config user.email "qodana-bot[bot]@users.noreply.github.com" | |
| # Checkout the branch to allow pushing | |
| git checkout ${{ github.head_ref }} | |
| git add -A | |
| # Build commit message with issue prefix if available | |
| if [ "${{ steps.extract-issue.outputs.has_issue }}" == "true" ]; then | |
| COMMIT_MSG="${{ steps.extract-issue.outputs.issue_prefix }}: Apply Qodana cleanup fixes" | |
| else | |
| COMMIT_MSG="Apply Qodana cleanup fixes" | |
| fi | |
| git commit -m "$COMMIT_MSG" | |
| git push | |
| - name: Create cleanup PR (develop branch) | |
| if: env.SHOULD_COMMIT == 'true' && github.event_name == 'push' && github.ref == 'refs/heads/develop' | |
| run: | | |
| # Check if there are changes | |
| if git diff --quiet && git diff --staged --quiet; then | |
| echo "No changes to commit" | |
| exit 0 | |
| fi | |
| git config user.name "qodana-bot[bot]" | |
| git config user.email "qodana-bot[bot]@users.noreply.github.com" | |
| # Create a new branch for the cleanup | |
| CLEANUP_BRANCH="qodana-cleanup-$(date +%Y%m%d-%H%M%S)" | |
| git checkout -b "$CLEANUP_BRANCH" | |
| git add -A | |
| git commit -m "Apply Qodana cleanup fixes" | |
| git push -u origin "$CLEANUP_BRANCH" | |
| # Create PR using GitHub CLI | |
| gh pr create \ | |
| --title "Apply Qodana cleanup fixes" \ | |
| --body "$(cat <<'EOF' | |
| ## Summary | |
| - Automated PR to apply Qodana cleanup fixes to the codebase | |
| ## Test plan | |
| - [ ] Review the automated fixes | |
| - [ ] Verify tests pass | |
| 🤖 Generated automatically by Qodana workflow | |
| EOF | |
| )" \ | |
| --base develop | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |