Skip to content

black-command

black-command #1791

Workflow file for this run

name: black-command
on:
repository_dispatch:
types: [black-command]
jobs:
black:
runs-on: ubuntu-latest
steps:
# Checkout the pull request branch
- uses: actions/checkout@v3
with:
token: ${{ secrets.PR_MAINTAIN }}
repository: ${{ github.event.client_payload.pull_request.head.repo.full_name }}
ref: ${{ github.event.client_payload.pull_request.head.ref }}
# Setup Python environment
- uses: actions/setup-python@v3
with:
python-version: 3.8
# Set cache id
- name: Cache weekly timestamp
id: pip-cache
run: echo "::set-output name=datew::$(date '+%Y-%V')"
shell: bash
# Set cache (linux only)
- name: Cache for pip
uses: actions/cache@v3
id: cache
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ steps.pip-cache.outputs.datew }}
- name: Install isort black autopep8
run: |
sudo apt-get -y install dos2unix libtinfo5
pip install isort black autopep8 torch numpy pycodestyle!=2.11.0
# Execute autopep8 and black
- name: Autopep8 isort Black
id: black
run: |
dos2unix --version
autopep8 --version
isort --version
black --version
find . -type f -not -path "./.git/*" -print0 | xargs -0 -n 1 -P 2 dos2unix # remove return
autopep8 --recursive --in-place --aggressive --aggressive --ignore E721 --max-line-length 200 .
isort .
black --skip-magic-trailing-comma .
repo_name=${{ github.event.client_payload.pull_request.head.repo.full_name }}
repo_name=${repo_name: -5}
echo $repo_name
script_file=runtests.sh
if [[ -f $script_file && "$repo_name" == "MONAI" ]]; then
./runtests.sh --clangformat
fi
changes=
if [ -n "$(git status --porcelain)" ]; then
changes="true"
fi
echo ::set-output name=format::$changes
shell: bash
# Commit the change to the PR branch
- name: Commit to the PR branch
if: steps.black.outputs.format == 'true'
run: |
git config --global user.name 'monai-bot'
git config --global user.email '[email protected]'
git commit -sam "[MONAI] code formatting"
git push
- name: Add reaction
uses: peter-evans/create-or-update-comment@v1
with:
token: ${{ secrets.PR_MAINTAIN }}
repository: ${{ github.event.client_payload.github.payload.repository.full_name }}
comment-id: ${{ github.event.client_payload.github.payload.comment.id }}
reaction-type: hooray