Skip to content

Commit f1d9bfb

Browse files
committed
リンクチェックCI : URLをコマンドライン引数で指定できるようにした
1 parent ab36172 commit f1d9bfb

File tree

1 file changed

+35
-27
lines changed

1 file changed

+35
-27
lines changed

.github/workflows/script/link_check.py

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ def add_link(origin_link: str):
122122
dest='check_outer_link',
123123
action='store_true',
124124
default=False)
125+
argparser.add_argument("--url",
126+
dest='url',
127+
type=str,
128+
default='')
125129
args = argparser.parse_args()
126130

127131
if not args.check_inner_link and not args.check_outer_link:
@@ -131,36 +135,40 @@ def add_link(origin_link: str):
131135
found_error = False
132136
current_dir = os.getcwd()
133137
outer_link_dict = dict()
134-
for p in glob.glob("**/*.md", recursive=True):
135-
dirname = os.path.dirname(p)
136-
with open(p) as f:
137-
text = f.read()
138-
139-
inner_links, outer_links = find_all_links(text)
140-
for link in outer_links:
141-
if link in outer_link_dict:
142-
outer_link_dict[link].append(p)
143-
else:
144-
outer_link_dict[link] = [p]
145-
146-
if args.check_inner_link:
147-
for link in inner_links:
148-
rel_link = ""
149-
if link.startswith("/"):
150-
rel_link = os.path.join(current_dir, link.lstrip("/"))
138+
if len(args.url) <= 0:
139+
for p in glob.glob("**/*.md", recursive=True):
140+
dirname = os.path.dirname(p)
141+
with open(p) as f:
142+
text = f.read()
143+
144+
inner_links, outer_links = find_all_links(text)
145+
for link in outer_links:
146+
if link in outer_link_dict:
147+
outer_link_dict[link].append(p)
151148
else:
152-
rel_link = os.path.join(dirname, link)
153-
154-
if link.endswith(".nolink"):
155-
if os.path.exists(rel_link.rstrip(".nolink")):
156-
print("nolinked {} href {} found.".format(p, link.rstrip(".nolink")), file=sys.stderr)
157-
found_error = True
158-
else:
159-
if not os.path.exists(rel_link):
160-
print("{} href {} not found.".format(p, link), file=sys.stderr)
161-
found_error = True
149+
outer_link_dict[link] = [p]
150+
151+
if args.check_inner_link:
152+
for link in inner_links:
153+
rel_link = ""
154+
if link.startswith("/"):
155+
rel_link = os.path.join(current_dir, link.lstrip("/"))
156+
else:
157+
rel_link = os.path.join(dirname, link)
158+
159+
if link.endswith(".nolink"):
160+
if os.path.exists(rel_link.rstrip(".nolink")):
161+
print("nolinked {} href {} found.".format(p, link.rstrip(".nolink")), file=sys.stderr)
162+
found_error = True
163+
else:
164+
if not os.path.exists(rel_link):
165+
print("{} href {} not found.".format(p, link), file=sys.stderr)
166+
found_error = True
162167

163168
if args.check_outer_link:
169+
if len(args.url) > 0:
170+
outer_link_dict[args.url] = ""
171+
164172
for link, from_list in outer_link_dict.items():
165173
exists, reason = check_url(link)
166174
if not exists:

0 commit comments

Comments
 (0)