|
| 1 | +name: Track Earthly to Earthbuild Progress |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [opened, synchronize] |
| 6 | + |
| 7 | +jobs: |
| 8 | + count-earthly: |
| 9 | + runs-on: ubuntu-24.04-arm |
| 10 | + permissions: |
| 11 | + contents: read |
| 12 | + pull-requests: write |
| 13 | + |
| 14 | + steps: |
| 15 | + - name: Checkout PR branch |
| 16 | + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 |
| 17 | + with: |
| 18 | + fetch-depth: 0 |
| 19 | + |
| 20 | + - name: Count occurrences in PR branch |
| 21 | + id: count_pr |
| 22 | + run: | |
| 23 | + # Count total occurrences |
| 24 | + total_count=$(git grep -i "earthly" -- ':!.github/workflows/earthly-count.yml' 2>/dev/null | wc -l || echo "0") |
| 25 | + echo "total_count=$total_count" >> $GITHUB_OUTPUT |
| 26 | +
|
| 27 | + # Count by file type |
| 28 | + go_count=$(git grep -i "earthly" -- "*.go" 2>/dev/null | wc -l || echo "0") |
| 29 | + md_count=$(git grep -i "earthly" -- "*.md" 2>/dev/null | wc -l || echo "0") |
| 30 | + earthfile_count=$(($(git grep -i "earthly" -- "Earthfile" 2>/dev/null | wc -l || echo "0") + $(git grep -i "earthly" -- "*.earth" 2>/dev/null | wc -l || echo "0"))) |
| 31 | +
|
| 32 | + echo "go_count=$go_count" >> $GITHUB_OUTPUT |
| 33 | + echo "md_count=$md_count" >> $GITHUB_OUTPUT |
| 34 | + echo "earthfile_count=$earthfile_count" >> $GITHUB_OUTPUT |
| 35 | +
|
| 36 | + echo "PR branch - Total: $total_count (Go: $go_count, MD: $md_count, Earthfiles: $earthfile_count)" |
| 37 | +
|
| 38 | + - name: Checkout main branch |
| 39 | + run: | |
| 40 | + git checkout origin/main |
| 41 | +
|
| 42 | + - name: Count occurrences in main branch |
| 43 | + id: count_main |
| 44 | + run: | |
| 45 | + # Count total occurrences |
| 46 | + total_count=$(git grep -i "earthly" -- ':!.github/workflows/earthly-count.yml' 2>/dev/null | wc -l || echo "0") |
| 47 | + echo "main_total_count=$total_count" >> $GITHUB_OUTPUT |
| 48 | +
|
| 49 | + # Count by file type |
| 50 | + go_count=$(git grep -i "earthly" -- "*.go" 2>/dev/null | wc -l || echo "0") |
| 51 | + md_count=$(git grep -i "earthly" -- "*.md" 2>/dev/null | wc -l || echo "0") |
| 52 | + earthfile_count=$(($(git grep -i "earthly" -- "Earthfile" 2>/dev/null | wc -l || echo "0") + $(git grep -i "earthly" -- "*.earth" 2>/dev/null | wc -l || echo "0"))) |
| 53 | +
|
| 54 | + echo "main_go_count=$go_count" >> $GITHUB_OUTPUT |
| 55 | + echo "main_md_count=$md_count" >> $GITHUB_OUTPUT |
| 56 | + echo "main_earthfile_count=$earthfile_count" >> $GITHUB_OUTPUT |
| 57 | +
|
| 58 | + echo "Main branch - Total: $total_count (Go: $go_count, MD: $md_count, Earthfiles: $earthfile_count)" |
| 59 | +
|
| 60 | + - name: Calculate difference |
| 61 | + id: calculate |
| 62 | + run: | |
| 63 | + pr_count=${{ steps.count_pr.outputs.total_count }} |
| 64 | + main_count=${{ steps.count_main.outputs.main_total_count }} |
| 65 | + difference=$((main_count - pr_count)) |
| 66 | +
|
| 67 | + # Calculate percentage with proper formatting |
| 68 | + if [ $main_count -gt 0 ]; then |
| 69 | + # Use awk for better decimal handling |
| 70 | + percentage=$(awk "BEGIN {printf \"%.2f\", $difference * 100 / $main_count}") |
| 71 | + else |
| 72 | + percentage="0.00" |
| 73 | + fi |
| 74 | +
|
| 75 | + echo "difference=$difference" >> $GITHUB_OUTPUT |
| 76 | + echo "percentage=$percentage" >> $GITHUB_OUTPUT |
| 77 | + echo "pr_count=$pr_count" >> $GITHUB_OUTPUT |
| 78 | + echo "main_count=$main_count" >> $GITHUB_OUTPUT |
| 79 | +
|
| 80 | + # Calculate differences by type |
| 81 | + go_diff=$((${{ steps.count_main.outputs.main_go_count }} - ${{ steps.count_pr.outputs.go_count }})) |
| 82 | + md_diff=$((${{ steps.count_main.outputs.main_md_count }} - ${{ steps.count_pr.outputs.md_count }})) |
| 83 | + earthfile_diff=$((${{ steps.count_main.outputs.main_earthfile_count }} - ${{ steps.count_pr.outputs.earthfile_count }})) |
| 84 | +
|
| 85 | + echo "go_diff=$go_diff" >> $GITHUB_OUTPUT |
| 86 | + echo "md_diff=$md_diff" >> $GITHUB_OUTPUT |
| 87 | + echo "earthfile_diff=$earthfile_diff" >> $GITHUB_OUTPUT |
| 88 | +
|
| 89 | + - name: Comment on PR |
| 90 | + uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0 |
| 91 | + with: |
| 92 | + script: | |
| 93 | + const prCount = ${{ steps.calculate.outputs.pr_count }}; |
| 94 | + const mainCount = ${{ steps.calculate.outputs.main_count }}; |
| 95 | + const difference = ${{ steps.calculate.outputs.difference }}; |
| 96 | + const percentage = '${{ steps.calculate.outputs.percentage }}'; |
| 97 | +
|
| 98 | + // File type differences |
| 99 | + const goDiff = ${{ steps.calculate.outputs.go_diff }}; |
| 100 | + const mdDiff = ${{ steps.calculate.outputs.md_diff }}; |
| 101 | + const earthfileDiff = ${{ steps.calculate.outputs.earthfile_diff }}; |
| 102 | +
|
| 103 | + let emoji = '📊'; |
| 104 | + let message = ''; |
| 105 | +
|
| 106 | + if (difference > 0) { |
| 107 | + emoji = '🎉'; |
| 108 | + message = `Great progress! You've reduced "earthly" occurrences by **${difference}** (${percentage}%)`; |
| 109 | + } else if (difference < 0) { |
| 110 | + emoji = '⚠️'; |
| 111 | + message = `Warning: "earthly" occurrences have increased by **${Math.abs(difference)}** (${Math.abs(parseFloat(percentage))}%)`; |
| 112 | + } else { |
| 113 | + emoji = '➖'; |
| 114 | + message = 'No change in "earthly" occurrences'; |
| 115 | + } |
| 116 | +
|
| 117 | + // Build detailed breakdown |
| 118 | + let breakdown = ''; |
| 119 | + if (goDiff !== 0 || mdDiff !== 0 || earthfileDiff !== 0) { |
| 120 | + breakdown = ` |
| 121 | +
|
| 122 | + ### 📁 Changes by file type: |
| 123 | + | File Type | Change | |
| 124 | + |-----------|--------| |
| 125 | + | Go files (.go) | ${goDiff > 0 ? '✅ -' + goDiff : goDiff < 0 ? '❌ +' + Math.abs(goDiff) : '➖ No change'} | |
| 126 | + | Documentation (.md) | ${mdDiff > 0 ? '✅ -' + mdDiff : mdDiff < 0 ? '❌ +' + Math.abs(mdDiff) : '➖ No change'} | |
| 127 | + | Earthfiles | ${earthfileDiff > 0 ? '✅ -' + earthfileDiff : earthfileDiff < 0 ? '❌ +' + Math.abs(earthfileDiff) : '➖ No change'} |`; |
| 128 | + } |
| 129 | +
|
| 130 | + const body = `## ${emoji} Are we earthbuild yet? |
| 131 | +
|
| 132 | + ${message} |
| 133 | +
|
| 134 | + ### 📈 Overall Progress |
| 135 | + | Branch | Total Count | |
| 136 | + |--------|-------------| |
| 137 | + | main | ${mainCount} | |
| 138 | + | This PR | ${prCount} | |
| 139 | + | **Difference** | **${difference > 0 ? '-' : '+'}${Math.abs(difference)}** ${difference !== 0 ? `(${Math.abs(parseFloat(percentage))}%)` : ''} | |
| 140 | + ${breakdown} |
| 141 | +
|
| 142 | + --- |
| 143 | + *Keep up the great work migrating from Earthly to Earthbuild!* 🚀 |
| 144 | +
|
| 145 | + <details> |
| 146 | + <summary>💡 Tips for finding more occurrences</summary> |
| 147 | +
|
| 148 | + Run locally to see detailed breakdown: |
| 149 | + \`\`\`bash |
| 150 | + ./.github/scripts/count-earthly.sh |
| 151 | + \`\`\` |
| 152 | +
|
| 153 | + **Note that the goal is not to reach 0.** |
| 154 | + There is anticipated to be at least _some_ occurences of \`earthly\` in the source code due to backwards compatibility with config files and language constructs. |
| 155 | + </details>`; |
| 156 | +
|
| 157 | + // Find existing comment |
| 158 | + const { data: comments } = await github.rest.issues.listComments({ |
| 159 | + owner: context.repo.owner, |
| 160 | + repo: context.repo.repo, |
| 161 | + issue_number: context.issue.number, |
| 162 | + }); |
| 163 | +
|
| 164 | + const botComment = comments.find(comment => |
| 165 | + comment.user.type === 'Bot' && |
| 166 | + comment.body.includes('Are we earthbuild yet?') |
| 167 | + ); |
| 168 | +
|
| 169 | + if (botComment) { |
| 170 | + // Update existing comment |
| 171 | + await github.rest.issues.updateComment({ |
| 172 | + owner: context.repo.owner, |
| 173 | + repo: context.repo.repo, |
| 174 | + comment_id: botComment.id, |
| 175 | + body: body |
| 176 | + }); |
| 177 | + } else { |
| 178 | + // Create new comment |
| 179 | + await github.rest.issues.createComment({ |
| 180 | + owner: context.repo.owner, |
| 181 | + repo: context.repo.repo, |
| 182 | + issue_number: context.issue.number, |
| 183 | + body: body |
| 184 | + }); |
| 185 | + } |
0 commit comments