Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 7
ci: adapt PR size job to add sizes label#96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -18,6 +18,26 @@ on: | ||
| required: false | ||
| type: string | ||
| default: '(\.lock$)' | ||
| xs_max_size: | ||
| description: 'Maximum lines for XS size' | ||
| required: false | ||
| type: number | ||
| default: 10 | ||
| s_max_size: | ||
| description: 'Maximum lines for S size' | ||
| required: false | ||
| type: number | ||
| default: 100 | ||
| m_max_size: | ||
| description: 'Maximum lines for M size' | ||
| required: false | ||
| type: number | ||
| default: 500 | ||
| l_max_size: | ||
| description: 'Maximum lines for L size' | ||
| required: false | ||
| type: number | ||
| default: 1000 | ||
| jobs: | ||
| check-lines: | ||
| @@ -79,15 +99,106 @@ jobs: | ||
| # Calculate additions and deletions across all changes between the base and HEAD, | ||
| # filtering out files matching the ignore pattern. | ||
| additions=$(git diff "origin/$BASE_BRANCH"...HEAD --numstat | grep -Ev "$ignore_pattern" | awk '{add += $1} END {print add}') | ||
| deletions=$(git diff "origin/$BASE_BRANCH"...HEAD --numstat | grep -Ev "$ignore_pattern" | awk '{del += $2} END {print del}') | ||
| additions=$(git diff "origin/$BASE_BRANCH"...HEAD --numstat | grep -Ev "$ignore_pattern" | awk '{add += $1} END {print add+0}') | ||
| deletions=$(git diff "origin/$BASE_BRANCH"...HEAD --numstat | grep -Ev "$ignore_pattern" | awk '{del += $2} END {print del+0}') | ||
| total=$((additions + deletions)) | ||
| echo "Additions: $additions, Deletions: $deletions, Total: $total" | ||
| echo "lines_changed=$total" >> "$GITHUB_OUTPUT" | ||
| { | ||
| echo "lines_changed=$total" | ||
| echo "additions=$additions" | ||
| echo "deletions=$deletions" | ||
| } >> "$GITHUB_OUTPUT" | ||
| max_lines="${{ inputs.max_lines }}" | ||
| if [ "$total" -gt "$max_lines" ]; then | ||
| echo "Error: Total changed lines ($total) exceed the limit of $max_lines." | ||
| exit 1 | ||
| fi | ||
| - name: Check line count limit | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| script: | | ||
| const total = parseInt('${{ steps.line_count.outputs.lines_changed }}') || 0; | ||
| const additions = parseInt('${{ steps.line_count.outputs.additions }}') || 0; | ||
| const deletions = parseInt('${{ steps.line_count.outputs.deletions }}') || 0; | ||
| // Thresholds from inputs with fallback to defaults | ||
| const maxLines = parseInt('${{ inputs.max_lines }}') || 1000; | ||
| const xsMaxSize = parseInt('${{ inputs.xs_max_size }}') || 10; | ||
| const sMaxSize = parseInt('${{ inputs.s_max_size }}') || 100; | ||
| const mMaxSize = parseInt('${{ inputs.m_max_size }}') || 500; | ||
| const lMaxSize = parseInt('${{ inputs.l_max_size }}') || 1000; | ||
| // Print summary | ||
| console.log('Summary:'); | ||
| console.log(` - Additions: ${additions}`); | ||
| console.log(` - Deletions: ${deletions}`); | ||
| console.log(` - Total: ${total}`); | ||
| console.log(` - Limit: ${maxLines}`); | ||
| // Determine size label based on configured criteria | ||
| let sizeLabel = ''; | ||
| if (total <= xsMaxSize) { | ||
| sizeLabel = 'size-XS'; | ||
| } else if (total <= sMaxSize) { | ||
| sizeLabel = 'size-S'; | ||
| } else if (total <= mMaxSize) { | ||
| sizeLabel = 'size-M'; | ||
| } else if (total <= lMaxSize) { | ||
| sizeLabel = 'size-L'; | ||
| } else { | ||
| sizeLabel = 'size-XL'; | ||
| } | ||
| console.log(` - Size category: ${sizeLabel}`); | ||
| // Manage PR labels | ||
| const owner = context.repo.owner; | ||
| const repo = context.repo.repo; | ||
| const issue_number = context.payload.pull_request.number; | ||
jvbriones marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| try { | ||
| const existingSizeLabels = ['size-XS', 'size-S', 'size-M', 'size-L', 'size-XL']; | ||
| // Get current labels | ||
| const currentLabels = await github.rest.issues.listLabelsOnIssue({ | ||
| owner, | ||
| repo, | ||
| issue_number | ||
| }); | ||
| const currentLabelNames = currentLabels.data.map(l => l.name); | ||
| // Build new label set: keep non-size labels and add the new size label | ||
| const newLabels = currentLabelNames | ||
| .filter(name => !existingSizeLabels.includes(name)) // Remove all size labels | ||
| .concat(sizeLabel); // Add the correct size label | ||
| // Check if labels need updating | ||
| const currentSizeLabel = currentLabelNames.find(name => existingSizeLabels.includes(name)); | ||
| if (currentSizeLabel === sizeLabel && currentLabelNames.length === newLabels.length) { | ||
| console.log(`✅ Correct label '${sizeLabel}' already present, no changes needed`); | ||
| } else { | ||
| // Update all labels in a single API call | ||
| await github.rest.issues.setLabels({ | ||
| owner, | ||
| repo, | ||
| issue_number, | ||
| labels: newLabels | ||
| }); | ||
| if (currentSizeLabel && currentSizeLabel !== sizeLabel) { | ||
| console.log(` - Replaced '${currentSizeLabel}' with '${sizeLabel}'`); | ||
| } else if (!currentSizeLabel) { | ||
| console.log(`✅ Added '${sizeLabel}' label to PR #${issue_number}`); | ||
| } else { | ||
| console.log(`✅ Updated labels for PR #${issue_number}`); | ||
| } | ||
| } | ||
| } catch (error) { | ||
| console.log(`⚠️ Could not manage labels: ${error.message}`); | ||
| } | ||
| // Check if exceeds limit | ||
| if (total > maxLines) { | ||
| console.log(`❌ Error: Total changed lines (${total}) exceed the limit of ${maxLines}.`); | ||
| process.exit(1); | ||
| } else { | ||
| console.log(`✅ Success: Total changed lines (${total}) are within the limit of ${maxLines}.`); | ||
| } | ||
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.