Skip to content

Commit 15a712b

Browse files
committed
Address review comments
1 parent 9b6438e commit 15a712b

6 files changed

Lines changed: 205 additions & 329 deletions

File tree

.github/workflows/pr-checks.yml

Lines changed: 92 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@ jobs:
7878
if: github.triggering_actor != 'dependabot[bot]'
7979
permissions:
8080
contents: read
81-
pull-requests: write
82-
runs-on: ubuntu-slim
81+
runs-on: ubuntu-latest
8382
timeout-minutes: 10
8483

8584
concurrency:
@@ -89,10 +88,6 @@ jobs:
8988
steps:
9089
- name: Checkout repository
9190
uses: actions/checkout@v6
92-
with:
93-
# Need full history so we have both the PR merge commit (HEAD) and the base SHA locally
94-
# for `git archive` to work against either.
95-
fetch-depth: 0
9691

9792
- name: Set up Node.js
9893
uses: actions/setup-node@v6
@@ -110,33 +105,54 @@ jobs:
110105
working-directory: pr-checks
111106
run: npx tsx --test
112107

108+
- name: Verify all Actions use the same Node version
109+
id: head-version
110+
run: |
111+
NODE_VERSION=$(find . -path "*/node_modules" -prune -o -name "action.yml" -exec yq -o=json '.runs.using' {} \; | jq -rs '[.[] | select(. != null and startswith("node"))] | unique | .[]')
112+
echo "NODE_VERSION: ${NODE_VERSION}"
113+
if [[ $(echo "$NODE_VERSION" | wc -l) -gt 1 ]]; then
114+
echo "::error::More than one node version used in 'action.yml' files."
115+
exit 1
116+
fi
117+
echo "node_version=${NODE_VERSION}" >> $GITHUB_OUTPUT
118+
119+
- name: Fetch base commit
120+
# Forks and Dependabot PRs don't have permission to write comments, so skip the repo size
121+
# check in those cases.
122+
if: >-
123+
github.event_name == 'pull_request' &&
124+
github.event.pull_request.head.repo.full_name == github.repository &&
125+
github.event.pull_request.user.login != 'dependabot[bot]'
126+
env:
127+
BASE_SHA: ${{ github.event.pull_request.base.sha }}
128+
run: git fetch --no-tags --depth=1 origin "$BASE_SHA"
129+
113130
- name: Check repo size
114-
# Forks and Dependabot PRs don't have permission to write comments, so skip the check in
115-
# those cases.
131+
# Forks and Dependabot PRs don't have permission to write comments, so skip the repo size
132+
# check in those cases.
116133
if: >-
117134
github.event_name == 'pull_request' &&
118135
github.event.pull_request.head.repo.full_name == github.repository &&
119136
github.event.pull_request.user.login != 'dependabot[bot]'
120137
working-directory: pr-checks
121138
env:
122-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
123139
BASE_REF: ${{ github.event.pull_request.base.ref }}
124140
BASE_SHA: ${{ github.event.pull_request.base.sha }}
125-
PR_NUMBER: ${{ github.event.pull_request.number }}
126-
GITHUB_REPOSITORY: ${{ github.repository }}
127141
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
128-
run: npx tsx check-repo-size.ts
142+
run: npx tsx check-repo-size.ts --output-dir "$RUNNER_TEMP/repo-size"
129143

130-
- name: Verify all Actions use the same Node version
131-
id: head-version
132-
run: |
133-
NODE_VERSION=$(find . -name "action.yml" -exec yq -e '.runs.using' {} \; | grep node | sort | uniq)
134-
echo "NODE_VERSION: ${NODE_VERSION}"
135-
if [[ $(echo "$NODE_VERSION" | wc -l) -gt 1 ]]; then
136-
echo "::error::More than one node version used in 'action.yml' files."
137-
exit 1
138-
fi
139-
echo "node_version=${NODE_VERSION}" >> $GITHUB_OUTPUT
144+
- name: Upload repo size comment
145+
# Forks and Dependabot PRs don't have permission to write comments, so skip the repo size
146+
# check in those cases.
147+
if: >-
148+
github.event_name == 'pull_request' &&
149+
github.event.pull_request.head.repo.full_name == github.repository &&
150+
github.event.pull_request.user.login != 'dependabot[bot]'
151+
uses: actions/upload-artifact@v7
152+
with:
153+
name: repo-size-comment
154+
path: ${{ runner.temp }}/repo-size/
155+
if-no-files-found: error
140156

