mirror of
https://github.com/espressif/openthread.git
synced 2026-08-13 14:17:47 +00:00
The API github.rest.repos.listPullRequestsAssociatedWithCommit() can only query commits from the repo owning those commits. Although a fork PR is pushed to the base repo, the base repo doesn't have the commit yet. This commit changes the workflow to query pull request from head repo.
114 lines
4.4 KiB
YAML
114 lines
4.4 KiB
YAML
#
|
|
# Copyright (c) 2026, The OpenThread Authors.
|
|
# All rights reserved.
|
|
#
|
|
# Redistribution and use in source and binary forms, with or without
|
|
# modification, are permitted provided that the following conditions are met:
|
|
# 1. Redistributions of source code must retain the above copyright
|
|
# notice, this list of conditions and the following disclaimer.
|
|
# 2. Redistributions in binary form must reproduce the above copyright
|
|
# notice, this list of conditions and the following disclaimer in the
|
|
# documentation and/or other materials provided with the distribution.
|
|
# 3. Neither the name of the copyright holder nor the
|
|
# names of its contributors may be used to endorse or promote products
|
|
# derived from this software without specific prior written permission.
|
|
#
|
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
# POSSIBILITY OF SUCH DAMAGE.
|
|
#
|
|
|
|
name: Size Report
|
|
|
|
on:
|
|
# zizmor: ignore[dangerous-triggers] - {workflow_run is required to comment on PRs from forks and does not execute untrusted code}
|
|
workflow_run:
|
|
workflows: ["Size Check"]
|
|
types:
|
|
- completed
|
|
|
|
permissions:
|
|
contents: read
|
|
pull-requests: write
|
|
|
|
jobs:
|
|
|
|
size-report:
|
|
if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success'
|
|
runs-on: ubuntu-24.04
|
|
steps:
|
|
- name: Download report
|
|
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
|
|
with:
|
|
name: report_pr
|
|
path: /tmp/ot-size-report
|
|
run-id: ${{ github.event.workflow_run.id }}
|
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Post Report
|
|
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3
|
|
id: post-report
|
|
with:
|
|
script: |
|
|
const fs = require('fs')
|
|
|
|
const report = fs.readFileSync('/tmp/ot-size-report/report_pr', 'utf8')
|
|
|
|
let pr_number = context.payload.workflow_run.pull_requests?.[0]?.number
|
|
|
|
if (!pr_number) {
|
|
const head_repo = context.payload.workflow_run.head_repository?.full_name;
|
|
if (!head_repo) {
|
|
core.setFailed('Head repository not found in workflow run context payload.');
|
|
return;
|
|
}
|
|
const [owner, repo] = head_repo.split('/')
|
|
const { data: prs } = await github.rest.repos.listPullRequestsAssociatedWithCommit({
|
|
owner,
|
|
repo,
|
|
commit_sha: context.payload.workflow_run.head_sha,
|
|
})
|
|
const base_full_name = `${context.repo.owner}/${context.repo.repo}`
|
|
const pr = prs?.find(pr => pr.base.repo.full_name === base_full_name && pr.state === 'open') ||
|
|
prs?.find(pr => pr.base.repo.full_name === base_full_name);
|
|
if (pr) {
|
|
pr_number = pr.number
|
|
}
|
|
}
|
|
|
|
if (!pr_number) {
|
|
core.setFailed('Could not determine PR number for workflow run')
|
|
return
|
|
}
|
|
|
|
const params = {
|
|
issue_number: pr_number,
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
body: report,
|
|
}
|
|
|
|
const response = await github.rest.issues.listComments({
|
|
issue_number: pr_number,
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
})
|
|
|
|
const kMagicHeader = '<!-- Size Report of **OpenThread** -->'
|
|
const comment = response.data.find(comment => comment.body.startsWith(kMagicHeader))
|
|
|
|
if (comment) {
|
|
params.comment_id = comment.id;
|
|
await github.rest.issues.updateComment(params)
|
|
} else {
|
|
await github.rest.issues.createComment(params)
|
|
}
|