Skip to content

Commit 277d3aa

Browse files
authored
URL checker added (#26)
* URL checker added
1 parent 8fe8cc3 commit 277d3aa

File tree

4 files changed

+98
-4
lines changed

4 files changed

+98
-4
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: "Check URLs"
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: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
:---: | :---: | :---:
1414
[![Generate](https://products.aspose.app/barcode/generate/img/aspose_generate-app-48.png)](https://products.aspose.app/barcode/generate) | [![Recognize](https://products.aspose.app/barcode/recognize/img/aspose_recognize-app-48.png)](https://products.aspose.app/barcode/recognize) | [![Embed](https://products.aspose.app/barcode/embed/img/aspose_embed-app-48.png)](https://products.aspose.app/barcode/embed)
1515

16-
[Aspose.BarCode for Cloud](https://products.aspose.cloud/barcode/cloud) is a REST API for Linear, 2D and postal barcode generation and recognition in the cloud. API recognizes and generates barcode images in a variety of formats. Barcode REST API allows to specify barcode image attributes like image width, height, border style and output image format in order to customize the generation process. Developers can also specify the barcode type and text attributes such as text location and font styles in order to suit the application requirements.
16+
[Aspose.BarCode for Cloud](https://products.aspose.cloud/barcode/) is a REST API for Linear, 2D and postal barcode generation and recognition in the cloud. API recognizes and generates barcode images in a variety of formats. Barcode REST API allows to specify barcode image attributes like image width, height, border style and output image format in order to customize the generation process. Developers can also specify the barcode type and text attributes such as text location and font styles in order to suit the application requirements.
1717

1818
This repository contains Aspose.BarCode Cloud SDK for .NET source code. This SDK allows you to work with Aspose.BarCode for Cloud REST APIs in your .NET Core or .NET Standard applications quickly and easily.
1919

@@ -30,7 +30,7 @@ The complete source code is available in this repository folder. You can either
3030

3131
## Prerequisites
3232

33-
To use Aspose.BarCode Cloud SDK for .NET you need to register an account with [Aspose Cloud](https://www.aspose.cloud/) and lookup/create Client Secret and Client Id 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).
33+
To use Aspose.BarCode Cloud SDK for .NET you need to register an account with [Aspose Cloud](https://www.aspose.cloud) and lookup/create Client Secret and Client Id 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).
3434

3535
## Installation
3636

@@ -84,11 +84,11 @@ All Aspose.BarCode for Cloud SDKs, helper scripts and templates are licensed und
8484
## Resources
8585

8686
- [**Website**](https://www.aspose.cloud)
87-
- [**Product Home**](https://products.aspose.cloud/barcode/cloud)
87+
- [**Product Home**](https://products.aspose.cloud/barcode/)
8888
- [**Documentation**](https://docs.aspose.cloud/barcode/)
8989
- [**Free Support Forum**](https://forum.aspose.cloud/c/barcode)
9090
- [**Paid Support Helpdesk**](https://helpdesk.aspose.cloud/)
91-
- [**Blog**](https://blog.aspose.cloud/category/aspose-products/aspose-barcode-product-family/)
91+
- [**Blog**](https://blog.aspose.cloud/category/barcode/)
9292

9393
## Documentation for API Endpoints
9494

scripts/check-urls-in-file.py

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

0 commit comments

Comments
 (0)