From 52199897dc1568fec6e6f5e2022a4a5f2dff7e74 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Mon, 13 Jul 2026 08:26:51 +0000 Subject: [PATCH] Automate homepage footer update date --- .github/workflows/branch-preview.yml | 1 + .github/workflows/deploy.yml | 1 + _layouts/about.liquid | 2 +- _plugins/repository-last-updated.rb | 19 +++++++++++ test/repository_last_updated_test.rb | 50 ++++++++++++++++++++++++++++ 5 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 _plugins/repository-last-updated.rb create mode 100644 test/repository_last_updated_test.rb diff --git a/.github/workflows/branch-preview.yml b/.github/workflows/branch-preview.yml index 7e36ed60..5b07a1d7 100644 --- a/.github/workflows/branch-preview.yml +++ b/.github/workflows/branch-preview.yml @@ -64,6 +64,7 @@ jobs: run: | pip3 install --upgrade jupyter ruby test/cache_bust_test.rb + ruby test/repository_last_updated_test.rb export JEKYLL_ENV=production bundle exec jekyll build - name: Purge unused CSS 🧹 diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 90725049..24346427 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -88,6 +88,7 @@ jobs: run: | pip3 install --upgrade jupyter ruby test/cache_bust_test.rb + ruby test/repository_last_updated_test.rb export JEKYLL_ENV=production bundle exec jekyll build - name: Purge unused CSS 🧹 diff --git a/_layouts/about.liquid b/_layouts/about.liquid index f83dab0c..d2a6bac8 100644 --- a/_layouts/about.liquid +++ b/_layouts/about.liquid @@ -144,5 +144,5 @@ layout: default - + diff --git a/_plugins/repository-last-updated.rb b/_plugins/repository-last-updated.rb new file mode 100644 index 00000000..b079f5f6 --- /dev/null +++ b/_plugins/repository-last-updated.rb @@ -0,0 +1,19 @@ +# Derive the site's update date from the commit being built, not the build clock. +require 'open3' + +module Jekyll + class RepositoryLastUpdatedGenerator < Generator + priority :highest + + def generate(site) + timestamp, status = Open3.capture2('git', 'log', '-1', '--format=%cI', 'HEAD', chdir: site.source) + timestamp = timestamp.strip + + unless status.success? && !timestamp.empty? + raise 'Could not determine the repository HEAD commit date' + end + + site.config['repository_last_updated_at'] = timestamp + end + end +end diff --git a/test/repository_last_updated_test.rb b/test/repository_last_updated_test.rb new file mode 100644 index 00000000..d1969d38 --- /dev/null +++ b/test/repository_last_updated_test.rb @@ -0,0 +1,50 @@ +# AI-generated regression coverage for the build-time repository update date. +require 'fileutils' +require 'minitest/autorun' +require 'tmpdir' + +module Jekyll + class Generator + def self.priority(_priority); end + end +end + +require_relative '../_plugins/repository-last-updated' + +class RepositoryLastUpdatedGeneratorTest < Minitest::Test + Site = Struct.new(:source, :config) + + def setup + @tmpdir = Dir.mktmpdir('repository-last-updated-test') + git('init', '--quiet') + git('config', 'user.name', 'Test User') + git('config', 'user.email', 'test@example.com') + File.write(File.join(@tmpdir, 'index.md'), 'test') + git('add', 'index.md') + git( + 'commit', '--quiet', '-m', 'Test commit', + env: { + 'GIT_AUTHOR_DATE' => '2026-07-12T09:10:11Z', + 'GIT_COMMITTER_DATE' => '2026-07-13T12:35:52+08:00' + } + ) + end + + def teardown + FileUtils.remove_entry(@tmpdir) + end + + def test_exposes_head_committer_timestamp_to_liquid + site = Site.new(@tmpdir, {}) + + Jekyll::RepositoryLastUpdatedGenerator.new.generate(site) + + assert_equal '2026-07-13T12:35:52+08:00', site.config['repository_last_updated_at'] + end + + private + + def git(*arguments, env: {}) + system(env, 'git', *arguments, chdir: @tmpdir, exception: true) + end +end