Skip to content

Commit 5d5c862

Browse files
authored
Add recent blog posts to the organisation README (#2)
We fetch from our main RSS feed every day at 11:00 UTC, then update the "blog" section in the README, which is marked using a comment. It then commits and pushes the changes. This is based on some prior work here: https://github.com/nickcharlton/nickcharlton
1 parent 82d31ce commit 5d5c862

File tree

17 files changed

+1168
-0
lines changed

17 files changed

+1168
-0
lines changed

.github/workflows/tests.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
name: Test
3+
on: [push]
4+
5+
jobs:
6+
test:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v4
10+
- name: Set up Ruby
11+
uses: ruby/setup-ruby@v1
12+
with:
13+
bundler-cache: true
14+
- name: Install dependencies
15+
run: bundle install
16+
- name: Run tests
17+
run: bundle exec rspec
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
name: Update README
3+
4+
on:
5+
workflow_dispatch:
6+
schedule:
7+
- cron: '0 11 * * *'
8+
9+
jobs:
10+
update:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
- name: Set up Ruby
15+
uses: ruby/setup-ruby@v1
16+
with:
17+
bundler-cache: true
18+
- name: Install dependencies
19+
run: bundle install
20+
- name: Update README
21+
run: |-
22+
bin/update_readme
23+
cat profile/README.md
24+
- name: Commit and push if changed
25+
run: |-
26+
git diff
27+
git config --global user.email "[email protected]"
28+
git config --global user.name "README Bot"
29+
git add -A
30+
git commit -m "Updated content" || exit 0
31+
git push

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.bundle
2+
vendor

.ruby-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ruby-3.4.1

Gemfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
source "https://rubygems.org"
2+
3+
gem "excon"
4+
gem "feedjira"
5+
6+
group :development, :test do
7+
gem "rspec"
8+
end

Gemfile.lock

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
GEM
2+
remote: https://rubygems.org/
3+
specs:
4+
crass (1.0.6)
5+
diff-lcs (1.5.1)
6+
excon (1.2.2)
7+
feedjira (3.2.3)
8+
loofah (>= 2.3.1, < 3)
9+
sax-machine (>= 1.0, < 2)
10+
loofah (2.23.1)
11+
crass (~> 1.0.2)
12+
nokogiri (>= 1.12.0)
13+
mini_portile2 (2.8.8)
14+
nokogiri (1.18.1)
15+
mini_portile2 (~> 2.8.2)
16+
racc (~> 1.4)
17+
nokogiri (1.18.1-aarch64-linux-gnu)
18+
racc (~> 1.4)
19+
nokogiri (1.18.1-arm-linux-gnu)
20+
racc (~> 1.4)
21+
nokogiri (1.18.1-arm64-darwin)
22+
racc (~> 1.4)
23+
nokogiri (1.18.1-x86_64-darwin)
24+
racc (~> 1.4)
25+
nokogiri (1.18.1-x86_64-linux-gnu)
26+
racc (~> 1.4)
27+
racc (1.8.1)
28+
rspec (3.13.0)
29+
rspec-core (~> 3.13.0)
30+
rspec-expectations (~> 3.13.0)
31+
rspec-mocks (~> 3.13.0)
32+
rspec-core (3.13.2)
33+
rspec-support (~> 3.13.0)
34+
rspec-expectations (3.13.3)
35+
diff-lcs (>= 1.2.0, < 2.0)
36+
rspec-support (~> 3.13.0)
37+
rspec-mocks (3.13.2)
38+
diff-lcs (>= 1.2.0, < 2.0)
39+
rspec-support (~> 3.13.0)
40+
rspec-support (3.13.2)
41+
sax-machine (1.3.2)
42+
43+
PLATFORMS
44+
aarch64-linux
45+
arm-linux
46+
arm64-darwin
47+
x86-linux
48+
x86_64-darwin
49+
x86_64-linux
50+
51+
DEPENDENCIES
52+
excon
53+
feedjira
54+
rspec
55+
56+
BUNDLED WITH
57+
2.5.23

bin/update_readme

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env ruby
2+
3+
require "bundler"
4+
5+
Bundler.require
6+
7+
$:.push File.expand_path("../lib", __dir__)
8+
9+
require "github_readme"
10+
11+
readme = Readme.new("profile/README.md")
12+
blog = RssFeed.new(url: "https://feeds.feedburner.com/GiantRobotsSmashingIntoOtherGiantRobots")
13+
14+
readme.update(section: "blog", items: blog.take(5))

lib/feed_item.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class FeedItem
2+
attr_accessor :id, :title, :url, :updated_at, :created_at
3+
4+
def initialize(id:, title:, url:, created_at:, updated_at:)
5+
@id = id
6+
@title = title
7+
@url = url
8+
@created_at = created_at
9+
@updated_at = updated_at
10+
end
11+
12+
def to_readme_line
13+
"[#{title}](#{url})\n"
14+
end
15+
end

lib/github_readme.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
require "excon"
2+
3+
require "feed_item"
4+
require "rss_feed"
5+
require "readme"

lib/readme.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
class Readme
2+
def initialize(file_path)
3+
@file_path = file_path
4+
end
5+
6+
def update(section:, items:)
7+
content = items.map(&:to_readme_line).join("\n")
8+
new_contents = insert(file_contents, section, content)
9+
File.write(file_path, new_contents)
10+
end
11+
12+
private
13+
14+
attr_reader :file_path
15+
16+
def file_contents
17+
File.read(file_path)
18+
end
19+
20+
def insert(document, marker, content)
21+
replacement = <<~REPLACEMENT
22+
<!-- #{marker} starts -->
23+
#{content}
24+
<!-- #{marker} ends -->
25+
REPLACEMENT
26+
27+
document.gsub(
28+
/<!\-\- #{marker} starts \-\->.*<!\-\- #{marker} ends \-\->/m,
29+
replacement.chomp
30+
)
31+
end
32+
end

0 commit comments

Comments
 (0)