diff --git a/.github/workflows/reusable-link-check.yml b/.github/workflows/reusable-link-check.yml index e891e6d06..87711b6ce 100644 --- a/.github/workflows/reusable-link-check.yml +++ b/.github/workflows/reusable-link-check.yml @@ -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 }} diff --git a/.mise/tasks/lint/.shellcheckrc b/.mise/tasks/lint/.shellcheckrc new file mode 100644 index 000000000..c186fb835 --- /dev/null +++ b/.mise/tasks/lint/.shellcheckrc @@ -0,0 +1,3 @@ +# shellcheck configuration for mise tasks +# SC2154: usage_* variables are set by mise framework +disable=SC2154 diff --git a/.mise/tasks/lint/links-in-modified-files.sh b/.mise/tasks/lint/links-in-modified-files.sh new file mode 100755 index 000000000..893723a44 --- /dev/null +++ b/.mise/tasks/lint/links-in-modified-files.sh @@ -0,0 +1,39 @@ +#!/usr/bin/env bash +#MISE description="Lint links in modified files" + +set -e + +#USAGE flag "--base " help="base branch to compare against" default="origin/main" +#USAGE flag "--head " help="head branch to compare against" default="" +#USAGE flag "--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 + diff --git a/.mise/tasks/lint/links.sh b/.mise/tasks/lint/links.sh new file mode 100755 index 000000000..479549f74 --- /dev/null +++ b/.mise/tasks/lint/links.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +#MISE description="Lint links in all files" + +set -e + +#USAGE arg "" var=#true help="files to check" default="." + +lychee --verbose --config .github/config/lychee.toml "$usage_file" diff --git a/.mise/tasks/lint/local-links.sh b/.mise/tasks/lint/local-links.sh new file mode 100755 index 000000000..e79694d95 --- /dev/null +++ b/.mise/tasks/lint/local-links.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +#MISE description="Lint links in all files" + +set -e + +#USAGE arg "" var=#true help="files to check" default="." + +lychee --verbose --scheme file --include-fragments "$usage_file" diff --git a/mise.toml b/mise.toml index bc7b9444a..0e27c5494 100644 --- a/mise.toml +++ b/mise.toml @@ -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