From b118d569b962acb212700aac37769a82dbca7725 Mon Sep 17 00:00:00 2001 From: AllyW Date: Tue, 1 Apr 2025 16:28:33 +0800 Subject: [PATCH 1/2] add linter --- .github/actions/AzdevSetup.yml | 44 +++++++++++++++ .github/workflows/AzdevLinter.yml | 91 +++++++++++++++++++++++++++++++ 2 files changed, 135 insertions(+) create mode 100644 .github/actions/AzdevSetup.yml create mode 100644 .github/workflows/AzdevLinter.yml diff --git a/.github/actions/AzdevSetup.yml b/.github/actions/AzdevSetup.yml new file mode 100644 index 00000000000..4f6d532b8f1 --- /dev/null +++ b/.github/actions/AzdevSetup.yml @@ -0,0 +1,44 @@ +name: GH Azdev Setup +description: 'azdev env setup' + +permissions: {} + +runs: + using: 'composite' + steps: + - name: Check Init GH Event + env: + action: ${{ toJSON(github.event.action) }} + label: ${{ toJSON(github.event.label) }} + run: | + echo version cal job start + - name: Set up Python 3.11 + uses: actions/setup-python@v3 + with: + python-version: "3.11" + - name: Checkout CLI main repo + uses: actions/checkout@v4 + with: + repository: Azure/azure-cli + path: ./azure-cli + - name: Move the main repo to the same level as the extension repo + run: | + pwd + ls + mv azure-cli ../ + cd ../ + pwd + ls + - name: Install azdev + run: | + python -m pip install --upgrade pip + set -ev + python -m venv env + chmod +x env/bin/activate + source ./env/bin/activate + pip install azdev + azdev --version + cd ../ + azdev setup -c azure-cli -r azure-cli-extensions --debug + az --version + pip list -v \ No newline at end of file diff --git a/.github/workflows/AzdevLinter.yml b/.github/workflows/AzdevLinter.yml new file mode 100644 index 00000000000..b848f486c78 --- /dev/null +++ b/.github/workflows/AzdevLinter.yml @@ -0,0 +1,91 @@ +name: GH Azdev Linter + +on: + workflow_dispatch: + pull_request_target: + types: [opened, labeled, unlabeled, synchronize] + branches: + - main + +permissions: {} + +jobs: + azdev-linter: + runs-on: ubuntu-latest + permissions: + pull-requests: read + contents: read + steps: + - name: Checkout CLI extension repo + uses: actions/checkout@v4 + with: + fetch-depth: 0 # checkout all branches + ref: ${{ github.event.pull_request.head.ref }} + repository: ${{ github.event.pull_request.head.repo.full_name }} # checkout pull request branch + - name: Azdev Env Setup + uses: ./.github/actions/AzdevSetup.yml + - name: Get Diff Files + env: + bash_sha: ${{ github.event.pull_request.base.sha }} + base_branch: ${{ github.event.pull_request.base.ref }} + base_repo: ${{ github.event.pull_request.base.repo.clone_url }} + base_branch_pre: "upstream" + diff_sha: ${{ github.event.pull_request.head.sha }} + diff_branch: ${{ github.event.pull_request.head.ref }} + repo_full_name: ${{ github.event.pull_request.head.repo.full_name }} + run: | + set -x + git --version + git log --oneline | head -n 10 + git branch -a + git fetch "$base_repo" "$base_branch":"$base_branch_pre"/"$base_branch" + git checkout "$base_branch_pre"/"$base_branch" + git log --oneline | head -n 10 + git checkout "$diff_branch" + git log --oneline | head -n 10 + git --no-pager diff --name-only --diff-filter=ACMRT "$base_branch_pre"/"$base_branch"..."$diff_branch" + set +e + # by default set -e is enabled to run commands, intermediate command failure may cause the whole step to fail. disable it here. + git --no-pager diff --name-only --diff-filter=ACMRT "$base_branch_pre"/"$base_branch"..."$diff_branch" | grep -v "/tests/" > changed_files + cat changed_files + cat changed_files | grep src/ | awk -F"src/" '{print $2}'| grep / | awk -F"/" '{print $1}' | sort | uniq + echo "changed_module_list=$(cat changed_files | grep src/ | awk -F"src/" '{print $2}'| grep / | awk -F"/" '{print $1}' | sort | uniq | xargs)" >> $GITHUB_ENV + - name: Display PR Diff Modules + run: | + for mod in ${changed_module_list[@]} + do + echo changed module: "${mod}" + done + if [ -z "$changed_module_list" ]; then + echo "no_changed_mod=true" >> $GITHUB_ENV + else + echo "no_changed_mod=false" >> $GITHUB_ENV + fi + echo array length + echo ${#changed_module_list[@]} + + - name: Run Azdev Linter + if: ${{ env.no_changed_mod == 'false' }} + env: + pr_label_list: ${{ toJson(github.event.pull_request.labels.*.name) }} + pr_user: ${{ github.event.pull_request.user.login }} + base_branch: ${{ github.event.pull_request.base.ref }} + base_branch_pre: "upstream" + diff_branch: ${{ github.event.pull_request.head.ref }} + run: | + chmod +x env/bin/activate + source ./env/bin/activate + set -ev + + # some module, like confcom, will change local data files, like data/rules.rego, during installation, need to reset when checkout different branch + git checkout -f "$diff_branch" + # always use the latest index.json and scripts from base branch + git checkout "$base_branch_pre"/"$base_branch" -- scripts + git checkout "$base_branch_pre"/"$base_branch" -- src/index.json + merge_base=$(git merge-base HEAD "$base_branch_pre"/"$base_branch") + + for mod in ${changed_module_list[@]} + do + echo changed module: "${mod}" + azdev extension add "${mod}" && azdev linter "${mod}" --min-severity medium --repo ./ --src "$diff_branch" --tgt "$merge_base" + done \ No newline at end of file From 5f5f7140be01c2876bd33e8ba08c9725e2b25236 Mon Sep 17 00:00:00 2001 From: AllyW Date: Tue, 1 Apr 2025 20:21:33 +0800 Subject: [PATCH 2/2] Update setup.py --- src/acat/setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/acat/setup.py b/src/acat/setup.py index d5433b5e313..aacbf5eab22 100644 --- a/src/acat/setup.py +++ b/src/acat/setup.py @@ -10,7 +10,7 @@ # HISTORY.rst entry. -VERSION = '1.0.0b1' +VERSION = '1.0.0b2' # The full list of classifiers is available at # https://pypi.python.org/pypi?%3Aaction=list_classifiers