Skip to content

opened

opened #400

Workflow file for this run

# Greet new pull requests with a welcome comment and apply labels.
# This workflow must initiate from an authenticated bot repo collaborator.
# Webhook events: Pull requests
name: New pull request
on:
repository_dispatch:
types: [opened, reopened]
jobs:
comment-welcome:
if: ${{ github.actor == 'tfdocsbot' }}
runs-on: ubuntu-latest
steps:
- name: Fetch pull request branch
uses: actions/checkout@v2
with:
repository: ${{ github.event.client_payload.pull_request.head.repo.full_name }}
ref: ${{ github.event.client_payload.pull_request.head.sha }}
- name: Fetch base master branch
run: git fetch -u "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY" master:master
- name: Post comment
env:
HEAD_REPOSITORY: ${{ github.event.client_payload.pull_request.head.repo.full_name }}
HEAD_REF: ${{ github.event.client_payload.pull_request.head.sha }}
PR_NUM: ${{ github.event.client_payload.pull_request.number }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ISSUE_URL: ${{ github.event.client_payload.pull_request.issue_url }}
run: |
git restore -s master -- ./tools/ci/utils.sh
source ./tools/ci/utils.sh
# Grab any changed files under a site/<lang>/ subdirectory.
readarray -t changed_files < <(get_changed_files | grep 'site/.*/')
if [[ ${#changed_files[@]} == 0 ]]; then
echo "No site/<lang>/ files modified in this pull request."
exit 0
fi
msg="<h4>Localization</h4>\n"
msg+="Translators and reviewers are encouraged to submit pull requests from our <a href='https://gitlocalize.com/tensorflow/docs-l10n'>GitLocalize project</a>.\n"
# Preview links and tool usage only needed for notebook changes.
readarray -t changed_notebooks < <(get_changed_files | grep '\.ipynb$')
if [[ ${#changed_notebooks[@]} == 0 ]]; then
echo "No notebooks modified in this pull request."
else
msg+="<h4>Preview</h4>\n"
msg+="Preview and run these notebook edits with Google Colab:\n<ul>\n"
# Link to PR branch in user's fork that is always current.
for fp in "${changed_notebooks[@]}"; do
gh_path="${HEAD_REPOSITORY}/blob/${HEAD_REF}/${fp}"
colab_url="https://colab.research.google.com/github/${gh_path}"
msg+="<li><a href='${colab_url}'>${fp}</a></li>\n"
done
msg+="</ul>\n"
reviewnb_url="https://app.reviewnb.com/${GITHUB_REPOSITORY}/pull/${PR_NUM}/files/"
msg+="Rendered <a href='${reviewnb_url}'>notebook diffs</a> available on ReviewNB.com.\n"
msg+="<h4>Format and style</h4>\n"
msg+="Use the TensorFlow docs <a href='https://github.com/tensorflow/docs/tree/master/tools/tensorflow_docs/tools'>notebook tools</a> to format for consistent source diffs and lint for style:\n"
msg+="<pre>\n$ python3 -m pip install -U --user git+https://github.com/tensorflow/docs\n<br/>"
msg+="$ python3 -m tensorflow_docs.tools.nbfmt notebook.ipynb\n<br/>"
msg+="$ python3 -m tensorflow_docs.tools.nblint --arg=repo:tensorflow/docs-l10n \ \n"
msg+="&nbsp;&nbsp;&nbsp;&nbsp;--styles=tensorflow,tensorflow_docs_l10n notebook.ipynb\n</pre>\n"
msg+="If commits are added to the pull request, synchronize your local branch: <code>git pull origin $HEAD_REF</code>\n"
fi
add_comment "$msg"
label-lang:
if: ${{ github.actor == 'tfdocsbot' }}
runs-on: ubuntu-latest
steps:
- name: Fetch pull request branch
uses: actions/checkout@v2
with:
# Head repo is the user's fork. Ref is the branch name.
repository: ${{ github.event.client_payload.pull_request.head.repo.full_name }}
ref: ${{ github.event.client_payload.pull_request.head.sha }}
- name: Fetch base master branch
run: git fetch -u "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY" master:master
- name: Add labels
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ISSUE_URL: ${{ github.event.client_payload.pull_request.issue_url }}
run: |
git restore -s master -- ./tools/ci/utils.sh
source ./tools/ci/utils.sh
# Grab any changed files under a site/<lang>/ subdirectory.
readarray -t changed_files < <(get_changed_files | grep 'site/.*/')
if [[ ${#changed_files[@]} == 0 ]]; then
echo "No site/<lang>/ files modified in this pull request."
exit 0
fi
declare -a labels
for fp in "${changed_files[@]}"; do
# Parse site/<lang>/ subdirectory for label.
lang=$(echo "$fp" | sed 's|.*site.\([^/]*\)/.*|\1|')
labels+=("$lang")
done
add_label "${labels[@]}"