Skip to content

Commit

Permalink
Add GitHub Action workflow to build the book (#50)
Browse files Browse the repository at this point in the history
* Add GitHub Action workflow to build the book

- updated packages & bundler
- removed 'kindlegen'. More at tdtds/kindlegen#42

* [GitHub Actions] run only on master

Co-authored-by: Alexandre Rousseau <contact@rousseau-alexandre.fr>

* store builds in YAML instead of JSON

* [GitHub Actions] change tag_name to include version and github run number

Co-authored-by: Alexandre Rousseau <contact@rousseau-alexandre.fr>

Co-authored-by: Alexandre Rousseau <contact@rousseau-alexandre.fr>
  • Loading branch information
grabberhamster812 and madeindjs committed Aug 31, 2020
1 parent ddf9009 commit e2746a0
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 24 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Build Book

on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ruby/setup-ruby@v1
with:
ruby-version: 2.7
- run: bundle install
- run: rake build:CI
- uses: actions/github-script@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const fs = require('fs').promises;
const { repo: { owner, repo }, sha } = context;
const release = await github.repos.createRelease({
owner, repo,
tag_name: `v6.${process.env.GITHUB_RUN_NUMBER}`,
draft: true,
target_commitish: sha
});
console.log('A release has been created');
const build_dir = 'build';
for (let file of await fs.readdir(build_dir)) {
if (file == '.gitkeep') continue;
console.log('uploading', file);
await github.repos.uploadReleaseAsset({
owner, repo,
release_id: release.data.id,
name: file,
data: await fs.readFile(`${build_dir}/${file}`)
});
}
console.log('DONE')
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ gem "asciidoctor-pdf", "~> 1.5.beta.7"
gem "concurrent-ruby", "~> 1.1"
gem "rouge", "~> 3.3"
gem "asciidoctor-epub3", "~> 1.5.alpha.9"
gem "kindlegen", "~> 3.0"
# TODO: uncomment when issue(https://github.com/tdtds/kindlegen/issues/42) solved
# gem "kindlegen", "~> 3.0"
39 changes: 18 additions & 21 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ GEM
public_suffix (>= 2.0.2, < 5.0)
afm (0.2.2)
asciidoctor (2.0.10)
asciidoctor-epub3 (1.5.0.alpha.9)
asciidoctor (>= 1.5.0, < 3.0.0)
concurrent-ruby (~> 1.1.5)
gepub (~> 1.0.2)
thread_safe (~> 0.3.6)
asciidoctor-pdf (1.5.0.rc.2)
asciidoctor-epub3 (1.5.0.alpha.18)
asciidoctor (>= 1.5.6, < 3.0.0)
gepub (~> 1.0.0)
mime-types (~> 3.0)
asciidoctor-pdf (1.5.3)
asciidoctor (>= 1.5.3, < 3.0.0)
concurrent-ruby (~> 1.1.0)
prawn (~> 2.2.0)
Expand All @@ -21,20 +20,20 @@ GEM
prawn-templates (~> 0.1.0)
safe_yaml (~> 1.0.0)
thread_safe (~> 0.3.0)
treetop (~> 1.5.0)
treetop (~> 1.6.0)
ttfunk (~> 1.5.0, >= 1.5.1)
concurrent-ruby (1.1.5)
concurrent-ruby (1.1.7)
css_parser (1.7.1)
addressable
gepub (1.0.7)
gepub (1.0.11)
nokogiri (>= 1.8.2, < 1.11)
rubyzip (> 1.1.1, < 2.1)
rubyzip (> 1.1.1, < 2.3)
hashery (2.1.2)
kindlegen (3.0.5)
rake
rubyzip
mime-types (3.3.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2020.0512)
mini_portile2 (2.4.0)
nokogiri (1.10.8)
nokogiri (1.10.10)
mini_portile2 (~> 2.4.0)
pdf-core (0.7.0)
pdf-reader (2.4.0)
Expand All @@ -57,14 +56,13 @@ GEM
prawn-templates (0.1.2)
pdf-reader (~> 2.0)
prawn (~> 2.2)
public_suffix (4.0.3)
rake (13.0.1)
rouge (3.14.0)
public_suffix (4.0.5)
rouge (3.22.0)
ruby-rc4 (0.1.5)
rubyzip (2.0.0)
rubyzip (2.2.0)
safe_yaml (1.0.5)
thread_safe (0.3.6)
treetop (1.5.3)
treetop (1.6.10)
polyglot (~> 0.3)
ttfunk (1.5.1)

Expand All @@ -76,8 +74,7 @@ DEPENDENCIES
asciidoctor-epub3 (~> 1.5.alpha.9)
asciidoctor-pdf (~> 1.5.beta.7)
concurrent-ruby (~> 1.1)
kindlegen (~> 3.0)
rouge (~> 3.3)

BUNDLED WITH
1.17.3
2.1.4
22 changes: 20 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'asciidoctor'
require 'asciidoctor-pdf'
require 'yaml'

LANGS = %w[en fr es].freeze
VERSIONS = %w[5 6].freeze
Expand All @@ -10,13 +11,13 @@ FONTS_DIR = File.join __dir__, 'fonts'
def check_args(args)
lang = args[:lang]
unless LANGS.include?(lang)
msg = format('Lang not availaible. Select on of theses langs: %s', LANGS.join(', '))
msg = format('Lang not available. Select on of these langs: %s', LANGS.join(', '))
raise ArgumentError, msg
end

version = args[:version]
unless VERSIONS.include?(version)
msg = format('Version not availaible. Select on of theses versions: %s', VERSIONS.join(', '))
msg = format('Version not available. Select on of these versions: %s', VERSIONS.join(', '))
raise ArgumentError, msg
end

Expand All @@ -32,6 +33,23 @@ def out_filename(args, extension)
end

namespace :build do
desc 'Build for all versions, languages'
task :CI do
builds = YAML.load(File.read("builds.yaml"))
builds.entries.each do |version, languages|
languages.each do |language|
puts "VERSION: #{version} - LANG: #{language}"
args = { version: version, lang: language }
Rake::Task['build:pdf'].execute(args)
Rake::Task['build:html'].execute(args)
Rake::Task['build:epub'].execute(args)
# [temporary] no mobi build
# TODO: fix when issue(https://github.com/tdtds/kindlegen/issues/42) solved
# Rake::Task['build:mobi'].execute(args)
end
end
end

desc 'Build all versions'
task :all, [:version, :lang] do |_task, args|
check_args(args)
Expand Down
2 changes: 2 additions & 0 deletions builds.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
5: [en, fr]
6: [en, es, fr]

0 comments on commit e2746a0

Please sign in to comment.