Skip to content

Commit dd343aa

Browse files
committed
build: add script and lint job to strip related packages
1 parent a591e05 commit dd343aa

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

.github/workflows/lint_autofix.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,12 @@ jobs:
149149
files="${{ steps.changed-files.outputs.files }}"
150150
. "$GITHUB_WORKSPACE/.github/workflows/scripts/add_trailing_newlines" "$files"
151151
152+
# Remove related packages from README.md files:
153+
- name: 'Remove related packages from README.md files'
154+
run: |
155+
files="${{ steps.changed-files.outputs.files }}"
156+
. "$GITHUB_WORKSPACE/.github/workflows/scripts/remove_related_packages" "$files"
157+
152158
# Disable Git hooks:
153159
- name: 'Disable Git hooks'
154160
run: |
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/usr/bin/env bash
2+
#
3+
# @license Apache-2.0
4+
#
5+
# Copyright (c) 2024 The Stdlib Authors.
6+
#
7+
# Licensed under the Apache License, Version 2.0 (the "License");
8+
# you may not use this file except in compliance with the License.
9+
# You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
19+
# Script to remove related packages sections from README.md files.
20+
#
21+
# Usage: remove_related_packages file1 [file2 file3 ...]
22+
#
23+
# Arguments:
24+
#
25+
# file1 File path.
26+
# file2 File path.
27+
# file3 File path.
28+
29+
# shellcheck disable=SC2068
30+
31+
# Ensure that the exit status of pipelines is non-zero in the event that at least one of the commands in a pipeline fails:
32+
set -o pipefail
33+
34+
for file in ${@}; do
35+
if [[ $file == *README.md ]]; then
36+
awk '
37+
BEGIN { print_mode = 1; in_related = 0; in_related_links = 0 }
38+
/<section class="related">/ {
39+
print; print ""; print "</section>";
40+
in_related = 1; print_mode = 0; next
41+
}
42+
/<\/section>/ {
43+
if (in_related) { in_related = 0; print_mode = 1 }
44+
else { print }
45+
next
46+
}
47+
/<!-- <related-links> -->/ {
48+
print; print ""; print "<!-- </related-links> -->";
49+
in_related_links = 1; print_mode = 0; next
50+
}
51+
/<!-- <\/related-links> -->/ {
52+
if (in_related_links) { in_related_links = 0; print_mode = 1 }
53+
else { print }
54+
next
55+
}
56+
{ if (print_mode == 1) print }
57+
' "$file" > "${file}.tmp" && mv "${file}.tmp" "$file"
58+
fi
59+
done
60+
61+
echo "All files processed successfully."

0 commit comments

Comments
 (0)