|
| 1 | +# Copyright 2022 The Matrix.org Foundation C.I.C. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | +import sys |
| 15 | + |
| 16 | +GROUP_START_PREFIX = "::group::" |
| 17 | +PASSING_CI_PREFIX = "✅" |
| 18 | +GROUP_END_PREFIX = "::endgroup::" |
| 19 | + |
| 20 | + |
| 21 | +def main() -> None: |
| 22 | + in_collapsed_block = False |
| 23 | + first_group_name = None |
| 24 | + last_group_name = None |
| 25 | + buffer = [] |
| 26 | + |
| 27 | + def flush_buffer() -> None: |
| 28 | + nonlocal buffer, in_collapsed_block |
| 29 | + |
| 30 | + sys.stdout.write(f"::group::{first_group_name} ... {last_group_name}\n") |
| 31 | + for buffered_line in buffer: |
| 32 | + sys.stdout.write(buffered_line) |
| 33 | + |
| 34 | + sys.stdout.write("::endgroup::\n") |
| 35 | + |
| 36 | + in_collapsed_block = False |
| 37 | + buffer = [] |
| 38 | + |
| 39 | + for line in sys.stdin: |
| 40 | + if line.startswith(GROUP_START_PREFIX): |
| 41 | + group_name = line[len(GROUP_START_PREFIX) :] |
| 42 | + should_skip_block = group_name.startswith(PASSING_CI_PREFIX) |
| 43 | + |
| 44 | + if in_collapsed_block and not should_skip_block: |
| 45 | + flush_buffer() |
| 46 | + elif in_collapsed_block and should_skip_block: |
| 47 | + last_group_name = group_name |
| 48 | + elif not in_collapsed_block and should_skip_block: |
| 49 | + first_group_name = group_name |
| 50 | + in_collapsed_block = True |
| 51 | + |
| 52 | + if not in_collapsed_block: |
| 53 | + sys.stdout.write(line) |
| 54 | + |
| 55 | + flush_buffer() |
| 56 | + |
| 57 | + |
| 58 | +if __name__ == "__main__": |
| 59 | + main() |
0 commit comments