Skip to content

Commit

Permalink
Actualizar docstats en la Github Action
Browse files Browse the repository at this point in the history
  • Loading branch information
jesustorresdev committed Oct 7, 2020
1 parent 16cd8ca commit 3110497
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 61 deletions.
15 changes: 9 additions & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@ on:
workflow_dispatch:

jobs:
test-and-publish:
build-and-publish:
runs-on: ubuntu-20.04
steps:

- name: Obtener contenidos
- name: Obtener el proyecto
uses: actions/checkout@v2
with:
persist-credentials: false

- name: Extract el nombre de la rama
uses: nelonoel/branch-name@v1

- name: Configurar Ruby
uses: ruby/setup-ruby@v1
with:
Expand All @@ -23,12 +26,12 @@ jobs:
- name: Instalar dependencias
run: bundle install

- name: Generar y testear
- name: Generar la documentación
run: bundle exec rake build

- name: Testear
run: bundle exec rake tests

- name: Extract el nombre de la rama
uses: nelonoel/branch-name@v1

- name: Publicar
if: |
github.event != 'pull_request' || (
Expand Down
58 changes: 32 additions & 26 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
require "nokogiri"

READING_SPEED_IN_WORDS_PER_MINUTE = 200

PROJECT_DIR = Rake.application.original_dir

CONTENT_DIR = File.join(PROJECT_DIR, "content")
CONFIG_DIR = File.join(PROJECT_DIR, "config")
OUTPUT_DIR = File.join(PROJECT_DIR, "output")

INPUT_FILES = FileList[File.join(CONTENT_DIR, "**/*.adoc")]
CONFIG_FILES = FileList[File.join(CONFIG_DIR, "**/*.adoc"),
File.join(CONFIG_DIR, "**/*.yml")]
DOCUMENT_MAIN_FILE = File.join(CONTENT_DIR, "main.adoc")
DOCSTATS_FILE = File.join(CONTENT_DIR, "docstats.adoc")

INCLUDED_FILES = FileList[File.join(CONTENT_DIR, "**/*.adoc"),
File.join(CONFIG_DIR, "**/*.adoc"),
File.join(CONFIG_DIR, "**/*.yml")
].exclude(DOCUMENT_MAIN_FILE)

MEDIA_FILES = FileList[File.join(CONTENT_DIR, "**/images/**", "*.jpg"),
File.join(CONTENT_DIR, "**/images/**", "*.png"),
File.join(CONTENT_DIR, "**/images/**", "*.svg")]
Expand All @@ -22,17 +29,13 @@ OUTPUT_PDF_DIR = File.dirname(OUTPUT_PDF_FILE)
OUTPUT_EPUB_FILE = File.join(OUTPUT_DIR, "epub", "sistemas-operativos.epub")
OUTPUT_EPUB_DIR = File.dirname(OUTPUT_EPUB_FILE)

DOCUMENT_MAIN_FILE = File.join(CONTENT_DIR, "main.adoc")
DOCSTATS_FILE = File.join(CONTENT_DIR, "docstats.adoc")
READING_SPEED_IN_WORDS_PER_MINUTE = 200

task :default => :html
task :default => :build
task :build => [:docstats, :html]

desc 'Generar la versión en HTML de la documentación'
task :html => [:html_only, :html_media_files]
task :html_only => OUTPUT_HTML_FILE
task :html => [OUTPUT_HTML_FILE, :html_media_files]

file OUTPUT_HTML_FILE => [OUTPUT_HTML_DIR, *INPUT_FILES, *CONFIG_FILES] do |t|
file OUTPUT_HTML_FILE => [OUTPUT_HTML_DIR, DOCUMENT_MAIN_FILE, *INCLUDED_FILES] do |t|
sh "asciidoctor", "--backend", "html5", DOCUMENT_MAIN_FILE, "-o", t.name
end

Expand All @@ -57,7 +60,7 @@ directory OUTPUT_HTML_DIR
desc 'Generar la versión en PDF de la documentación'
task :pdf => OUTPUT_PDF_FILE

file OUTPUT_PDF_FILE => [OUTPUT_PDF_DIR, *INPUT_FILES, *CONFIG_FILES] do |t|
file OUTPUT_PDF_FILE => [OUTPUT_PDF_DIR, DOCUMENT_MAIN_FILE, *INCLUDED_FILES] do |t|
sh "asciidoctor", "--require", "asciidoctor-pdf", "--backend", "pdf", DOCUMENT_MAIN_FILE, "-o", t.name
end

Expand All @@ -66,16 +69,30 @@ directory OUTPUT_PDF_DIR
desc 'Generar la versión en EPUB de la documentación'
task :epub => OUTPUT_EPUB_FILE

file :epub => [OUTPUT_EPUB_DIR, *INPUT_FILES, *CONFIG_FILES] do |t|
file OUTPUT_EPUB_FILE => [OUTPUT_EPUB_DIR, DOCUMENT_MAIN_FILE, *INCLUDED_FILES] do |t|
sh "asciidoctor", "--require", "asciidoctor-epub3", "--backend", "epub3", DOCUMENT_MAIN_FILE, "-o", t.name
end

directory OUTPUT_EPUB_DIR

desc 'Ejecutar los tests'
task :tests => :html do |t|
typhoeus_config = '{"ssl_verifyhost": 0, "ssl_verifypeer": false}'
sh "htmlproofer", "--typhoeus_config", typhoeus_config, OUTPUT_HTML_DIR
end

desc 'Limpiar todos los archivos generados'
task :clean do |t|
rm_r OUTPUT_DIR
end

desc 'Generar el archivo de información estadística'
task :docstats => :html_only do |t|
document = Nokogiri::HTML.parse(open(OUTPUT_HTML_FILE))
task :docstats do |t|
# Contamos las palabras en la versión HTML del documento
output_html = `asciidoctor --backend html5 #{DOCUMENT_MAIN_FILE} -o -`
docstats = open(DOCSTATS_FILE, "w")

document = Nokogiri::HTML.parse(output_html)
document.css(".sect1 > h2 + .sectionbody").each do |sectionbody|
if matches = /^(?<chapter_number>\d+)\. /.match(sectionbody.previous_element)
chapter_number = matches['chapter_number']
Expand All @@ -101,14 +118,3 @@ task :docstats => :html_only do |t|
end
end
end

desc 'Ejecutar los tests'
task :tests => :html do |t|
typhoeus_config = '{"ssl_verifyhost": 0, "ssl_verifypeer": false}'
sh "htmlproofer", "--typhoeus_config", typhoeus_config, OUTPUT_HTML_DIR
end

desc 'Limpiar todos los archivos generados'
task :clean do |t|
rm_r OUTPUT_DIR
end
60 changes: 31 additions & 29 deletions content/docstats.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,39 @@
:C07_reading_time: 16 minutos
:C08_words: 1907
:C08_reading_time: 10 minutos
:C09_words: 7806
:C09_words: 7803
:C09_reading_time: 39 minutos
:C10_words: 6451
:C10_reading_time: 32 minutos
:C11_words: 1044
:C11_words: 1041
:C11_reading_time: 5 minutos
:C12_words: 4665
:C12_reading_time: 23 minutos
:C13_words: 5954
:C13_reading_time: 30 minutos
:C14_words: 1709
:C14_reading_time: 9 minutos
:C15_words: 2077
:C15_reading_time: 10 minutos
:C16_words: 7523
:C16_reading_time: 38 minutos
:C17_words: 1326
:C17_reading_time: 7 minutos
:C18_words: 423
:C18_reading_time: 2 minutos
:C19_words: 220
:C19_reading_time: 1 minuto
:C20_words: 1279
:C20_reading_time: 6 minutos
:C21_words: 4295
:C21_reading_time: 21 minutos
:C22_words: 1711
:C22_reading_time: 9 minutos
:C23_words: 1893
:C12_words: 3126
:C12_reading_time: 16 minutos
:C13_words: 1542
:C13_reading_time: 8 minutos
:C14_words: 5951
:C14_reading_time: 30 minutos
:C15_words: 1709
:C15_reading_time: 9 minutos
:C16_words: 2077
:C16_reading_time: 10 minutos
:C17_words: 7520
:C17_reading_time: 38 minutos
:C18_words: 1326
:C18_reading_time: 7 minutos
:C19_words: 423
:C19_reading_time: 2 minutos
:C20_words: 220
:C20_reading_time: 1 minuto
:C21_words: 1279
:C21_reading_time: 6 minutos
:C22_words: 4295
:C22_reading_time: 21 minutos
:C23_words: 1708
:C23_reading_time: 9 minutos
:C24_words: 4147
:C24_reading_time: 21 minutos
:C25_words: 1347
:C25_reading_time: 7 minutos
:C24_words: 1893
:C24_reading_time: 9 minutos
:C25_words: 4147
:C25_reading_time: 21 minutos
:C26_words: 1347
:C26_reading_time: 7 minutos

0 comments on commit 3110497

Please sign in to comment.