Skip to content

Commit 7059eb5

Browse files
committed
add linter
1 parent 35d36e2 commit 7059eb5

File tree

3 files changed

+226
-0
lines changed

3 files changed

+226
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: GH Azdev Setup
2+
description: 'azdev env setup'
3+
4+
runs:
5+
using: 'composite'
6+
steps:
7+
- name: Check Init GH Event
8+
env:
9+
action: ${{ toJSON(github.event.action) }}
10+
label: ${{ toJSON(github.event.label) }}
11+
shell: bash
12+
run: |
13+
echo version cal job start
14+
- name: Checkout CLI extension repo
15+
uses: actions/checkout@v4
16+
with:
17+
fetch-depth: 0 # checkout all branches
18+
ref: ${{ github.event.pull_request.head.ref }}
19+
repository: ${{ github.event.pull_request.head.repo.full_name }} # checkout pull request branch
20+
- name: Set up Python 3.11
21+
uses: actions/setup-python@v3
22+
with:
23+
python-version: "3.11"
24+
- name: Checkout CLI main repo
25+
uses: actions/checkout@v4
26+
with:
27+
repository: Azure/azure-cli
28+
path: ./azure-cli
29+
- name: Move the main repo to the same level as the extension repo
30+
shell: bash
31+
run: |
32+
pwd
33+
ls
34+
mv azure-cli ../
35+
cd ../
36+
pwd
37+
ls
38+
- name: Install azdev
39+
shell: bash
40+
run: |
41+
python -m pip install --upgrade pip
42+
set -ev
43+
python -m venv env
44+
chmod +x env/bin/activate
45+
source ./env/bin/activate
46+
pip install azdev
47+
azdev --version
48+
cd ../
49+
azdev setup -c azure-cli -r azure-cli-extensions --debug
50+
az --version
51+
pip list -v

