Skip to content

Commit 581e813

Browse files
DenisVieriu97skotapati
authored andcommitted
Add lint.yml mps script (pytorch#3)
* Add linter * Fix lint * Fix lint pytorch#2
1 parent 6556991 commit 581e813

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed

.github/workflows/lint_mps.yml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: Lint MPS
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
- release/*
9+
workflow_dispatch:
10+
11+
concurrency:
12+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}-${{ github.event_name == 'workflow_dispatch' }}-${{ github.event_name == 'schedule' }}
13+
cancel-in-progress: true
14+
15+
jobs:
16+
lintrunner-mps:
17+
runs-on: macos-executorch
18+
steps:
19+
- uses: actions/checkout@v4
20+
with:
21+
submodules: 'recursive'
22+
- name: Lintrunner
23+
id: lint-mps
24+
run: |
25+
set -eux
26+
27+
# Conda setup
28+
if conda info --envs | grep -w -q "env-${{ runner.name }}"; then echo "env-${{ runner.name }} already exists"; else conda create -y -n "env-${{ runner.name }}" python=3.10; fi
29+
CONDA_ENV="~/miniconda3/envs/env-${{ runner.name }}"
30+
if [[ -n "$CONDA_ENV" ]]; then
31+
# Use binaries under conda environment
32+
export PATH="$CONDA_ENV/bin":$PATH
33+
fi
34+
35+
conda init zsh
36+
conda init
37+
source ~/miniconda3/bin/activate
38+
conda deactivate
39+
conda activate "$CONDA_ENV"
40+
41+
source .ci/scripts/utils.sh
42+
# This is a simple Python script but as it tries to import executorch.examples.models,
43+
# it requires a whole bunch of ExecuTorch dependencies on the Docker image
44+
install_pip_dependencies
45+
install_executorch
46+
brew install jq
47+
48+
source .ci/scripts/utils.sh
49+
50+
# Install lint depdendencies
51+
pip install lintrunner==0.11.0
52+
pip install lintrunner-adapters==0.11.0
53+
54+
CACHE_DIRECTORY="/tmp/.lintbin"
55+
# Try to recover the cached binaries
56+
if [[ -d "${CACHE_DIRECTORY}" ]]; then
57+
# It's ok to fail this as lintrunner init would download these binaries
58+
# again if they do not exist
59+
cp -r "${CACHE_DIRECTORY}" . || true
60+
fi
61+
62+
# This has already been cached in the docker image
63+
lintrunner init 2> /dev/null
64+
65+
RC=0
66+
# Run lintrunner on all files
67+
if ! lintrunner --force-color --all-files --tee-json lint.json 2> /dev/null; then
68+
echo ""
69+
echo -e "\e[1m\e[36mYou can reproduce these results locally by using \`lintrunner\`. (If you don't get the same results, run \'lintrunner init\' to update your local linter)\e[0m"
70+
echo -e "\e[1m\e[36mSee https://github.com/pytorch/pytorch/wiki/lintrunner for setup instructions.\e[0m"
71+
RC=1
72+
fi
73+
74+
# Use jq to massage the JSON lint output into GitHub Actions workflow commands.
75+
jq --raw-output \
76+
'"::\(if .severity == "advice" or .severity == "disabled" then "warning" else .severity end) file=\(.path),line=\(.line),col=\(.char),title=\(.code) \(.name)::" + (.description | gsub("\\n"; "%0A"))' \
77+
lint.json || true
78+
79+
exit $RC

0 commit comments

Comments
 (0)