Skip to content

Commit a221d03

Browse files
committed
Autoformat README.md
1 parent e6a39c7 commit a221d03

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

.github/workflows/main.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,18 @@ jobs:
4141
- name: Run Unit Tests
4242
run: swift test
4343

44+
lint-markdown:
45+
name: Lint Markdown
46+
runs-on: macos-15
47+
steps:
48+
- uses: actions/checkout@v6
49+
- uses: ruby/setup-ruby@v1
50+
with:
51+
bundler-cache: true
52+
- uses: actions/setup-node@v4
53+
- name: Lint README.md
54+
run: bundle exec rake lint:markdown
55+
4456
site-build:
4557
name: Build Site
4658
runs-on: macos-15

Rakefile

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,52 @@ namespace :lint do
88
task :swift do
99
sh 'swift package --allow-writing-to-package-directory format --lint'
1010
end
11+
12+
desc 'Lints README.md'
13+
task :markdown do
14+
unless system('which npx > /dev/null 2>&1')
15+
puts "Error: npx is not installed. Please run: brew install node"
16+
exit 1
17+
end
18+
19+
readme_path = 'README.md'
20+
check_result = system('npx --yes prettier --check README.md')
21+
22+
unless check_result
23+
puts ""
24+
puts "README.md has unformatted changes."
25+
puts "Please run `bundle exec rake format:markdown` and commit the result."
26+
exit 1
27+
end
28+
end
1129
end
1230

1331
namespace :format do
1432
desc 'Formats swift files'
1533
task :swift do
1634
sh 'swift package --allow-writing-to-package-directory format'
1735
end
36+
37+
desc 'Formats README.md'
38+
task :markdown do
39+
unless system('which npx > /dev/null 2>&1')
40+
puts "Error: npx is not installed. Please run: brew install node"
41+
exit 1
42+
end
43+
44+
readme_path = 'README.md'
45+
46+
# Check if there would be changes by running prettier in check mode
47+
check_result = system('npx --yes prettier --check README.md > /dev/null 2>&1')
48+
49+
if check_result
50+
puts "No changes"
51+
else
52+
# Format the file
53+
sh 'npx --yes prettier --write README.md'
54+
puts "Formatted README.md"
55+
end
56+
end
1857
end
1958

2059
namespace :update do

0 commit comments

Comments
 (0)