From df1c720d6dfd1ece2860e87fec5f6b2aa31ac926 Mon Sep 17 00:00:00 2001 From: sfujiwara Date: Sun, 24 Nov 2019 16:07:17 +0900 Subject: [PATCH 01/12] check only diff --- README.md | 23 +++++++++++++++++-- bin/diff | 61 +++++++++++++++++++++++++++++++++++++++++++++++++ bin/diff-docker | 8 +++++++ 3 files changed, 90 insertions(+), 2 deletions(-) create mode 100755 bin/diff create mode 100755 bin/diff-docker diff --git a/README.md b/README.md index 3ebc31b..4dd2b17 100644 --- a/README.md +++ b/README.md @@ -11,19 +11,21 @@ This tool works to 3. Apply RedPen to `*.md` 4. Output the result to a text file +### Check all files + Basic usage is as below: ```bash $ ./bin/run ${REPOSITORY} ${BRANCH} ${OUTPUT_FILE} ``` -### Without Docker +#### Without Docker ```bash $ ./bin/run tensorflow/docs master result.txt ``` -### With Docker +#### With Docker If you would like to use Docker, you can also execute the proofreading as @@ -31,6 +33,23 @@ If you would like to use Docker, you can also execute the proofreading as $ ./bin/run-docker tensorflow/docs master result.txt ``` +### Check files which have diff from `origin/master` branch + +Checking all files take too much time to review only one pull request. +Then, we can check only the difference from `origin/master` branch. + +#### Without Docker + +```bash +$ ./bin/diff ${REPOSITORY} ${BRANCH} ${OUTPUT_FILE} +``` + +#### With Docker + +```bash +$ ./bin/diff-docker ${REPOSITORY} ${BRANCH} ${OUTPUT_FILE} +``` + ## Why use RedPen? We are working on translation with more than one person. So It is expected that a lot of orthographical variants will occur. diff --git a/bin/diff b/bin/diff new file mode 100755 index 0000000..9652538 --- /dev/null +++ b/bin/diff @@ -0,0 +1,61 @@ +#!/bin/bash + +# Check the number of arguments +if [ $# -ne 3 ]; then + echo "Error: Invalid arguments" + echo "Usage: ./bin/run.sh " + exit 1 +fi + +GITHUB_REPOSITORY=${1} +GITHUB_REPOSITORY_URL="https://github.com/${GITHUB_REPOSITORY}" +BRANCH=${2} +OUTPUT_FILE=${3} + +# Show config +echo "GITHUB_REPOSITORY: ${GITHUB_REPOSITORY}" +echo "GITHUB_REPOSITORY_URL: ${GITHUB_REPOSITORY_URL}" +echo "BRANCH: ${BRANCH}" +echo "OUTPUT_FILE: ${OUTPUT_FILE}" +echo "" + +TEMP_DIR="ghrepos" + +# Remove temporary directory +rm -rf ${TEMP_DIR} +mkdir ${TEMP_DIR} + +# Clone GitHub repository +git clone -b ${BRANCH} ${GITHUB_REPOSITORY_URL} ${TEMP_DIR}/${GITHUB_REPOSITORY} +echo "" + +# 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}" > "${OUTPUT_FILE}" +echo "BRANCH: ${BRANCH}" >> "${OUTPUT_FILE}" +echo "" >> "${OUTPUT_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}]" >> "${OUTPUT_FILE}" + redpen --result-format plain2 ${markdown} >> "${OUTPUT_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}]" >> "${OUTPUT_FILE}" + redpen --result-format plain2 ${markdown} >> "${OUTPUT_FILE}" + fi + +done diff --git a/bin/diff-docker b/bin/diff-docker new file mode 100755 index 0000000..c34a5e6 --- /dev/null +++ b/bin/diff-docker @@ -0,0 +1,8 @@ +#!/bin/bash + +docker run \ + -it \ + --rm \ + -v $(pwd):/usr/local/documents \ + tfug/proofreading \ + /bin/ash ./bin/diff ${1} ${2} ${3} From d43899b892e5ce5c589c2871903872a4de5b97a7 Mon Sep 17 00:00:00 2001 From: chie8842 Date: Sun, 1 Dec 2019 14:56:57 +0900 Subject: [PATCH 02/12] refactor diff script --- bin/diff | 61 ---------------------------------------------------- bin/run-diff | 39 +++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 61 deletions(-) delete mode 100755 bin/diff create mode 100755 bin/run-diff diff --git a/bin/diff b/bin/diff deleted file mode 100755 index 9652538..0000000 --- a/bin/diff +++ /dev/null @@ -1,61 +0,0 @@ -#!/bin/bash - -# Check the number of arguments -if [ $# -ne 3 ]; then - echo "Error: Invalid arguments" - echo "Usage: ./bin/run.sh " - exit 1 -fi - -GITHUB_REPOSITORY=${1} -GITHUB_REPOSITORY_URL="https://github.com/${GITHUB_REPOSITORY}" -BRANCH=${2} -OUTPUT_FILE=${3} - -# Show config -echo "GITHUB_REPOSITORY: ${GITHUB_REPOSITORY}" -echo "GITHUB_REPOSITORY_URL: ${GITHUB_REPOSITORY_URL}" -echo "BRANCH: ${BRANCH}" -echo "OUTPUT_FILE: ${OUTPUT_FILE}" -echo "" - -TEMP_DIR="ghrepos" - -# Remove temporary directory -rm -rf ${TEMP_DIR} -mkdir ${TEMP_DIR} - -# Clone GitHub repository -git clone -b ${BRANCH} ${GITHUB_REPOSITORY_URL} ${TEMP_DIR}/${GITHUB_REPOSITORY} -echo "" - -# 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}" > "${OUTPUT_FILE}" -echo "BRANCH: ${BRANCH}" >> "${OUTPUT_FILE}" -echo "" >> "${OUTPUT_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}]" >> "${OUTPUT_FILE}" - redpen --result-format plain2 ${markdown} >> "${OUTPUT_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}]" >> "${OUTPUT_FILE}" - redpen --result-format plain2 ${markdown} >> "${OUTPUT_FILE}" - fi - -done diff --git a/bin/run-diff b/bin/run-diff new file mode 100755 index 0000000..ee5bf0d --- /dev/null +++ b/bin/run-diff @@ -0,0 +1,39 @@ +#!/bin/ash + +################################################################### +# 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 From 397363de48c24ecc0cdf5e3e062ee98b2c2cca32 Mon Sep 17 00:00:00 2001 From: chie8842 Date: Sun, 1 Dec 2019 14:57:43 +0900 Subject: [PATCH 03/12] split run to run and run-all --- bin/run | 79 +++++++++++++++++++++++++++++------------------------ bin/run-all | 26 ++++++++++++++++++ 2 files changed, 70 insertions(+), 35 deletions(-) create mode 100755 bin/run-all diff --git a/bin/run b/bin/run index 67b8baa..adbab61 100755 --- a/bin/run +++ b/bin/run @@ -1,45 +1,54 @@ -#!/bin/bash +#!/bin/ash + +################################################################### +# 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}" - -TEMP_DIR="ghrepos" - -# Remove temporary directory -rm -rf ${TEMP_DIR} -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 "LOG_FILE: ${LOG_FILE}" +echo "" + +export TEMP_DIR="ghrepos" + +## Remove temporary directory +#rm -rf ${TEMP_DIR} +#mkdir ${TEMP_DIR} +# +## Clone GitHub repository +#git clone -b ${BRANCH} ${GITHUB_REPOSITORY_URL} ${TEMP_DIR}/${GITHUB_REPOSITORY} +#echo "" + +if [ -n "${TYPE}" -a "${TYPE}" = "all" ]; then + echo "Run bin/run-all" + /bin/ash bin/run-all $@ +else + echo "Run bin/run-diff" + /bin/ash bin/run-diff $@ +fi diff --git a/bin/run-all b/bin/run-all new file mode 100755 index 0000000..024592d --- /dev/null +++ b/bin/run-all @@ -0,0 +1,26 @@ +#!/bin/ash + +################################################################### +# 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 From 2c6c85b142701a0d30885498e4dfa43cd57c0c46 Mon Sep 17 00:00:00 2001 From: chie8842 Date: Sun, 1 Dec 2019 14:58:04 +0900 Subject: [PATCH 04/12] update README --- README.md | 39 ++++++++++++++++----------------------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 4dd2b17..0aee4cf 100644 --- a/README.md +++ b/README.md @@ -11,43 +11,36 @@ This tool works to 3. Apply RedPen to `*.md` 4. Output the result to a text file -### Check all files +### Description + +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) Basic usage is as below: ```bash -$ ./bin/run ${REPOSITORY} ${BRANCH} ${OUTPUT_FILE} +$ ./bin/run ${REPOSITORY} ${BRANCH} [all] ``` -#### Without Docker +### Run script without Docker ```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 +### Run script with Docker If you would like to use Docker, you can also execute the proofreading as ```bash -$ ./bin/run-docker tensorflow/docs master result.txt -``` - -### Check files which have diff from `origin/master` branch - -Checking all files take too much time to review only one pull request. -Then, we can check only the difference from `origin/master` branch. - -#### Without Docker - -```bash -$ ./bin/diff ${REPOSITORY} ${BRANCH} ${OUTPUT_FILE} -``` - -#### With Docker - -```bash -$ ./bin/diff-docker ${REPOSITORY} ${BRANCH} ${OUTPUT_FILE} +# 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? From c555711d472f5af0125f8a15e0289b9b3b4649a6 Mon Sep 17 00:00:00 2001 From: chie8842 Date: Sun, 1 Dec 2019 15:06:07 +0900 Subject: [PATCH 05/12] remove diff-docker --- bin/diff-docker | 8 -------- 1 file changed, 8 deletions(-) delete mode 100755 bin/diff-docker diff --git a/bin/diff-docker b/bin/diff-docker deleted file mode 100755 index c34a5e6..0000000 --- a/bin/diff-docker +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash - -docker run \ - -it \ - --rm \ - -v $(pwd):/usr/local/documents \ - tfug/proofreading \ - /bin/ash ./bin/diff ${1} ${2} ${3} From b6a69bb05a802b5684ef0d5bcfbde21b09bd31a5 Mon Sep 17 00:00:00 2001 From: chie8842 Date: Sun, 1 Dec 2019 15:16:18 +0900 Subject: [PATCH 06/12] fix comments --- bin/run | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/bin/run b/bin/run index adbab61..da29987 100755 --- a/bin/run +++ b/bin/run @@ -37,14 +37,15 @@ echo "" export TEMP_DIR="ghrepos" -## Remove temporary directory -#rm -rf ${TEMP_DIR} -#mkdir ${TEMP_DIR} -# -## Clone GitHub repository -#git clone -b ${BRANCH} ${GITHUB_REPOSITORY_URL} ${TEMP_DIR}/${GITHUB_REPOSITORY} -#echo "" +# Remove temporary directory +rm -rf ${TEMP_DIR} +mkdir ${TEMP_DIR} +# Clone GitHub repository +git clone -b ${BRANCH} ${GITHUB_REPOSITORY_URL} ${TEMP_DIR}/${GITHUB_REPOSITORY} +echo "" + +# execute run-all or run-diff script if [ -n "${TYPE}" -a "${TYPE}" = "all" ]; then echo "Run bin/run-all" /bin/ash bin/run-all $@ From 87bdc2dc3e779211ab43b60e369d41e847cfbf2c Mon Sep 17 00:00:00 2001 From: Chie Hayashida Date: Sat, 21 Dec 2019 17:30:19 +0900 Subject: [PATCH 07/12] Update bin/run Co-Authored-By: Shuhei Fujiwara --- bin/run | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/run b/bin/run index da29987..34c959b 100755 --- a/bin/run +++ b/bin/run @@ -1,4 +1,4 @@ -#!/bin/ash +#!/bin/sh ################################################################### # Script Name : run From 00015165880dbc143c5d32b75f9491f92bcb6bee Mon Sep 17 00:00:00 2001 From: Chie Hayashida Date: Sat, 21 Dec 2019 17:30:31 +0900 Subject: [PATCH 08/12] Update bin/run Co-Authored-By: Shuhei Fujiwara --- bin/run | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/run b/bin/run index 34c959b..50b7095 100755 --- a/bin/run +++ b/bin/run @@ -48,7 +48,7 @@ echo "" # execute run-all or run-diff script if [ -n "${TYPE}" -a "${TYPE}" = "all" ]; then echo "Run bin/run-all" - /bin/ash bin/run-all $@ + ./bin/run-all $@ else echo "Run bin/run-diff" /bin/ash bin/run-diff $@ From b444bb738612c129b9983d98415ed43555a294d1 Mon Sep 17 00:00:00 2001 From: Chie Hayashida Date: Sat, 21 Dec 2019 17:30:40 +0900 Subject: [PATCH 09/12] Update bin/run Co-Authored-By: Shuhei Fujiwara --- bin/run | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/run b/bin/run index 50b7095..e2c2371 100755 --- a/bin/run +++ b/bin/run @@ -51,5 +51,5 @@ if [ -n "${TYPE}" -a "${TYPE}" = "all" ]; then ./bin/run-all $@ else echo "Run bin/run-diff" - /bin/ash bin/run-diff $@ + ./bin/run-diff $@ fi From 0be8e9bc334e61eaa750121759f9dde523b15210 Mon Sep 17 00:00:00 2001 From: Chie Hayashida Date: Sat, 21 Dec 2019 17:30:45 +0900 Subject: [PATCH 10/12] Update bin/run-diff Co-Authored-By: Shuhei Fujiwara --- bin/run-diff | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/run-diff b/bin/run-diff index ee5bf0d..2916ea8 100755 --- a/bin/run-diff +++ b/bin/run-diff @@ -1,4 +1,4 @@ -#!/bin/ash +#!/bin/sh ################################################################### # Script Name : run-diff From 6f0f7182d4196dbe7cc68ce9e1994f791f7cb9b7 Mon Sep 17 00:00:00 2001 From: Chie Hayashida Date: Sat, 21 Dec 2019 17:33:40 +0900 Subject: [PATCH 11/12] Update bin/run-all Co-Authored-By: Shuhei Fujiwara --- bin/run-all | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/run-all b/bin/run-all index 024592d..6e282aa 100755 --- a/bin/run-all +++ b/bin/run-all @@ -1,4 +1,4 @@ -#!/bin/ash +#!/bin/sh ################################################################### # Script Name : run-all From dd04378a1a24219167385c5e65a508e77d590870 Mon Sep 17 00:00:00 2001 From: chie8842 Date: Sat, 21 Dec 2019 17:48:54 +0900 Subject: [PATCH 12/12] update README --- README.md | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 0aee4cf..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,20 +11,23 @@ This tool works to 3. Apply RedPen to `*.md` 4. Output the result to a text file -### Description 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) -Basic usage is as below: +## How To Use -```bash -$ ./bin/run ${REPOSITORY} ${BRANCH} [all] -``` +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 # To check files which are differ from `origin/master` branch $ ./bin/run tensorflow/docs master @@ -33,9 +36,10 @@ $ ./bin/run tensorflow/docs master all ``` ### Run script with Docker +#### requirements +* Install [Docker](https://www.docker.com/products/docker-desktop) -If you would like to use Docker, you can also execute the proofreading as - +#### Usage ```bash # To check files which are differ from `origin/master` branch $ ./bin/run-docker tensorflow/docs master