|
1 | 1 | name: Proof Links |
| 2 | +on: [pull_request, workflow_dispatch] |
2 | 3 |
|
3 | | -on: |
4 | | - push: |
5 | | - branches: |
6 | | - - master |
7 | | - pull_request: |
8 | | - branches: |
9 | | - - master |
| 4 | +env: |
| 5 | + HUGO_VERSION: 0.147.8 |
| 6 | + GH_USER: site-commons-machine-user |
| 7 | + LYCHEE_RELEASE: "lychee-v0.15.1-x86_64-unknown-linux-gnu.tar.gz" |
| 8 | + LYCHEE_VERSION_TAG: "v0.15.1" |
10 | 9 |
|
11 | 10 | jobs: |
12 | 11 | proof-links: |
13 | 12 | runs-on: ubuntu-latest |
| 13 | + concurrency: |
| 14 | + group: ${{ github.workflow }}-${{ github.ref }} |
14 | 15 | steps: |
15 | | - - uses: actions/checkout@v3 |
| 16 | + - name: Checkout |
| 17 | + uses: actions/checkout@v4 |
| 18 | + |
| 19 | + - name: Setup Hugo |
| 20 | + uses: peaceiris/actions-hugo@v3 |
| 21 | + with: |
| 22 | + hugo-version: ${{ env.HUGO_VERSION }} |
| 23 | + extended: true |
| 24 | + |
| 25 | + - name: Setup Node |
| 26 | + uses: actions/setup-node@v3 |
| 27 | + with: |
| 28 | + node-version: '20' |
| 29 | + |
| 30 | + - name: Cache dependencies |
| 31 | + uses: actions/cache@v4 |
| 32 | + with: |
| 33 | + path: ~/.npm |
| 34 | + key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} |
| 35 | + restore-keys: | |
| 36 | + ${{ runner.os }}-node- |
| 37 | +
|
| 38 | + - name: Cache Hugo Modules |
| 39 | + uses: actions/cache@v4 |
| 40 | + with: |
| 41 | + path: /tmp/hugo_cache |
| 42 | + key: ${{ runner.os }}-hugomod-${{ hashFiles('**/go.sum') }} |
| 43 | + restore-keys: | |
| 44 | + ${{ runner.os }}-hugomod- |
| 45 | +
|
| 46 | + - name: Prepare environment |
| 47 | + run: git config --global url."https://${{ env.GH_USER }}:${{ secrets.GH_SITE_COMMONS_PAT }}@github.com".insteadOf "https://github.com" |
| 48 | + |
| 49 | + - name: Install Dependencies |
| 50 | + working-directory: site |
| 51 | + run: npm ci |
| 52 | + |
| 53 | + - name: Build Spine |
| 54 | + working-directory: site |
| 55 | + run: hugo -e development |
| 56 | + |
| 57 | + # Cache Lychee results to avoid hitting rate limits. |
| 58 | + - name: Cache Lychee results |
| 59 | + uses: actions/cache@v4 |
16 | 60 | with: |
17 | | - submodules: 'recursive' |
| 61 | + path: .lycheecache |
| 62 | + key: cache-lychee-results |
18 | 63 |
|
19 | | - - name: Set up Ruby and Bundler |
20 | | - uses: ruby/setup-ruby@v1 |
| 64 | + - name: Cache Lychee executable |
| 65 | + id: cache-lychee |
| 66 | + uses: actions/cache@v4 |
21 | 67 | with: |
22 | | - ruby-version: '2.7.4' |
23 | | - |
24 | | - # Bundler version is restricted to `2.4.22`, |
25 | | - # as we want to use Ruby `2.7.4` to match GH Pages environment. |
26 | | - # |
27 | | - # Any newer versions of Bundler require Ruby 3.x, |
28 | | - # which are much newer than what's GH Pages has at the moment. |
29 | | - # |
30 | | - - name: Run Jekyll build |
| 68 | + path: lychee |
| 69 | + key: ${{ runner.os }}-${{ env.LYCHEE_RELEASE }} |
| 70 | + |
| 71 | + # We use Lychee directly instead of a GitHub Action because it |
| 72 | + # must have access the local Hugo server, which is not visible |
| 73 | + # from the Docker-based action. |
| 74 | + - name: Download Lychee executable |
| 75 | + uses: robinraju/release-downloader@v1.7 |
| 76 | + if: steps.cache-lychee.outputs.cache-hit != 'true' |
| 77 | + with: |
| 78 | + repository: "lycheeverse/lychee" |
| 79 | + tag: ${{ env.LYCHEE_VERSION_TAG }} |
| 80 | + fileName: ${{ env.LYCHEE_RELEASE }} |
| 81 | + |
| 82 | + - name: Extract Lychee executable |
| 83 | + if: steps.cache-lychee.outputs.cache-hit != 'true' |
31 | 84 | run: | |
32 | | - gem install bundler -v 2.4.22 |
33 | | - bundle install |
34 | | - bundle exec jekyll build |
| 85 | + mkdir -p lychee && |
| 86 | + tar -xf ${{ env.LYCHEE_RELEASE }} -C lychee |
35 | 87 |
|
36 | | - - name: Proof Links |
37 | | - run: ./_script/proof-links |
| 88 | + # 1. In the generated HTML, some inner links will have absolute URLs and |
| 89 | + # the link checker will attempt to fetch them. That's why we need |
| 90 | + # a server. Sadly, link checkers have no settings to address this. |
| 91 | + # 2. Output redirection is necessary for nohup in GitHub Actions. |
| 92 | + # 3. Sleep makes sure the server is up before the next step. |
| 93 | + - name: Start Hugo server |
| 94 | + working-directory: site |
| 95 | + run: | |
| 96 | + nohup hugo server \ |
| 97 | + --environment development \ |
| 98 | + > nohup.out 2> nohup.err < /dev/null & |
| 99 | + sleep 5 |
| 100 | +
|
| 101 | + - name: Check if the cache file exists |
| 102 | + run: | |
| 103 | + if [ -f ".lycheecache" ]; then |
| 104 | + echo "Lychee cache exists." |
| 105 | + else |
| 106 | + echo "No lychee cache file." |
| 107 | + fi |
| 108 | +
|
| 109 | + - name: Check links |
| 110 | + run: | |
| 111 | + ./lychee/lychee --config lychee.toml --timeout 60 \ |
| 112 | + --base http://localhost:1313/ \ |
| 113 | + 'site/public/**/*.html' |
0 commit comments