Skip to content

Commit 70b7dc1

Browse files
zeitlingertrask
andauthored
Use mise to check for modified files (#2318)
Co-authored-by: Trask Stalnaker <[email protected]>
1 parent b18407b commit 70b7dc1

File tree

6 files changed

+66
-39
lines changed

6 files changed

+66
-39
lines changed

.github/workflows/reusable-link-check.yml

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -20,40 +20,9 @@ jobs:
2020
if: github.event_name == 'pull_request'
2121
env:
2222
GITHUB_TOKEN: ${{ github.token }}
23-
run: mise run lint-local-links
24-
25-
- name: Get modified files
26-
if: github.event_name == 'pull_request'
27-
id: modified-files
28-
run: |
29-
merge_base=$(git merge-base origin/${{ github.base_ref }} HEAD)
30-
# Using lychee's default extension filter here to match when it runs against all files
31-
# Note: --diff-filter=d filters out deleted files
32-
modified_files=$(git diff --name-only --diff-filter=d $merge_base...${{ github.event.pull_request.head.sha }} \
33-
| grep -E '\.(md|mkd|mdx|mdown|mdwn|mkdn|mkdown|markdown|html|htm|txt)$' \
34-
| tr '\n' ' ' || true)
35-
echo "files=$modified_files" >> $GITHUB_OUTPUT
36-
echo "Modified files: $modified_files"
37-
38-
- name: Check if lychee config was modified
39-
if: github.event_name == 'pull_request'
40-
id: config-check
41-
run: |
42-
merge_base=$(git merge-base origin/${{ github.base_ref }} HEAD)
43-
config_modified=$(git diff --name-only $merge_base...${{ github.event.pull_request.head.sha }} \
44-
| grep -E '^(\.github/config/lychee\.toml|mise\.toml)$' || true)
45-
if [ -n "$config_modified" ]; then
46-
echo "modified=true" >> $GITHUB_OUTPUT
47-
fi
23+
run: mise run lint:local-links
4824

4925
- name: Link check (modified files only)
50-
if: github.event_name == 'pull_request' && steps.modified-files.outputs.files != '' && steps.config-check.outputs.modified != 'true'
51-
env:
52-
GITHUB_TOKEN: ${{ github.token }}
53-
run: mise run lint-links ${{ steps.modified-files.outputs.files }}
54-
55-
- name: Link check (all files)
56-
if: github.event_name != 'pull_request' || steps.config-check.outputs.modified == 'true'
5726
env:
5827
GITHUB_TOKEN: ${{ github.token }}
59-
run: mise run lint-links
28+
run: mise run lint:links-in-modified-files --base origin/${{ github.base_ref }} --head ${{ github.event.pull_request.head.sha }} --event ${{ github.event_name }}

.mise/tasks/lint/.shellcheckrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# shellcheck configuration for mise tasks
2+
# SC2154: usage_* variables are set by mise framework
3+
disable=SC2154
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env bash
2+
#MISE description="Lint links in modified files"
3+
4+
set -e
5+
6+
#USAGE flag "--base <base>" help="base branch to compare against" default="origin/main"
7+
#USAGE flag "--head <head>" help="head branch to compare against" default=""
8+
#USAGE flag "--event <event>" help="PR name" default="pull_request"
9+
10+
if [ "$usage_head" == "''" ]; then
11+
usage_head=""
12+
fi
13+
14+
# Check if lychee config was modified
15+
config_modified=$(git diff --name-only --merge-base "$usage_base" "$usage_head" \
16+
| grep -E '^(\.github/config/lychee\.toml|.mise/tasks/lint|mise\.toml)$' || true)
17+
18+
if [ -n "$config_modified" ] ; then
19+
echo "config changes, checking all files."
20+
mise run lint:links
21+
elif [ "$usage_event" != "pull_request" ] ; then
22+
echo "Not a PR - skipping link linting."
23+
exit 0
24+
else
25+
# Using lychee's default extension filter here to match when it runs against all files
26+
# Note: --diff-filter=d filters out deleted files
27+
modified_files=$(git diff --name-only --diff-filter=d "$usage_base" "$usage_head" \
28+
| grep -E '\.(md|mkd|mdx|mdown|mdwn|mkdn|mkdown|markdown|html|htm|txt)$' \
29+
| tr '\n' ' ' || true)
30+
31+
if [ -z "$modified_files" ]; then
32+
echo "No modified files, skipping link linting."
33+
exit 0
34+
fi
35+
36+
# shellcheck disable=SC2086
37+
mise run lint:links $modified_files
38+
fi
39+

.mise/tasks/lint/links.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
#MISE description="Lint links in all files"
3+
4+
set -e
5+
6+
#USAGE arg "<file>" var=#true help="files to check" default="."
7+
8+
lychee --verbose --config .github/config/lychee.toml "$usage_file"

.mise/tasks/lint/local-links.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
#MISE description="Lint links in all files"
3+
4+
set -e
5+
6+
#USAGE arg "<file>" var=#true help="files to check" default="."
7+
8+
lychee --verbose --scheme file --include-fragments "$usage_file"

mise.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
[tools]
22
lychee = "0.20.1"
33

4-
[tasks.lint-local-links]
5-
run = 'lychee --verbose --scheme file --include-fragments {{arg(name="files", default=".")}}'
6-
7-
[tasks.lint-links]
8-
run = 'lychee --verbose --config .github/config/lychee.toml {{arg(name="files", var=true, default=".")}}'
9-
104
[settings]
115
# Only install tools explicitly defined in the [tools] section above
126
idiomatic_version_file_enable_tools = []
7+
8+
# Windows configuration for file-based tasks
9+
# Based on: https://github.com/jdx/mise/discussions/4461
10+
windows_executable_extensions = ["sh"]
11+
windows_default_file_shell_args = "bash"
12+
use_file_shell_for_executable_tasks = true

0 commit comments

Comments
 (0)