Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 28 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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?
Expand Down
64 changes: 37 additions & 27 deletions bin/run
Original file line number Diff line number Diff line change
@@ -1,45 +1,55 @@
#!/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 <repository name> <branch name> <output file>"
echo "Usage: ./bin/run <repository name> <branch name> <run-type>"
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}
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
26 changes: 26 additions & 0 deletions bin/run-all
Original file line number Diff line number Diff line change
@@ -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
39 changes: 39 additions & 0 deletions bin/run-diff
Original file line number Diff line number Diff line change
@@ -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