Skip to content

Commit 1ff607b

Browse files
authored
Added URL checker (#11)
* Added URL checker
1 parent ec4341e commit 1ff607b

File tree

4 files changed

+86
-1
lines changed

4 files changed

+86
-1
lines changed

.github/workflows/check-urls.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: CI
2+
3+
# Controls when the action will run. Triggers the workflow on push or pull request
4+
# events but only for the master branch
5+
on:
6+
push:
7+
branches: [ master ]
8+
pull_request:
9+
branches: [ master ]
10+
11+
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
12+
jobs:
13+
# This workflow contains a single job called "build"
14+
build:
15+
# The type of runner that the job will run on
16+
runs-on: ubuntu-latest
17+
18+
# Steps represent a sequence of tasks that will be executed as part of the job
19+
steps:
20+
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
21+
- uses: actions/checkout@v2
22+
23+
# Check all urls in Markdown files
24+
- name: Check all URLs
25+
run: ./scripts/check_all_urls.sh

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ Postnet, Planet, USPS OneCode, Australia Post, Deutsche Post Identcode, Deutsche
6565

6666
## Prerequisites
6767

68-
To use Aspose Barcode Cloud for Android you need to register an account with [Aspose Cloud](https://www.aspose.cloud/) and lookup/create Client Secret and SID at [Cloud Dashboard](https://dashboard.aspose.cloud/applications). There is free quota available. For more details, see [Aspose Cloud Pricing](https://purchase.aspose.cloud/pricing).
68+
To use Aspose Barcode Cloud for Android you need to register an account with [Aspose Cloud](https://www.aspose.cloud) and lookup/create Client Secret and SID at [Cloud Dashboard](https://dashboard.aspose.cloud/applications). There is free quota available. For more details, see [Aspose Cloud Pricing](https://purchase.aspose.cloud/pricing).
6969

7070
## Getting Started
7171

scripts/check-urls-in-file.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import re
2+
import subprocess
3+
import os
4+
import sys
5+
import fileinput
6+
import collections
7+
8+
URL_REGEX = re.compile(r"""(http[s]*://[^{})"'<>#\s]+)[)"'<>#\s]""")
9+
10+
GOOD_URLS = set('https://www.aspose.cloud',)
11+
BROKEN_URLS = collections.defaultdict(list)
12+
13+
14+
def check_url(url):
15+
with open(os.devnull, 'w') as devnull:
16+
ret_code = subprocess.call(['curl', '-sSf', '--user-agent', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Firefox/91.0', url], stdout=devnull)
17+
return ret_code == 0
18+
19+
20+
def check_file(filename):
21+
with open(filename, 'r') as f:
22+
urls = frozenset(URL_REGEX.findall(f.read()))
23+
24+
for url in sorted(urls):
25+
if url in GOOD_URLS:
26+
continue
27+
elif url in BROKEN_URLS:
28+
continue
29+
30+
if check_url(url):
31+
print("OK: '%s'" % url)
32+
GOOD_URLS.add(url)
33+
else:
34+
print("BROKEN: '%s' in file %s" % (url, filename))
35+
BROKEN_URLS[url].append(filename)
36+
37+
38+
def main():
39+
for filename in fileinput.input():
40+
check_file(filename.strip())
41+
42+
for url, files in BROKEN_URLS.items():
43+
print("BROKEN URL: '%s' in files: %s" % (url, ', '.join(files)), file=sys.stderr)
44+
if BROKEN_URLS:
45+
exit(1)
46+
47+
48+
if __name__ == '__main__':
49+
main()

scripts/check_all_urls.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
6+
7+
check_file () {
8+
echo "$1"
9+
}
10+
11+
git ls-files --exclude-standard --full-name | grep -i '\.md$\|\.kt$' | python "${SCRIPT_DIR}/check-urls-in-file.py"

0 commit comments

Comments
 (0)