Skip to content

Commit

Permalink
whole process
Browse files Browse the repository at this point in the history
  • Loading branch information
markcmiller86 committed Jul 1, 2024
1 parent f53a1e0 commit f024ad6
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 15 deletions.
40 changes: 36 additions & 4 deletions .github/workflows/check-urls.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,24 @@ jobs:
tmp=$(echo "${{ env.ignore_file_patterns }}" | tr '\n' ' ')
echo "ignore_file_patterns=$tmp" >> $GITHUB_OUTPUT
- name: Checkout Repository
- name: Checkout Repo for PR branch
if: ${{ github.event_name == 'pull_request' }}
uses: actions/checkout@v4

- name: Checkout Repo for link check
if: ${{ github.event_name != 'pull_request' }}
uses: actions/checkout@v4
with:
ref: 'sched-link-checks'

- name: Sync main to link check branch
if: ${{ github.event_name != 'pull_request' }}
run: |
git config user.name 'github-actions'
git config user.email '[email protected]'
git fetch origin main
git merge origin/main --no-edit -X thiers
git push origin sched-link-checks
- name: Get Changed Files (for PRs)
if: ${{ github.event_name == 'pull_request' }}
Expand All @@ -62,7 +78,6 @@ jobs:
echo "ignore_file_patterns=${{ steps.setup_vars.outputs.ignore_file_patterns }}" >> $GITHUB_OUTPUT
fi
#exclude_patterns: ${{ steps.setup_vars.outputs.ignore_url_patterns }}
- name: Check URLs in selected files
run: |
for f in ${{ steps.file_list.outputs.files }}; do
Expand All @@ -78,11 +93,27 @@ jobs:
cat linkchecker.out >> linkchecker-all.out
done
- name: Process log
run: |
python utils/LinkChecker/cklcresults.py ${{ github.event_name }}
- name: Finalize Check Status
if: ${{ github.event_name == 'pull_request' }}
run: |
[ $(wc -c utils/LinkChecker/bad_links.txt) -gt 0 ] && exit 1
- name: Upload artifact
if: always()
uses: actions/upload-artifact@v4
with:
name: my-artifact
path: linkchecker-all.out
name: bad-links
path: utils/LinkChecker/bad_links.txt

- name: Update link logs
if: ${{ github.event_name != 'pull_request' }}
run: |
git commit -m 'Update link logs'
git push origin sched-link-checks
#
# Keep the recurring failures and definitely bad lists in repo on
Expand All @@ -102,6 +133,7 @@ jobs:
# Report success if definitely bad list is empty, otherwise failure
# generate email with links or actual data
#
# you have to use file:// on command-line to checker

# bare URLs in markdown are not actually links and will not be checked. Many
# markdown renderers and browsers will recognize these and handle them as links
Expand Down
35 changes: 24 additions & 11 deletions utils/LinkChecker/cklcresults.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ast, datetime
import ast, datetime, sys

def AddEntryToRecord(cr, key, line):
assert key not in cr.keys(), f"duplicate key {key}, {line}, {cr}"
Expand All @@ -18,15 +18,22 @@ def AddRecord(records, cr, key, line, now):
def AppendLineToPreviousKey(cr, key, line):
cr[key] += line

#
# Handle command-line args to this script
ghEvent = ""
if len(sys.argv) > 1:
ghEvent = sys.argv[1]

#
# Open log and read all lines into a python list object
f = open('linkchecker-all.out','r')
lines = f.readlines()
f.close()

#
# Process contents of log, looking for groups of lines defining
# each link tested and its results. Each link is its own dict
# object (record) and we append each record to a list, records.
# Process contents of linkchecker log, looking for groups of lines
# defining each link tested and its results. Each link is its own dict
# object (record) and we append each record to a list named records.
#
records = []
currentRecord = {}
Expand Down Expand Up @@ -59,18 +66,20 @@ def AppendLineToPreviousKey(cr, key, line):
# Open trouble_links.txt and read all contents
#
trouble_links = []
with open('../../utils/LinkChecker/trouble_links.txt','r') as file:
for line in file:
trouble_links.append(ast.literal_eval(line.strip()))
if ghEvent != "pull_request":
with open('../../utils/LinkChecker/trouble_links.txt','r') as file:
for line in file:
trouble_links.append(ast.literal_eval(line.strip()))
trouble_links_original_size = len(trouble_links)

#
# Open bad_links.log
#
bad_links = []
with open('../../utils/LinkChecker/bad_links.txt','r') as file:
for line in file:
bad_links.append(ast.literal_eval(line.strip()))
if ghEvent != "pull_request":
with open('../../utils/LinkChecker/bad_links.txt','r') as file:
for line in file:
bad_links.append(ast.literal_eval(line.strip()))
bad_links_original_size = len(bad_links)

#
Expand All @@ -91,6 +100,10 @@ def AppendLineToPreviousKey(cr, key, line):
else:
linkOK = False

if ghEvent == "pull_request" and not linkOK:
bad_links += [r]
continue

prev_trouble_records = [x for x in trouble_links if x['URL'] == r['URL']]

if linkOK:
Expand Down Expand Up @@ -118,7 +131,7 @@ def AppendLineToPreviousKey(cr, key, line):
#
# Update trouble_links file if modified
#
if len(trouble_links) != trouble_links_original_size:
if ghEvent != "pull_request" and len(trouble_links) != trouble_links_original_size:
with open('../../utils/LinkChecker/trouble_links.txt','w') as file:
for rec in trouble_links:
file.write(str(rec)+'\n')
Expand Down

0 comments on commit f024ad6

Please sign in to comment.