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
0 commit comments