-
Notifications
You must be signed in to change notification settings - Fork 7
69 lines (62 loc) · 1.85 KB
/
check-broken-link.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
name: check_broken_links
on:
schedule:
- cron: 30 17 * * *
push:
paths:
- '**/*.ipynb'
pull_request:
paths:
- '**/*.ipynb'
# Trigger the workflow on manual dispatch
workflow_dispatch:
permissions:
contents: read
pages: write
id-token: write
defaults:
run:
shell: bash
jobs:
get-notebooks:
runs-on: ubuntu-22.04
outputs:
notebook_list: ${{ steps.list_all_notebooks.outputs.notebook_list }}
steps:
- uses: actions/checkout@v4
- name: Get all notebooks
working-directory: ./books
id: list_all_notebooks
run: |
all_notebooks=($(find . -type f -name "*.ipynb"))
notebook_list='['
for NOTEBOOK in "${all_notebooks[@]}"; do
echo "NOTEBOOK=${NOTEBOOK}"
notebook_list+="\"${NOTEBOOK}\","
done
notebook_list=$(sed '$s/,$//' <<< $notebook_list)
notebook_list+=']'
echo "notebook_list=${notebook_list}"
echo "notebook_list=${notebook_list}" >> $GITHUB_OUTPUT
check-links:
needs: [ get-notebooks ]
if: ${{ needs.get-notebooks.outputs.notebook_list != '[]' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.9'
- name: Install Python dependencies
run: |
python -m pip install pytest-check-links
- name: Check broken links
working-directory: ./books
run: |
notebook_list='${{ needs.get-notebooks.outputs.notebook_list }}'
echo "notebook_list=${notebook_list}"
for notebook in $(echo $notebook_list | jq -r '.[]'); do
echo "Checking links in $notebook"
pytest --check-links --check-links-ignore "https://doi.org/.*/" "https://www.sciencedirect.com/.*" $notebook
done