141157
- name: 'Backport: Check out base ref'
142158
id: checkout-base
@@ -150,10 +166,63 @@ jobs:
150166
env:
151167
HEAD_VERSION: ${{ steps.head-version.outputs.node_version }}
152168
run: |
153-
BASE_VERSION=$(find . -name "action.yml" -exec yq -e '.runs.using' {} \; | grep node | sort | uniq)
169+
BASE_VERSION=$(find . -path "*/node_modules" -prune -o -name "action.yml" -exec yq -o=json '.runs.using' {} \; | jq -rs '[.[] | select(. != null and startswith("node"))] | unique | .[]')
154170
echo "HEAD_VERSION: ${HEAD_VERSION}"
155171
echo "BASE_VERSION: ${BASE_VERSION}"
156172
if [[ "$BASE_VERSION" != "$HEAD_VERSION" ]]; then
157173
echo "::error::Cannot change the Node version of an Action in a backport PR."
158174
exit 1
159175
fi
176+
177+
post-repo-size-comment:
178+
name: Post repo size comment
179+
needs: pr-checks
180+
# Keep write permissions isolated from the job that checks out and tests PR code. This job only
181+
# posts the candidate comment body produced by the read-only `pr-checks` job.
182+
if: >-
183+
github.event_name == 'pull_request' &&
184+
github.event.pull_request.head.repo.full_name == github.repository &&
185+
github.event.pull_request.user.login != 'dependabot[bot]' &&
186+
needs.pr-checks.result == 'success'
187+
permissions:
188+
contents: read
189+
pull-requests: write
190+
runs-on: ubuntu-slim
191+
timeout-minutes: 10
192+
193+
concurrency:
194+
cancel-in-progress: true
195+
group: check-repo-size-${{ github.event.pull_request.number }}
196+
197+
steps:
198+
- name: Download repo size comment
199+
uses: actions/download-artifact@v8
200+
with:
201+
name: repo-size-comment
202+
path: repo-size-comment
203+
204+
- name: Post repo size comment
205+
env:
206+
COMMENT_MARKER: "<!-- repo-size-diff-bot -->"
207+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
208+
GITHUB_REPOSITORY: ${{ github.repository }}
209+
PR_NUMBER: ${{ github.event.pull_request.number }}
210+
run: |
211+
significant=$(jq -r '.significant' repo-size-comment/metadata.json)
212+
body=$(cat repo-size-comment/body.md)
213+
comment_id=$(
214+
gh api "repos/$GITHUB_REPOSITORY/issues/$PR_NUMBER/comments" \
215+
--paginate \
216+
--jq ".[] | select(.body | contains(\"$COMMENT_MARKER\")) | .id" \
217+
| head -n 1
218+
)
219+
220+
if [[ -n "$comment_id" ]]; then
221+
echo "Updating existing comment $comment_id."
222+
gh api --method PATCH "repos/$GITHUB_REPOSITORY/issues/comments/$comment_id" --field body="$body"
223+
elif [[ "$significant" == "true" ]]; then
224+
echo "Creating new repo size comment."
225+
gh api --method POST "repos/$GITHUB_REPOSITORY/issues/$PR_NUMBER/comments" --field body="$body"
226+
else
227+
echo "Skipping repo size comment because the delta is below the threshold and no sticky comment exists."
228+
fi

package-lock.json

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)