Skip to content

Commit bd48328

Browse files
Add GHA workflow to diff slides with batch script
1 parent 5ca1c2a commit bd48328

2 files changed

Lines changed: 100 additions & 0 deletions

File tree

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: Compare SCT Commands
2+
3+
on:
4+
pull_request:
5+
workflow_dispatch:
6+
inputs:
7+
text_url:
8+
description: "URL to text file (e.g. GitHub raw gist link)"
9+
required: true
10+
type: string
11+
12+
jobs:
13+
compare:
14+
runs-on: macos-latest
15+
env:
16+
YDIFF_OPTIONS: "--unified --pager=cat --color=always --width=120 --nowrap"
17+
18+
steps:
19+
- name: Check out repo
20+
uses: actions/checkout@v4
21+
22+
- name: Install Python (for parsing script)
23+
uses: actions/setup-python@v5
24+
with:
25+
python-version: "3.11"
26+
27+
- name: Install `ydiff` # https://github.com/ymattw/ydiff
28+
run: brew install ydiff
29+
30+
- name: Download remote text file
31+
run: |
32+
curl -L https://gist.githubusercontent.com/joshuacwnewton/3c554bf27111cf0020e5c124b66448c4/raw/ff08cbcf7738941008eca0fa54e024d98eea24e8/gistfile1.txt -o remote.txt
33+
echo "✅ Downloaded remote file:"
34+
wc -l remote.txt
35+
36+
- name: Extract commands from remote file
37+
run: |
38+
python3 .github/workflows/scripts/extract_sct.py remote.txt -o remote_cmds.txt
39+
sort -u remote_cmds.txt > remote_cmds_sorted.txt
40+
echo "✅ Extracted $(wc -l < remote_cmds_sorted.txt) commands from remote file"
41+
42+
- name: Extract commands from local batch script
43+
run: |
44+
python3 .github/workflows/scripts/extract_sct.py single_subject/batch_single_subject.sh -o local_cmds.txt
45+
sort -u local_cmds.txt > local_cmds_sorted.txt
46+
echo "✅ Extracted $(wc -l < local_cmds_sorted.txt) commands from local script"
47+
48+
- name: Diff commands
49+
run: |
50+
echo "🔍 Diffing remote vs local..."
51+
diff -u local_cmds_sorted.txt remote_cmds_sorted.txt > diff.txt || true
52+
ydiff < diff.txt
53+
54+
- name: Upload results as artifacts
55+
uses: actions/upload-artifact@v4
56+
with:
57+
name: command-diff-output
58+
path: |
59+
remote_cmds_sorted.txt
60+
local_cmds_sorted.txt
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import argparse
2+
from pathlib import Path
3+
4+
5+
def extract_sct_commands(paths, output=None):
6+
results = []
7+
8+
for path in paths:
9+
with open(path, "r", encoding="utf-8") as f:
10+
for line in f:
11+
stripped = line.lstrip()
12+
if stripped.startswith("# sct_"):
13+
stripped = stripped[2:]
14+
# Find relavent SCT commands to compare
15+
if (stripped.startswith("sct_")
16+
# sct commands must have command + arg + value (3)
17+
# this excludes slide subtitles like "sct_slide ..."
18+
and len(stripped.split(" ")) >= 3
19+
# exclude lines with <> which are likely placeholders
20+
and not ("<" in stripped and ">" in stripped)
21+
# exclude sct_download_data (data already present)
22+
and not stripped.startswith("sct_download_data")
23+
# exclude sct_run_batch (handled in .yml workflow)
24+
and not stripped.startswith("sct_run_batch")):
25+
results.append(stripped.rstrip())
26+
27+
if output:
28+
Path(output).write_text("\n".join(results), encoding="utf-8")
29+
else:
30+
print("\n".join(results))
31+
32+
33+
if __name__ == "__main__":
34+
parser = argparse.ArgumentParser(description="Extract SCT commands "
35+
"from TXT files.")
36+
parser.add_argument("files", nargs="+", help="Input text files")
37+
parser.add_argument("-o", "--output", help="Optional output file")
38+
args = parser.parse_args()
39+
40+
extract_sct_commands(args.files, args.output)

0 commit comments

Comments
 (0)