Skip to content

Commit

Permalink
Update format.yml | Improve the github action (#1875)
Browse files Browse the repository at this point in the history
* Update format.yml | Improve the github action

* Update format-py.sh

* Update format-cpp.sh

* Update format.yml

* Update accuracy-squad.py | testing

* Update format.yml

* [Automated Commit] Format Codebase

---------

Co-authored-by: arjunsuresh <arjunsuresh@users.noreply.github.com>
  • Loading branch information
arjunsuresh and arjunsuresh authored Oct 29, 2024
1 parent c72a59f commit de6c550
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 20 deletions.
4 changes: 2 additions & 2 deletions .github/scripts/format-cpp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

# Checks all the modified c/c++ files, format them and adds them
# to the commit.
for FILE in $(git diff upstream/$1 --name-only | grep -E '.*\.(cc|cpp|h|hpp)$')
for FILE in $(git diff $1/$2 --name-only | grep -E '.*\.(cc|cpp|h|hpp)$')
do
clang-format -i -style=file $FILE
git add $FILE
done
done
4 changes: 2 additions & 2 deletions .github/scripts/format-py.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

# Checks all the modified c/c++ files, format them and adds them
# to the commit.
for FILE in $(git diff upstream/$1 --name-only | grep -E '.*\.py$')
for FILE in $(git diff $1/$2 --name-only | grep -E '.*\.py$')
do
autopep8 --in-place -a $FILE
git add $FILE
done
done
25 changes: 11 additions & 14 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

# Automatic code formatting
name: "format"
on:
pull_request:
Expand All @@ -8,16 +8,14 @@ on:

env:
python_version: "3.9"
repo: "mlcommons/inference"

jobs:
format-code:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.head_ref || github.ref_name }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.ref }}
- name: Set up Python ${{ env.python_version }}
uses: actions/setup-python@v3
with:
Expand All @@ -29,27 +27,26 @@ jobs:
- name: Grant permissions
run: |
chmod 777 "${GITHUB_WORKSPACE}/.github/scripts/format-cpp.sh"
chmod 777 "${GITHUB_WORKSPACE}/.github/scripts/format-py.sh"
chmod +x "${GITHUB_WORKSPACE}/.github/scripts/format-cpp.sh"
chmod +x "${GITHUB_WORKSPACE}/.github/scripts/format-py.sh"
- name: Format Codebase
if: ${{ github.event.pull_request.base.repo.full_name == env.repo }}
run: |
git remote add upstream ${{ github.event.pull_request.base.repo.clone_url }}
git fetch upstream ${{ github.event.pull_request.base.ref }}
".github/scripts/format-cpp.sh" "${{ github.event.pull_request.base.ref }}"
".github/scripts/format-py.sh" "${{ github.event.pull_request.base.ref }}"
git fetch upstream
".github/scripts/format-cpp.sh" "upstream" "${{ github.event.pull_request.base.ref }}"
".github/scripts/format-py.sh" "upstream" "${{ github.event.pull_request.base.ref }}"
- name: Commit
run: |
cd ${GITHUB_WORKSPACE}
HAS_CHANGES=$(git diff --cached --name-only)
HAS_CHANGES=$(git diff --staged --name-only)
if [ ${#HAS_CHANGES} -gt 0 ]; then
git log
git config --global user.email "${GITHUB_ACTOR_ID}+${GITHUB_ACTOR}@users.noreply.github.com"
git config --global user.name "${GITHUB_ACTOR}"
git config --global user.email "${{ github.actor }}@users.noreply.github.com"
git config --global user.name "${{ github.actor }}"
git commit -m '[Automated Commit] Format Codebase'
git push upstream ${{ github.head_ref || github.ref_name }}
git push
fi
3 changes: 1 addition & 2 deletions language/bert/accuracy-squad.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@
"int64": np.int64,
"float16": np.float16,
"float32": np.float32,
"float64": np.float64,
}
"float64": np.float64}


def get_final_text(pred_text, orig_text, do_lower_case):
Expand Down

0 comments on commit de6c550

Please sign in to comment.