.github/workflows/AzdevLinter.yml

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: GH Azdev Linter
2+
3+
on:
4+
workflow_dispatch:
5+
pull_request_target:
6+
types: [opened, labeled, unlabeled, synchronize]
7+
branches:
8+
- main
9+
10+
permissions: {}
11+
12+
jobs:
13+
azdev-linter:
14+
runs-on: ubuntu-latest
15+
permissions:
16+
pull-requests: read
17+
contents: read
18+
steps:
19+
- name: Checkout CLI extension repo
20+
uses: actions/checkout@v4
21+
- name: Azdev Env Setup
22+
uses: ./.github/actions/env-setup
23+
- name: Get Diff Files
24+
env:
25+
bash_sha: ${{ github.event.pull_request.base.sha }}
26+
base_branch: ${{ github.event.pull_request.base.ref }}
27+
base_repo: ${{ github.event.pull_request.base.repo.clone_url }}
28+
base_branch_pre: "upstream"
29+
diff_sha: ${{ github.event.pull_request.head.sha }}
30+
diff_branch: ${{ github.event.pull_request.head.ref }}
31+
repo_full_name: ${{ github.event.pull_request.head.repo.full_name }}
32+
run: |
33+
set -x
34+
git --version
35+
git log --oneline | head -n 10
36+
git branch -a
37+
git fetch "$base_repo" "$base_branch":"$base_branch_pre"/"$base_branch"
38+
git checkout "$base_branch_pre"/"$base_branch"
39+
git log --oneline | head -n 10
40+
git checkout "$diff_branch"
41+
git log --oneline | head -n 10
42+
git --no-pager diff --name-only --diff-filter=ACMRT "$base_branch_pre"/"$base_branch"..."$diff_branch"
43+
set +e
44+
# by default set -e is enabled to run commands, intermediate command failure may cause the whole step to fail. disable it here.
45+
git --no-pager diff --name-only --diff-filter=ACMRT "$base_branch_pre"/"$base_branch"..."$diff_branch" | grep -v "/tests/" > changed_files
46+
cat changed_files
47+
cat changed_files | grep src/ | awk -F"src/" '{print $2}'| grep / | awk -F"/" '{print $1}' | sort | uniq
48+
echo "changed_module_list=$(cat changed_files | grep src/ | awk -F"src/" '{print $2}'| grep / | awk -F"/" '{print $1}' | sort | uniq | xargs)" >> $GITHUB_ENV
49+
- name: Display PR Diff Modules
50+
run: |
51+
for mod in ${changed_module_list[@]}
52+
do
53+
echo changed module: "${mod}"
54+
done
55+
if [ -z "$changed_module_list" ]; then
56+
echo "no_changed_mod=true" >> $GITHUB_ENV
57+
else
58+
echo "no_changed_mod=false" >> $GITHUB_ENV
59+
fi
60+
echo array length
61+
echo ${#changed_module_list[@]}
62+
63+
- name: Run Azdev Linter
64+
if: ${{ env.no_changed_mod == 'false' }}
65+
env:
66+
pr_label_list: ${{ toJson(github.event.pull_request.labels.*.name) }}
67+
pr_user: ${{ github.event.pull_request.user.login }}
68+
base_branch: ${{ github.event.pull_request.base.ref }}
69+
base_branch_pre: "upstream"
70+
diff_branch: ${{ github.event.pull_request.head.ref }}
71+
run: |
72+
chmod +x env/bin/activate
73+
source ./env/bin/activate
74+
set -ev
75+
76+
git checkout -f "$diff_branch"
77+
# always use the latest index.json and scripts from base branch
78+
git checkout "$base_branch_pre"/"$base_branch" -- scripts
79+
git checkout "$base_branch_pre"/"$base_branch" -- src/index.json
80+
merge_base=$(git merge-base HEAD "$base_branch_pre"/"$base_branch")
81+
echo merge_base: "$merge_base"
82+
83+
for mod in ${changed_module_list[@]}
84+
do
85+
echo changed module: "${mod}"
86+
azdev extension add "${mod}" && azdev linter "${mod}" --min-severity medium --repo ./ --src "$diff_branch" --tgt "$merge_base"
87+
done

.github/workflows/AzdevStyle.yml

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
name: GH Azdev Style
2+
3+
on:
4+
workflow_dispatch:
5+
pull_request_target:
6+
types: [opened, labeled, unlabeled, synchronize]
7+
branches:
8+
- main
9+
10+
permissions: {}
11+
12+
jobs:
13+
azdev-style:
14+
runs-on: ubuntu-latest
15+
permissions:
16+
pull-requests: read
17+
contents: read
18+
steps:
19+
- name: Checkout CLI extension repo
20+
uses: actions/checkout@v4
21+
- name: Azdev Env Setup
22+
uses: ./.github/actions/env-setup
23+
- name: Get Diff Files
24+
env:
25+
bash_sha: ${{ github.event.pull_request.base.sha }}
26+
base_branch: ${{ github.event.pull_request.base.ref }}
27+
base_repo: ${{ github.event.pull_request.base.repo.clone_url }}
28+
base_branch_pre: "upstream"
29+
diff_sha: ${{ github.event.pull_request.head.sha }}
30+
diff_branch: ${{ github.event.pull_request.head.ref }}
31+
repo_full_name: ${{ github.event.pull_request.head.repo.full_name }}
32+
run: |
33+
set -x
34+
git --version
35+
git log --oneline | head -n 10
36+
git branch -a
37+
git fetch "$base_repo" "$base_branch":"$base_branch_pre"/"$base_branch"
38+
git checkout "$base_branch_pre"/"$base_branch"
39+
git log --oneline | head -n 10
40+
git checkout "$diff_branch"
41+
git log --oneline | head -n 10
42+
git --no-pager diff --name-only --diff-filter=ACMRT "$base_branch_pre"/"$base_branch"..."$diff_branch"
43+
set +e
44+
# by default set -e is enabled to run commands, intermediate command failure may cause the whole step to fail. disable it here.
45+
git --no-pager diff --name-only --diff-filter=ACMRT "$base_branch_pre"/"$base_branch"..."$diff_branch" | grep -v "/tests/" > changed_files
46+
cat changed_files
47+
cat changed_files | grep src/ | awk -F"src/" '{print $2}'| grep / | awk -F"/" '{print $1}' | sort | uniq
48+
echo "changed_module_list=$(cat changed_files | grep src/ | awk -F"src/" '{print $2}'| grep / | awk -F"/" '{print $1}' | sort | uniq | xargs)" >> $GITHUB_ENV
49+
- name: Display PR Diff Modules
50+
run: |
51+
for mod in ${changed_module_list[@]}
52+
do
53+
echo changed module: "${mod}"
54+
done
55+
if [ -z "$changed_module_list" ]; then
56+
echo "no_changed_mod=true" >> $GITHUB_ENV
57+
else
58+
echo "no_changed_mod=false" >> $GITHUB_ENV
59+
fi
60+
echo array length
61+
echo ${#changed_module_list[@]}
62+
63+
- name: Run Azdev Style
64+
if: ${{ env.no_changed_mod == 'false' }}
65+
env:
66+
pr_label_list: ${{ toJson(github.event.pull_request.labels.*.name) }}
67+
pr_user: ${{ github.event.pull_request.user.login }}
68+
base_branch: ${{ github.event.pull_request.base.ref }}
69+
base_branch_pre: "upstream"
70+
diff_branch: ${{ github.event.pull_request.head.ref }}
71+
run: |
72+
chmod +x env/bin/activate
73+
source ./env/bin/activate
74+
set -ev
75+
76+
git checkout -f "$diff_branch"
77+
# always use the latest index.json and scripts from base branch
78+
git checkout "$base_branch_pre"/"$base_branch" -- scripts
79+
git checkout "$base_branch_pre"/"$base_branch" -- src/index.json
80+
merge_base=$(git merge-base HEAD "$base_branch_pre"/"$base_branch")
81+
echo merge_base: "$merge_base"
82+
83+
for mod in ${changed_module_list[@]}
84+
do
85+
echo changed module: "${mod}"
86+
azdev extension add "${mod}"
87+
azdev style "${mod}"
88+
done

0 commit comments

Comments
 (0)