From 31104970005255f8ccd59dfc630a5aaa3a45eeca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Torres?= Date: Wed, 7 Oct 2020 17:27:26 +0100 Subject: [PATCH] Actualizar docstats en la Github Action --- .github/workflows/main.yml | 15 ++++++---- Rakefile | 58 +++++++++++++++++++----------------- content/docstats.adoc | 60 ++++++++++++++++++++------------------ 3 files changed, 72 insertions(+), 61 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e8545d7..8ec21be 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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: @@ -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' || ( diff --git a/Rakefile b/Rakefile index 060690c..fc1d78c 100644 --- a/Rakefile +++ b/Rakefile @@ -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")] @@ -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 @@ -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 @@ -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 = /^(?\d+)\. /.match(sectionbody.previous_element) chapter_number = matches['chapter_number'] @@ -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 \ No newline at end of file diff --git a/content/docstats.adoc b/content/docstats.adoc index 7ba6c54..6c705fc 100644 --- a/content/docstats.adoc +++ b/content/docstats.adoc @@ -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