Skip to content

Commit

Permalink
Add recent blog posts to the organisation README
Browse files Browse the repository at this point in the history
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
  • Loading branch information
nickcharlton committed Dec 24, 2024
1 parent ef3d3f3 commit 12b909b
Show file tree
Hide file tree
Showing 17 changed files with 1,172 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
name: Test
on: [push]

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- name: Install dependencies
run: bundle install
- name: Run tests
run: bundle exec rspec
31 changes: 31 additions & 0 deletions .github/workflows/update_readme.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
name: Update README

on:
workflow_dispatch:
schedule:
- cron: '0 11 * * *'

jobs:
update:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- name: Install dependencies
run: bundle install
- name: Update README
run: |-
bin/update_readme
cat profile/README.md
- name: Commit and push if changed
run: |-
git diff
git config --global user.email "[email protected]"
git config --global user.name "README Bot"
git add -A
git commit -m "Updated content" || exit 0
git push
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.bundle
vendor
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ruby-3.3.6
8 changes: 8 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
source "https://rubygems.org"

gem "excon"
gem "feedjira"

group :development, :test do
gem "rspec"
end
55 changes: 55 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
GEM
remote: https://rubygems.org/
specs:
crass (1.0.6)
diff-lcs (1.5.1)
excon (1.2.2)
feedjira (3.2.3)
loofah (>= 2.3.1, < 3)
sax-machine (>= 1.0, < 2)
loofah (2.23.1)
crass (~> 1.0.2)
nokogiri (>= 1.12.0)
nokogiri (1.17.2-aarch64-linux)
racc (~> 1.4)
nokogiri (1.17.2-arm-linux)
racc (~> 1.4)
nokogiri (1.17.2-arm64-darwin)
racc (~> 1.4)
nokogiri (1.17.2-x86-linux)
racc (~> 1.4)
nokogiri (1.17.2-x86_64-darwin)
racc (~> 1.4)
nokogiri (1.17.2-x86_64-linux)
racc (~> 1.4)
racc (1.8.1)
rspec (3.13.0)
rspec-core (~> 3.13.0)
rspec-expectations (~> 3.13.0)
rspec-mocks (~> 3.13.0)
rspec-core (3.13.2)
rspec-support (~> 3.13.0)
rspec-expectations (3.13.3)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-mocks (3.13.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-support (3.13.2)
sax-machine (1.3.2)

PLATFORMS
aarch64-linux
arm-linux
arm64-darwin
x86-linux
x86_64-darwin
x86_64-linux

DEPENDENCIES
excon
feedjira
rspec

BUNDLED WITH
2.5.23
14 changes: 14 additions & 0 deletions bin/update_readme
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env ruby

require "bundler"

Bundler.require

$:.push File.expand_path("../lib", __dir__)

require "github_readme"

readme = Readme.new("profile/README.md")
blog = RssFeed.new(url: "https://feeds.feedburner.com/GiantRobotsSmashingIntoOtherGiantRobots")

readme.update(section: "blog", items: blog.take(5))
15 changes: 15 additions & 0 deletions lib/feed_item.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class FeedItem
attr_accessor :id, :title, :url, :updated_at, :created_at

def initialize(id:, title:, url:, created_at:, updated_at:)
@id = id
@title = title
@url = url
@created_at = created_at
@updated_at = updated_at
end

def to_readme_line
"[#{title}](#{url})\n"
end
end
5 changes: 5 additions & 0 deletions lib/github_readme.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require "excon"

require "feed_item"
require "rss_feed"
require "readme"
32 changes: 32 additions & 0 deletions lib/readme.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
class Readme
def initialize(file_path)
@file_path = file_path
end

def update(section:, items:)
content = items.map(&:to_readme_line).join("\n")
new_contents = insert(file_contents, section, content)
File.write(file_path, new_contents)
end

private

attr_reader :file_path

def file_contents
File.read(file_path)
end

def insert(document, marker, content)
replacement = <<~REPLACEMENT
<!-- #{marker} starts -->
#{content}
<!-- #{marker} ends -->
REPLACEMENT

document.gsub(
/<!\-\- #{marker} starts \-\->.*<!\-\- #{marker} ends \-\->/m,
replacement.chomp
)
end
end
36 changes: 36 additions & 0 deletions lib/rss_feed.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
require "json"
require "excon"
require "feedjira"

class RssFeed
include Enumerable

def initialize(url:)
@url = url
end

def each
feed.entries.each do |entry|
yield FeedItem.new(
id: entry.id,
title: entry.title,
url: entry.url,
created_at: entry.published,
updated_at: entry.updated
)
end
end

private

attr_reader :url

def feed
@feed ||=
begin
client = Excon.new(url)
response = client.get
Feedjira.parse(response.body)
end
end
end
15 changes: 15 additions & 0 deletions profile/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,21 @@ for your business each step of the way. Since 2003, we have worked to produce
higher-quality products while improving team processes and have done so
successfully for over [1,000 clients.][case studies]

### Writing

<!-- blog starts -->
[Optimize your shell experience](https://thoughtbot.com/blog/optimize-your-shell-experience)

[What I learned about design by helping my grandfather send an email](https://thoughtbot.com/blog/what-i-learned-about-design-by-helping-my-grandfather-send-an-email)

[Zero-downtime with Rails credentials part II](https://thoughtbot.com/blog/from-environment-variables-to-rails-credentials-part-two)

[Making typography decisions with AI as an assistant](https://thoughtbot.com/blog/making-typography-decisions-with-ai-as-an-assistant)

[Testing SQL queries in a Ruby service](https://thoughtbot.com/blog/testing-sql-queries-in-a-ruby-service)

<!-- blog ends -->

[thoughtbot]: https://thoughtbot.com
[design]: https://thoughtbot.com/services/product-design
[development]: https://thoughtbot.com/product-management
Expand Down
20 changes: 20 additions & 0 deletions spec/feed_item_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require "spec_helper"
require "github_readme"

RSpec.describe FeedItem do
describe "#to_readme_line" do
it "is a markdown link to the feed item" do
feed_item = described_class.new(
id: nil,
title: "Blog Post",
url: "http://example.com",
created_at: nil,
updated_at: nil,
)

expect(feed_item.to_readme_line).to eq(
"[Blog Post](http://example.com)\n",
)
end
end
end
Loading

0 comments on commit 12b909b

Please sign in to comment.