diff --git a/README.md b/README.md index 3ebc31b..012a168 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # Proofreading for TensorFlow docs translation -[tensorflow/docs](https://github.com/tensorflow/docs)の日本語訳の表記ゆれ等をチェックするツールです。 +## Description -## Usage +[tensorflow/docs](https://github.com/tensorflow/docs)の日本語訳の表記ゆれ等をチェックするツールです。 This tool works to @@ -11,24 +11,40 @@ This tool works to 3. Apply RedPen to `*.md` 4. Output the result to a text file -Basic usage is as below: -```bash -$ ./bin/run ${REPOSITORY} ${BRANCH} ${OUTPUT_FILE} -``` +There are following 2 patterns of checking with this script. +1. Check documents which are differ from `origin/master`(default) +2. Check all documents(with `all` option) + +## How To Use -### Without Docker +There are following 2 ways to run this script. +### Run script without Docker + +#### requirements + +* Install [`jupyter`](https://jupyter.org/install) and [`RedPen`](http://redpen.cc/docs/1.10/index.html) +* bin directory of `RedPen` should be added to `PATH` variable. + +#### Usage ```bash -$ ./bin/run tensorflow/docs master result.txt +# To check files which are differ from `origin/master` branch +$ ./bin/run tensorflow/docs master +# To check all files +$ ./bin/run tensorflow/docs master all ``` -### With Docker - -If you would like to use Docker, you can also execute the proofreading as +### Run script with Docker +#### requirements +* Install [Docker](https://www.docker.com/products/docker-desktop) +#### Usage ```bash -$ ./bin/run-docker tensorflow/docs master result.txt +# To check files which are differ from `origin/master` branch +$ ./bin/run-docker tensorflow/docs master +# To check all files +$ ./bin/run-docker tensorflow/docs master all ``` ## Why use RedPen? diff --git a/bin/run b/bin/run index 67b8baa..e2c2371 100755 --- a/bin/run +++ b/bin/run @@ -1,23 +1,41 @@ -#!/bin/bash +#!/bin/sh + +################################################################### +# Script Name : run +# Description : A script to check orthographical variants +# Args : +# GITHUB_REPOSITORY: organization name/repository name like +# "tensorflow/docs" +# BRANCH: branch name +# TYPE(OPTIONAL): all +# Usage Example: +# ./bin/run tensorflow/docs master # check documents which is \ +# differ from master branch of tensorflow/docs +# ./bin/run tensorflow/docs master all # check all documents +################################################################### +set -e # Check the number of arguments -if [ $# -ne 3 ]; then +if [ $# -lt 2 -o $# -gt 3 ]; then echo "Error: Invalid arguments" - echo "Usage: ./bin/run.sh " + echo "Usage: ./bin/run " exit 1 fi -GITHUB_REPOSITORY=${1} -GITHUB_REPOSITORY_URL="https://github.com/${GITHUB_REPOSITORY}" -BRANCH=${2} -OUTPUT_FILE=${3} +export GITHUB_REPOSITORY=${1} +export GITHUB_REPOSITORY_URL="https://github.com/${GITHUB_REPOSITORY}" +export BRANCH=${2} +TYPE=${3} +export LOG_FILE=result.txt +# Show config echo "GITHUB_REPOSITORY: ${GITHUB_REPOSITORY}" echo "GITHUB_REPOSITORY_URL: ${GITHUB_REPOSITORY_URL}" echo "BRANCH: ${BRANCH}" -echo "OUTPUT_FILE: ${OUTPUT_FILE}" +echo "LOG_FILE: ${LOG_FILE}" +echo "" -TEMP_DIR="ghrepos" +export TEMP_DIR="ghrepos" # Remove temporary directory rm -rf ${TEMP_DIR} @@ -25,21 +43,13 @@ mkdir ${TEMP_DIR} # Clone GitHub repository git clone -b ${BRANCH} ${GITHUB_REPOSITORY_URL} ${TEMP_DIR}/${GITHUB_REPOSITORY} - -# Convert all notebooks to markdowns -notebooks=`find ${TEMP_DIR}/${GITHUB_REPOSITORY}/site/ja -type f | grep .ipynb` -for notebook in ${notebooks}; do - jupyter nbconvert --to markdown ${notebook} -done - -# Create output file -echo "GITHUB_REPOSITORY: ${GITHUB_REPOSITORY}" > "${OUTPUT_FILE}" -echo "BRANCH: ${BRANCH}" >> "${OUTPUT_FILE}" -echo "" >> "${OUTPUT_FILE}" - -# Apply RedPen to all markdowns -files=`find ${TEMP_DIR}/${GITHUB_REPOSITORY}/site/ja -type f | grep .md` -for file in ${files}; do - echo "[${file}]" >> "${OUTPUT_FILE}" - redpen --result-format plain2 ${file} >> "${OUTPUT_FILE}" -done +echo "" + +# execute run-all or run-diff script +if [ -n "${TYPE}" -a "${TYPE}" = "all" ]; then + echo "Run bin/run-all" + ./bin/run-all $@ +else + echo "Run bin/run-diff" + ./bin/run-diff $@ +fi diff --git a/bin/run-all b/bin/run-all new file mode 100755 index 0000000..6e282aa --- /dev/null +++ b/bin/run-all @@ -0,0 +1,26 @@ +#!/bin/sh + +################################################################### +# Script Name : run-all +# Description : A script to check orthographical variants for all +# documents in specified branch of repository. +# This script is child script of bin/run. +################################################################### + +# Convert all notebooks to markdowns +notebooks=`find ${TEMP_DIR}/${GITHUB_REPOSITORY}/site/ja -type f | grep .ipynb` +for notebook in ${notebooks}; do + jupyter nbconvert --to markdown ${notebook} +done + +# Create output file +echo "GITHUB_REPOSITORY: ${GITHUB_REPOSITORY}" > "${LOG_FILE}" +echo "BRANCH: ${BRANCH}" >> "${LOG_FILE}" +echo "" >> "${LOG_FILE}" + +# Apply RedPen to all markdowns +files=`find ${TEMP_DIR}/${GITHUB_REPOSITORY}/site/ja -type f | grep .md` +for file in ${files}; do + echo "[${file}]" >> "${LOG_FILE}" + redpen --result-format plain2 ${file} >> "${LOG_FILE}" +done diff --git a/bin/run-diff b/bin/run-diff new file mode 100755 index 0000000..2916ea8 --- /dev/null +++ b/bin/run-diff @@ -0,0 +1,39 @@ +#!/bin/sh + +################################################################### +# Script Name : run-diff +# Description : A script to check orthographical variants for +# documents which are differ form master branch of +# https://github.com/tensorflow/docs repository. +# This script is child script of bin/run. +################################################################### +# Find diff files +cd ${TEMP_DIR}/${GITHUB_REPOSITORY} && diff_files=$(git diff --name-only origin/master) +echo "DIFF_FILES:" +echo ${diff_files} +echo "" +cd - + +# Create output file +echo "GITHUB_REPOSITORY: ${GITHUB_REPOSITORY}" > "${LOG_FILE}" +echo "BRANCH: ${BRANCH}" >> "${LOG_FILE}" +echo "" >> "${LOG_FILE}" + +for file in ${diff_files}; do + + # The case diff file is markdown + if [ ${file##*.} = "md" ]; then + markdown=${TEMP_DIR}/${GITHUB_REPOSITORY}/${file} + echo "[${markdown}]" >> "${LOG_FILE}" + redpen --result-format plain2 ${markdown} >> "${LOG_FILE}" + + # The case diff file is notebook + elif [ ${file##*.} = "ipynb" ]; then + notebook=${TEMP_DIR}/${GITHUB_REPOSITORY}/${file} + markdown=${TEMP_DIR}/${GITHUB_REPOSITORY}/${file%.ipynb}.md + jupyter nbconvert --to markdown ${notebook} + echo "[${markdown}]" >> "${LOG_FILE}" + redpen --result-format plain2 ${markdown} >> "${LOG_FILE}" + fi + +done