@@ -74,20 +74,10 @@ jobs:
7474
7575 echo "SERIES_DIR=/tmp/series" >> $GITHUB_ENV
7676
77- - name : Check for label 'no-ml' to skip sending emails
78- id : checklabel
79- run : |
80- # Skip if PR has label "no-ml"
81- if echo "$PR_LABELS" | grep -qiE "(^|,)no-ml(,|$)"; then
82- echo "Opt-out label present: skipping mailing list." | tee $GITHUB_STEP_SUMMARY
83- echo "skip_sending=1" >> $GITHUB_OUTPUT
84- else
85- echo "skip_sending=0" >> $GITHUB_OUTPUT
86- fi
87-
8877 - name : Get commit list from PR and skip the internal ones
8978 id : commits
90- if : ${{ steps.checklabel.outputs.skip_sending != '1' }}
79+ env :
80+ MAX_NUM_COMMITS : 30
9181 run : |
9282 # Skip commits that touches any of these
9383 patterns=(".github/"
@@ -106,34 +96,55 @@ jobs:
10696 # Fetch commits from the pull request (maybe they're from another repository)
10797 git fetch origin "pull/$PR_NUMBER/head"
10898
109- gh api repos/$GITHUB_REPOSITORY/pulls/$PR_NUMBER/commits --jq '.[].sha' | while read SHA1; do
99+ TOTAL=$(gh api repos/$GITHUB_REPOSITORY/pulls/$PR_NUMBER/commits --paginate --jq '.[].sha'|wc -l)
100+ if [ "${TOTAL}" -gt "$MAX_NUM_COMMITS" ]; then
101+ echo "Pull request has too many commits"
102+ echo "has_commits=false" >> $GITHUB_OUTPUT
103+ exit 0
104+ fi
105+
106+ gh api repos/$GITHUB_REPOSITORY/pulls/$PR_NUMBER/commits --paginate --jq '.[].sha' | while read SHA1; do
110107 echo "Looking at $SHA1"
111108 if grep -q -E "$regex" <(git diff-tree --no-commit-id --name-only -r "$SHA1"); then
112109 echo "Touching something not to be upstreamed, skipping commit $SHA1"
113110 else
111+ echo "Adding one commit to the send list"
114112 echo "$SHA1" >> /tmp/commits.txt
115113 fi
116114 done
117115
118116 if [ ! -f /tmp/commits.txt ]; then
119117 echo "No commits to send email for" | tee $GITHUB_STEP_SUMMARY
120118 echo "has_commits=false" >> $GITHUB_OUTPUT
121- else
122- COUNT=$(wc -l < /tmp/commits.txt)
123- echo "COUNT=$COUNT" >> $GITHUB_ENV
124- echo "has_commits=true" >> $GITHUB_OUTPUT
119+ exit 0
125120 fi
126121
127- - name : Check what to do based on series' size
128- if : steps.commits.outputs.has_commits == 'true'
122+ COUNT=$(wc -l < /tmp/commits.txt)
123+ echo "Has $COUNT commits in the series"
124+
125+ echo "has_commits=true" >> $GITHUB_OUTPUT
126+
127+ - name : Check for label 'no-ml' to skip sending emails
128+ id : checklabel
129129 run : |
130- MAX=150
131- if [ "${COUNT}" -gt "$MAX" ]; then
132- echo "Series has $COUNT commits (> $MAX). Not doing anything" | tee $GITHUB_STEP_SUMMARY
130+ # Skip if PR has label "no-ml"
131+ if echo "$PR_LABELS" | grep -qiE "(^|,)no-ml(,|$)"; then
132+ echo "Opt-out label present: skipping mailing list." | tee $GITHUB_STEP_SUMMARY
133+ echo "skip=true" >> $GITHUB_OUTPUT
134+ else
135+ echo "No opt-out label found"
136+ echo "skip=false" >> $GITHUB_OUTPUT
133137 fi
134138
139+ - name : Decide if we're sending something or not
140+ id : send_emails
141+ if : ( steps.commits.outputs.has_commits == 'true' &&
142+ steps.checklabel.outputs.skip == 'false' )
143+ run : |
144+ echo "enabled=true" >> $GITHUB_OUTPUT
145+
135146 - name : Prepare patch series
136- if : steps.commits .outputs.has_commits == 'true'
147+ if : steps.send_emails .outputs.enabled == 'true'
137148 run : |
138149 set -euo pipefail
139150
@@ -144,9 +155,6 @@ jobs:
144155 git cherry-pick "$sha"
145156 done < /tmp/commits.txt
146157
147- # Build cover letter text
148- N="${COUNT:-0}"
149- TITLE="$(printf '[PATCH 0/%d] PR #%s: %s' "$N" "$PR_NUMBER" "$PR_TITLE")"
150158
151159 echo "This change was merged into the gccrs repository and is posted here for" >> /tmp/description.txt
152160 echo "upstream visibility and potential drive-by review, as requested by GCC" >> /tmp/description.txt
@@ -190,7 +198,7 @@ jobs:
190198 done < <(find /tmp/series/ -maxdepth 1 -type f -print0|sort -z -n)
191199
192200 - name : Send series via git send-email
193- if : steps.commits .outputs.has_commits == 'true'
201+ if : steps.send_emails .outputs.enabled == 'true'
194202 env :
195203 GIT_SMTP_SERVER : ${{ secrets.SMTP_SERVER }}
196204 GIT_SMTP_ENCRYPTION : tls
0 commit comments