@@ -20,22 +20,49 @@ jobs:
2020 steps :
2121 - name : Checkout Code
2222 uses : actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
23+ with :
24+ fetch-depth : 2
25+
26+ - name : Get changed files
27+ id : changed-files
28+ uses : tj-actions/changed-files@e0021407031f5be11a464abee9a0776171c79891 # v47.0.1
29+ with :
30+ files : |
31+ **/*.md
2332
2433 # Extract shell commands from markdown code blocks for validation
25- # This creates a README .sh file containing all bash/shell/sh code blocks
34+ # This creates a shell_commands_from_md .sh file containing all bash/shell/sh code blocks
2635 # from markdown files to ensure they are syntactically correct
2736 - name : Extract commands from markdown files
37+ if : steps.changed-files.outputs.any_changed == 'true'
38+ env :
39+ ALL_CHANGED_FILES : ${{ steps.changed-files.outputs.all_changed_and_modified_files }}
2840 run : |
2941 set -euxo pipefail
3042 eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
31- brew install mdq
32- echo '#!/usr/bin/env bash' > README.sh
33- readarray -d '' MD_FILES < <(find . -type f -name "*.md" -print0)
34- mdq '```/^bash$|^shell$|^sh$/' --br -o plain "${MD_FILES[@]}" >> README.sh || true
35- chmod a+x README.sh
43+ brew install mq
44+ echo '#!/usr/bin/env bash' > shell_commands_from_md.sh
45+ read -ra FILES <<< "${ALL_CHANGED_FILES}"
46+ mq 'select(.code.lang == "bash" || .code.lang == "shell" || .code.lang == "sh") | to_text()' "${FILES[@]}" >> shell_commands_from_md.sh
47+ chmod a+x shell_commands_from_md.sh
48+
49+ - name : Restore lychee cache
50+ id : restore-cache
51+ uses : actions/cache/restore@9255dc7a253b0ccc959486e2bca901246202afeb # v5.0.1
52+ with :
53+ path : .lycheecache
54+ key : cache-lychee-${{ github.sha }}
55+ restore-keys : cache-lychee-
3656
3757 - name : 💡 MegaLinter
3858 uses : oxsecurity/megalinter@55a59b24a441e0e1943080d4a512d827710d4a9d # v9.2.0
3959 env :
4060 GITHUB_COMMENT_REPORTER : false
4161 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
62+
63+ - name : Save lychee cache
64+ uses : actions/cache/save@9255dc7a253b0ccc959486e2bca901246202afeb # v5.0.1
65+ if : always() && steps.restore-cache.outputs.cache-primary-key
66+ with :
67+ path : .lycheecache
68+ key : ${{ steps.restore-cache.outputs.cache-primary-key }}
0 commit comments