From 0ac7f03b1b85a056d8260567ac6c2c386c55c838 Mon Sep 17 00:00:00 2001 From: Gabriel Arazas Date: Tue, 25 Apr 2023 18:59:34 +0800 Subject: [PATCH] Replace Makefile with Rakefile --- .github/workflows/build-drafts.yml | 2 +- .github/workflows/build-webring.yml | 2 +- .github/workflows/build.yml | 2 +- Gemfile | 6 +++- Gemfile.lock | 2 ++ Makefile | 20 ----------- README.adoc | 2 +- Rakefile | 53 +++++++++++++++++++++++++++++ gemset.nix | 35 +++++++++++++------ netlify.toml | 15 ++------ 10 files changed, 91 insertions(+), 48 deletions(-) delete mode 100644 Makefile create mode 100644 Rakefile diff --git a/.github/workflows/build-drafts.yml b/.github/workflows/build-drafts.yml index aee5d9e..1e19b0a 100644 --- a/.github/workflows/build-drafts.yml +++ b/.github/workflows/build-drafts.yml @@ -27,4 +27,4 @@ jobs: git fetch origin +refs/heads/content/*:refs/heads/content/* - name: Build and deploy site run: | - nix develop --command bash -c "make build-draft && netlify deploy --context branch-deploy" + nix develop --command bash -c "netlify deploy --build --context branch-deploy" diff --git a/.github/workflows/build-webring.yml b/.github/workflows/build-webring.yml index 45d5951..3cb1d47 100644 --- a/.github/workflows/build-webring.yml +++ b/.github/workflows/build-webring.yml @@ -12,7 +12,7 @@ jobs: with: nix_path: nixpkgs=channel:nixpkgs-unstable - name: Build webring - run: nix develop -c make build-openring + run: nix develop -c rake build_openring - name: Commit the changes run: | # Show the commit as set by the Actions bot. diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 168ee17..cb3db73 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -27,4 +27,4 @@ jobs: git fetch origin +refs/heads/content/*:refs/heads/content/* - name: Build and deploy site run: | - nix develop --command bash -c "make build && netlify deploy" + nix develop --command bash -c "netlify deploy --build --prod" diff --git a/Gemfile b/Gemfile index e5de560..dea0ed2 100644 --- a/Gemfile +++ b/Gemfile @@ -10,11 +10,15 @@ gem 'asciidoctor-tabs', github: 'asciidoctor/asciidoctor-tabs' gem 'concurrent-ruby' gem 'open-uri-cached' gem 'rouge' -gem 'rubocop' gem 'rugged' gem 'slim' gem 'tilt' group :development do + gem 'rake' gem 'ruby-lsp', require: false end + +group :lint do + gem 'rubocop', require: false +end diff --git a/Gemfile.lock b/Gemfile.lock index 3d9c921..b840dda 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -51,6 +51,7 @@ GEM ast (~> 2.4.1) prettier_print (1.2.0) rainbow (3.1.1) + rake (13.0.6) regexp_parser (2.7.0) rexml (3.2.5) rouge (3.30.0) @@ -95,6 +96,7 @@ DEPENDENCIES asciidoctor-tabs! concurrent-ruby open-uri-cached + rake rouge rubocop ruby-lsp diff --git a/Makefile b/Makefile deleted file mode 100644 index 7a50e74..0000000 --- a/Makefile +++ /dev/null @@ -1,20 +0,0 @@ -.PHONY: build -build: - hugo --destination public - -.PHONY: build-draft -build-draft: - hugo --environment development --buildDrafts --buildFuture --buildExpired --destination public - -.PHONY: build-openring -build-openring: - ./bin/openring-create --input assets/templates/openring-input.html --output layouts/partials/openring.html - -.PHONY: serve -serve: - hugo serve --buildFuture --verboseLog --destination public - -.PHONY: update -update: - curl --silent --location https://api.github.com/repos/foo-dogsquared/hugo-theme-more-contentful/commits | jq '.[0].sha' --raw-output | xargs --replace='{}' hugo mod get -u "github.com/foo-dogsquared/hugo-theme-more-contentful@{}" && hugo mod tidy - curl --silent --location https://api.github.com/repos/foo-dogsquared/hugo-mod-web-feeds/commits | jq '.[0].sha' --raw-output | xargs --replace='{}' hugo mod get -u "github.com/foo-dogsquared/hugo-mod-web-feeds@{}" && hugo mod tidy diff --git a/README.adoc b/README.adoc index 8201145..2d51514 100644 --- a/README.adoc +++ b/README.adoc @@ -21,7 +21,7 @@ Otherwise, you might have to manually install the following components: With the things installed, you can just clone the Git repo of this project, run `make serve`, and voila! You're now a content creator! -Most of the usual tasks done with this project should be handled by this project already which is listed in its link:Makefile[Makefile]. +Most of the usual tasks done with this project should be handled by this project already which is listed in its link:./Rakefile[Rakefile]. You can view the file for more details but for the sake of completion, here are the following tasks. - Building the website with `make serve`. diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..16a0cf9 --- /dev/null +++ b/Rakefile @@ -0,0 +1,53 @@ +# frozen_string_literal: true + +require 'json' +require 'open3' +require 'shellwords' + +github_api_headers = { + 'Header' => 'application/vnd.github+json', + 'X-GitHub-Api-Version' => '2022-11-28' +} +github_api_headers['Authorization'] = "Token #{ENV['GITHUB_API_BEARER_TOKEN']}" if ENV['GITHUB_API_BEARER_TOKEN'] + +desc 'Build the site in Netlify with the given context' +task :build, [:context, :base_url] do |_, args| + args.with_defaults(context: 'production') + draft_args = '--environment development --buildDrafts --buildFuture --buildExpired' unless args.context == 'production' + base_uri_args = "-b #{args.base_url}" if args.base_url + + # Unfortunately, we have to pass it inside of another Nix shell since + # Asciidoctor doesn't want to be found when executed in here for whatever + # reason. + sh "nix develop -c hugo #{draft_args} #{base_uri_args} --destination public" +end + +desc 'Build the webring to be embedded with the site' +task :build_webring, [:limit, :input, :output, :file] do |_, args| + args.with_defaults( + limit: 5, + file: './data/blogs.json', + input: './assets/templates/openring-input.html', + output: './layouts/partials/openring.html' + ) + + File.open args.file do |f| + feeds = JSON.parse(f.read).sample(args.limit) + feeds.map! { |feed| "-s #{Shellwords.escape(feed)}" } + + command = ['openring', '-n', args.limit.to_s] + command.append(*feeds) + + Open3.pipeline command.join(' '), in: args.input, out: args.output + end +end + +desc 'Create a web server' +task :serve do + sh 'nix develop -c hugo serve --buildFuture --verboseLog --destination public' +end + +desc 'Update the Hugo modules for this project' +task :update do + sh 'hugo mod get ./... && hugo mod tidy' +end diff --git a/gemset.nix b/gemset.nix index 0846a6b..23c30bd 100644 --- a/gemset.nix +++ b/gemset.nix @@ -30,6 +30,7 @@ platforms = []; source = { path = "gems"; + target = "ruby"; type = "path"; }; targets = []; @@ -77,7 +78,7 @@ version = "1.0.0.beta.3"; }; ast = { - groups = ["default"]; + groups = ["default" "lint"]; platforms = []; source = { remotes = ["https://rubygems.org"]; @@ -166,7 +167,7 @@ version = "1.0.1.11"; }; json = { - groups = ["default"]; + groups = ["default" "lint"]; platforms = []; source = { remotes = ["https://rubygems.org"]; @@ -226,7 +227,7 @@ version = "1.0.0"; }; parallel = { - groups = ["default"]; + groups = ["default" "lint"]; platforms = []; source = { remotes = ["https://rubygems.org"]; @@ -239,7 +240,7 @@ }; parser = { dependencies = ["ast"]; - groups = ["default"]; + groups = ["default" "lint"]; platforms = []; source = { remotes = ["https://rubygems.org"]; @@ -263,7 +264,7 @@ version = "1.2.0"; }; rainbow = { - groups = ["default"]; + groups = ["default" "lint"]; platforms = []; source = { remotes = ["https://rubygems.org"]; @@ -274,8 +275,20 @@ targets = []; version = "3.1.1"; }; + rake = { + groups = ["development"]; + platforms = []; + source = { + remotes = ["https://rubygems.org"]; + sha256 = "15whn7p9nrkxangbs9hh75q585yfn66lv0v2mhj6q6dl6x8bzr2w"; + target = "ruby"; + type = "gem"; + }; + targets = []; + version = "13.0.6"; + }; regexp_parser = { - groups = ["default"]; + groups = ["default" "lint"]; platforms = []; source = { remotes = ["https://rubygems.org"]; @@ -287,7 +300,7 @@ version = "2.7.0"; }; rexml = { - groups = ["default"]; + groups = ["default" "lint"]; platforms = []; source = { remotes = ["https://rubygems.org"]; @@ -312,7 +325,7 @@ }; rubocop = { dependencies = ["json" "parallel" "parser" "rainbow" "regexp_parser" "rexml" "rubocop-ast" "ruby-progressbar" "unicode-display_width"]; - groups = ["default"]; + groups = ["lint"]; platforms = []; source = { remotes = ["https://rubygems.org"]; @@ -325,7 +338,7 @@ }; rubocop-ast = { dependencies = ["parser"]; - groups = ["default"]; + groups = ["default" "lint"]; platforms = []; source = { remotes = ["https://rubygems.org"]; @@ -350,7 +363,7 @@ version = "0.4.1"; }; ruby-progressbar = { - groups = ["default"]; + groups = ["default" "lint"]; platforms = []; source = { remotes = ["https://rubygems.org"]; @@ -448,7 +461,7 @@ version = "2.1.0"; }; unicode-display_width = { - groups = ["default"]; + groups = ["default" "lint"]; platforms = []; source = { remotes = ["https://rubygems.org"]; diff --git a/netlify.toml b/netlify.toml index 796407a..e29857d 100644 --- a/netlify.toml +++ b/netlify.toml @@ -1,18 +1,9 @@ [build] publish = "public/" -command = "make build -e" - -[context.production.environment] -HUGO_BASEURL = "$DEPLOY_URL" +command = "rake build" [context.branch-deploy] -command = "make build-draft -e" - -[context.branch-deploy.environment] -HUGO_BASEURL = "$DEPLOY_PRIME_URL" +command = "rake build[branch-deploy,$DEPLOY_PRIME_URL]" [context.deploy-preview] -command = "make build-draft -e" - -[context.deploy-preview.environment] -HUGO_BASEURL = "$DEPLOY_PRIME_URL" +command = "rake build[deploy-preview,$DEPLOY_PRIME_URL]"