chesnokoff commented on code in PR #13876:
URL: https://github.com/apache/ignite/pull/13876#discussion_r4692108928
##########
.github/workflows/check-protected-classes.yml:
##########
@@ -13,119 +13,91 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-name: Protected Classes
+name: Wire format report
-# pull_request_target for the write token needed to comment/label the PR. The
fork's changes are
-# read through the API as data and never checked out or executed, so no
allow-unsafe-pr-checkout and
-# no working copy of the PR code on the runner. Do not add a step that builds
or runs the PR code.
-on: pull_request_target
+on:
+ workflow_run:
+ workflows: ['Code Style, Abandoned Tests, Javadocs']
+ types: [completed]
-concurrency:
- group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
- cancel-in-progress: true
+permissions: {}
jobs:
- check-protected-classes:
+ report:
+ if: github.event.workflow_run.event == 'pull_request'
runs-on: ubuntu-latest
- name: Rolling Upgrade check
+ concurrency:
+ group: wire-report-${{ github.event.workflow_run.head_repository.id
}}-${{ github.event.workflow_run.head_branch }}
+ queue: max
permissions:
- issues: write
+ actions: read
pull-requests: write
- checks: write
steps:
- - name: Detect protected class changes and report
+ - name: Report the wire comparison
uses: actions/github-script@v8
with:
script: |
- const ORDER_USE = '@Order(';
- const ORDER_IMPORT = 'import org.apache.ignite.internal.Order;';
- const ORDER_PKG = 'package org.apache.ignite.internal;';
- const MARKER = '<!-- ignite-rolling-upgrade-check -->';
- const { owner, repo } = context.repo;
- const pr = context.payload.pull_request;
- const baseSha = pr.base.sha;
- const headSha = pr.head.sha;
-
- // Changed files are read from the API as data; the fork's code is
never checked out or executed.
- const files = await github.paginate(github.rest.pulls.listFiles, {
- owner, repo, pull_number: pr.number, per_page: 100,
- });
-
- // Reproduce `git diff --no-renames --diff-filter=ADM`: a rename
is a delete(old)+add(new) pair.
- // A protected class carries the @Order annotation; an added file
is defined by the head revision,
- // a deleted/modified one by the base.
- const revisions = [];
- for (const f of files) {
- if (f.status === 'added' || f.status === 'copied')
- revisions.push([f.filename, headSha]);
- else if (f.status === 'removed' || f.status === 'modified' ||
f.status === 'changed')
- revisions.push([f.filename, baseSha]);
- else if (f.status === 'renamed') {
- revisions.push([f.previous_filename, baseSha]);
- revisions.push([f.filename, headSha]);
- }
+ const label = 'compatibility';
+ const marker = '<!-- ignite-rolling-upgrade-check -->';
+
+ const run = context.payload.workflow_run;
+ const repo = context.repo;
+ const {actions, issues, pulls} = github.rest;
+ const singleOrUndefined = items => items.length === 1 ? items[0] :
undefined;
+ const list = (method, params) => github.paginate(method, {...repo,
...params, per_page: 100});
+
+ function findStepConclusion(job, name) {
+ return singleOrUndefined(job?.steps?.filter(step => step.name
=== name && step.status === 'completed') ?? [])?.conclusion;
}
- const isProtected = async (path, ref) => {
- let meta;
- try {
- ({ data: meta } = await github.rest.repos.getContent({ owner,
repo, path, ref }));
- } catch (e) {
- if (e.status === 404) return false;
- throw e;
- }
- if (Array.isArray(meta) || meta.type !== 'file') return false;
- let content = meta.content ? Buffer.from(meta.content,
'base64').toString('utf8') : '';
- if (!content && meta.sha) {
- const { data: blob } = await github.rest.git.getBlob({ owner,
repo, file_sha: meta.sha });
- content = Buffer.from(blob.content,
blob.encoding).toString('utf8');
- }
- const lines = content.split(/\r?\n/);
-
- return content.includes(ORDER_USE)
- && (lines.includes(ORDER_IMPORT) || lines.includes(ORDER_PKG));
- };
-
- const hits = [];
- for (const [path, ref] of revisions) {
- if (path.endsWith('.java')
- && !path.startsWith('modules/core/src/test/resources/codegen/')
- && await isProtected(path, ref)) hits.push(path);
+ async function findPullRequestForRun(run) {
+ if (run.pull_requests.length) return
singleOrUndefined(run.pull_requests);
+
+ const head =
`${run.head_repository.owner.login}:${run.head_branch}`;
+ const candidates = await list(pulls.list, {head, state: 'all'});
+ return singleOrUndefined(candidates.filter(pr =>
pr.head.repo?.id === run.head_repository.id
+ && pr.created_at <= run.created_at && (!pr.closed_at ||
pr.closed_at >= run.created_at)));
}
- if (hits.length === 0) return;
-
- // File names come from the fork; render them as inert inline code
so they cannot inject
- // markdown (backticks, @mentions, links) into content posted
under the bot's write token.
- const safe = f => '`' + String(f).replace(/[`\r\n]/g, '') + '`';
- const list = hits.map(f => '- ' + safe(f)).join('\n');
- const summary = [
- 'This PR modifies protected classes (with **Order**
annotation).',
- 'Changes to these classes can break rolling upgrade
compatibility.',
- '',
- '**Affected files:**',
- list,
- ].join('\n');
- const body = MARKER + '\n## Possible compatibility issues. Please,
check rolling upgrade cases\n\n' + summary + '\n';
-
- const comments = await
github.paginate(github.rest.issues.listComments, {
- owner, repo, issue_number: pr.number,
- });
- const existing = comments.find(c => c.body.includes(MARKER));
- if (existing) {
- await github.rest.issues.deleteComment({ owner, repo,
comment_id: existing.id });
+ const jobs = await list(actions.listJobsForWorkflowRun, {run_id:
run.id});
+ const wire = singleOrUndefined(jobs.filter(job => job.name ===
'Compare wire format descriptions'));
+ const java = singleOrUndefined(jobs.filter(job => job.name ===
'Check java code on JDK 17'));
+ const upload = findStepConclusion(wire, 'Upload wire diff');
+ if (wire?.conclusion !== 'success' || findStepConclusion(wire,
'Compare descriptions and publish summary') !== 'success'
+ || findStepConclusion(java, 'Check all wire format descriptions
are collected') !== 'success'
+ || !['success', 'skipped'].includes(upload))
+ return core.info('The wire comparison or completeness check
could not be verified.');
+
+ const target = await findPullRequestForRun(run);
+ if (!target)
+ return core.info('Could not identify the PR and its target
branch.');
+
+ const issue = {...repo, issue_number: target.number};
+ const comments = await list(issues.listComments, issue);
+ const {data: pr} = await pulls.get({...repo, pull_number:
target.number});
+ if (pr.state !== 'open' || pr.head.repo?.id !==
run.head_repository.id || pr.head.ref !== run.head_branch
+ || pr.head.sha !== run.head_sha || pr.base.ref !==
target.base.ref)
+ return core.info('The PR has closed or changed since the
comparison.');
+
+ for (const comment of comments) {
+ if (comment.user?.login === 'github-actions[bot]' &&
comment.body?.startsWith(marker))
+ await issues.deleteComment({...repo, comment_id: comment.id});
Review Comment:
Fixed
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]