Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 2 additions & 33 deletions .github/workflows/reusable-link-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,40 +20,9 @@ jobs:
if: github.event_name == 'pull_request'
env:
GITHUB_TOKEN: ${{ github.token }}
run: mise run lint-local-links

- name: Get modified files
if: github.event_name == 'pull_request'
id: modified-files
run: |
merge_base=$(git merge-base origin/${{ github.base_ref }} HEAD)
# Using lychee's default extension filter here to match when it runs against all files
# Note: --diff-filter=d filters out deleted files
modified_files=$(git diff --name-only --diff-filter=d $merge_base...${{ github.event.pull_request.head.sha }} \
| grep -E '\.(md|mkd|mdx|mdown|mdwn|mkdn|mkdown|markdown|html|htm|txt)$' \
| tr '\n' ' ' || true)
echo "files=$modified_files" >> $GITHUB_OUTPUT
echo "Modified files: $modified_files"

- name: Check if lychee config was modified
if: github.event_name == 'pull_request'
id: config-check
run: |
merge_base=$(git merge-base origin/${{ github.base_ref }} HEAD)
config_modified=$(git diff --name-only $merge_base...${{ github.event.pull_request.head.sha }} \
| grep -E '^(\.github/config/lychee\.toml|mise\.toml)$' || true)
if [ -n "$config_modified" ]; then
echo "modified=true" >> $GITHUB_OUTPUT
fi
run: mise run lint:local-links

- name: Link check (modified files only)
if: github.event_name == 'pull_request' && steps.modified-files.outputs.files != '' && steps.config-check.outputs.modified != 'true'
env:
GITHUB_TOKEN: ${{ github.token }}
run: mise run lint-links ${{ steps.modified-files.outputs.files }}

- name: Link check (all files)
if: github.event_name != 'pull_request' || steps.config-check.outputs.modified == 'true'
env:
GITHUB_TOKEN: ${{ github.token }}
run: mise run lint-links
run: mise run lint:links-in-modified-files --base origin/${{ github.base_ref }} --head ${{ github.event.pull_request.head.sha }} --event ${{ github.event_name }}
3 changes: 3 additions & 0 deletions .mise/tasks/lint/.shellcheckrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# shellcheck configuration for mise tasks
# SC2154: usage_* variables are set by mise framework
disable=SC2154
39 changes: 39 additions & 0 deletions .mise/tasks/lint/links-in-modified-files.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env bash
#MISE description="Lint links in modified files"

set -e

#USAGE flag "--base <base>" help="base branch to compare against" default="origin/main"
#USAGE flag "--head <head>" help="head branch to compare against" default=""
#USAGE flag "--event <event>" help="PR name" default="pull_request"

if [ "$usage_head" == "''" ]; then
usage_head=""
fi

# Check if lychee config was modified
config_modified=$(git diff --name-only --merge-base "$usage_base" "$usage_head" \
| grep -E '^(\.github/config/lychee\.toml|.mise/tasks/lint|mise\.toml)$' || true)

if [ -n "$config_modified" ] ; then
echo "config changes, checking all files."
mise run lint:links
elif [ "$usage_event" != "pull_request" ] ; then
echo "Not a PR - skipping link linting."
exit 0
else
# Using lychee's default extension filter here to match when it runs against all files
# Note: --diff-filter=d filters out deleted files
modified_files=$(git diff --name-only --diff-filter=d "$usage_base" "$usage_head" \
| grep -E '\.(md|mkd|mdx|mdown|mdwn|mkdn|mkdown|markdown|html|htm|txt)$' \
| tr '\n' ' ' || true)

if [ -z "$modified_files" ]; then
echo "No modified files, skipping link linting."
exit 0
fi

# shellcheck disable=SC2086
mise run lint:links $modified_files
fi

8 changes: 8 additions & 0 deletions .mise/tasks/lint/links.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
#MISE description="Lint links in all files"

set -e

#USAGE arg "<file>" var=#true help="files to check" default="."

lychee --verbose --config .github/config/lychee.toml "$usage_file"
8 changes: 8 additions & 0 deletions .mise/tasks/lint/local-links.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
#MISE description="Lint links in all files"

set -e

#USAGE arg "<file>" var=#true help="files to check" default="."

lychee --verbose --scheme file --include-fragments "$usage_file"
12 changes: 6 additions & 6 deletions mise.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[tools]
lychee = "0.20.1"

[tasks.lint-local-links]
run = 'lychee --verbose --scheme file --include-fragments {{arg(name="files", default=".")}}'

[tasks.lint-links]
run = 'lychee --verbose --config .github/config/lychee.toml {{arg(name="files", var=true, default=".")}}'

[settings]
# Only install tools explicitly defined in the [tools] section above
idiomatic_version_file_enable_tools = []

# Windows configuration for file-based tasks
# Based on: https://github.com/jdx/mise/discussions/4461
windows_executable_extensions = ["sh"]
windows_default_file_shell_args = "bash"
use_file_shell_for_executable_tasks = true