diff --git a/.github/workflows/VersionCalPRComment.yml b/.github/workflows/VersionCalPRComment.yml index 472a46d708e..43964550aab 100644 --- a/.github/workflows/VersionCalPRComment.yml +++ b/.github/workflows/VersionCalPRComment.yml @@ -17,29 +17,42 @@ jobs: if: ${{ !contains(github.event.pull_request.labels.*.name, 'skip-cal-version') && (!contains(fromJSON('["labeled", "unlabeled"]'), github.event.action) || github.event.label.name != 'release-version-block') }} runs-on: ubuntu-latest permissions: - pull-requests: write + pull-requests: read contents: read steps: - - name: Set Init Version Message + - name: Check Init GH Event env: action: ${{ toJSON(github.event.action) }} label: ${{ toJSON(github.event.label) }} run: | - echo "message=$(echo 'Suggested init version: 1.0.0b1 for preview release and 1.0.0 for stable release')" >> $GITHUB_ENV - - name: Set up Python 3.10 + echo version cal job start + - name: Set up Python 3.11 uses: actions/setup-python@v3 with: - python-version: "3.10" + python-version: "3.11" - name: Checkout CLI extension repo - uses: actions/checkout@master + 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: Show workdirectory after site cloned + - name: Show work directory after site cloned run: | pwd ls + - name: Set Default Version Output + env: + result_path: "./cal_result" + output_file: "version_update.txt" + remove_labels_file: "labels_removed.txt" + run: | + set -x + mkdir "$result_path" + cd "$result_path" + echo " - For more info about extension versioning, please refer to [Extension version schema](https://github.com/Azure/azure-cli/blob/release/doc/extensions/versioning_guidelines.md)" > "$output_file" + echo "release-version-block" > "$remove_labels_file" + cd ../ + ls "$result_path" - name: Get Diff Files env: bash_sha: ${{ github.event.pull_request.base.sha }} @@ -64,14 +77,14 @@ jobs: cat changed_files | grep azext_ | awk -F"azext_" '{print $1}'| awk -F"/" '{print $2}' | sort | uniq > changed_modules echo "changed_module_list=$(cat changed_files | grep azext_ | awk -F"azext_" '{print $1}'| awk -F"/" '{print $2}' | sort | uniq | xargs)" >> $GITHUB_ENV git --no-pager diff --diff-filter=ACMRT "$base_branch_pre"/"$base_branch"..."$diff_branch" > "$diff_code_file" - - name: Display Diff Modules + - name: Display PR Diff Modules run: | for mod in "$changed_module_list" do echo changed module: "${mod}" done - name: Checkout CLI main repo - uses: actions/checkout@master + uses: actions/checkout@v4 with: repository: Azure/azure-cli path: ./azure-cli @@ -108,47 +121,103 @@ jobs: diff_branch: ${{ github.event.pull_request.head.ref }} base_meta_path: "./base_meta/" diff_meta_path: "./diff_meta/" + result_path: "./cal_result" output_file: "version_update.txt" + add_labels_file: "labels_added.json" + remove_labels_file: "labels_removed.txt" run: | - chmod +x env/bin/activate - source ./env/bin/activate - set -ev - git checkout "$base_branch_pre"/"$base_branch" - mkdir "$base_meta_path" - for mod in "$changed_module_list" - do - echo changed module: "${mod}" - azdev extension add "${mod}" && azdev command-change meta-export "${mod}" --meta-output-path ./"$base_meta_path"/ && azdev extension remove "${mod}" - done - git checkout "$diff_branch" - mkdir "$diff_meta_path" - for mod in "$changed_module_list" - do - echo changed module: "${mod}" - azdev extension add "${mod}" && azdev command-change meta-export "${mod}" --meta-output-path ./"$diff_meta_path"/ && azdev extension remove "${mod}" - done - ls ./"$base_meta_path"/ - ls ./"$diff_meta_path"/ - git checkout "$base_branch_pre"/"$base_branch" - python scripts/ci/release_version_cal.py - # echo "commit_message=$(cat $output_file)" >> $GITHUB_ENV + chmod +x env/bin/activate + source ./env/bin/activate + set -ev + git checkout "$base_branch_pre"/"$base_branch" + mkdir "$base_meta_path" + for mod in "$changed_module_list" + do + echo changed module: "${mod}" + azdev extension add "${mod}" && azdev command-change meta-export "${mod}" --meta-output-path ./"$base_meta_path"/ && azdev extension remove "${mod}" + done + git checkout "$diff_branch" + mkdir "$diff_meta_path" + for mod in "$changed_module_list" + do + echo changed module: "${mod}" + azdev extension add "${mod}" && azdev command-change meta-export "${mod}" --meta-output-path ./"$diff_meta_path"/ && azdev extension remove "${mod}" + done + ls ./"$base_meta_path"/ + ls ./"$diff_meta_path"/ + ls "$result_path" + git checkout "$base_branch_pre"/"$base_branch" + python scripts/ci/release_version_cal.py + ls "$result_path" + cat "$result_path"/"$remove_labels_file" + # echo "commit_message=$(cat $output_file)" >> $GITHUB_ENV + - name: Archive pr version cal output + uses: actions/upload-artifact@v4 + with: + name: version-cal-output + path: | + cal_result + !cal_result/**/*.md + version-output: + needs: version-cal + runs-on: ubuntu-latest + permissions: + pull-requests: write + contents: read + steps: + - name: Check Init GH Event + env: + action: ${{ toJSON(github.event.action) }} + label: ${{ toJSON(github.event.label) }} + run: | + echo version output job start + - name: Download version cal result + uses: actions/download-artifact@v4 + with: + name: version-cal-output + - name: Show work directory after result downloaded + run: | + pwd + ls + - name: Check comment file existence + id: check_comment_file + uses: andstor/file-existence-action@v3 + with: + files: "./version_update.txt" - name: Comment on the pull request + if: steps.check_comment_file.outputs.files_exists == 'true' uses: mshick/add-pr-comment@v2 with: - repo-token: ${{ secrets.GITHUB_TOKEN }} - message-id: versioncommentbot - message-path: | + repo-token: ${{ secrets.GITHUB_TOKEN }} + message-id: versioncommentbot + message-path: | version_update.txt - message-failure: | + message-failure: | Please refer to [Extension version schema](https://github.com/Azure/azure-cli/blob/release/doc/extensions/versioning_guidelines.md) to update release versions. + - name: Check add label file existence + id: check_add_label_file + uses: andstor/file-existence-action@v3 + with: + files: "./labels_added.json" - name: Add block release label - uses: actions-ecosystem/action-add-labels@v1 - if: ${{ steps.get_comment_message.outputs.BlockPR == 1 }} + if: steps.check_add_label_file.outputs.files_exists == 'true' + run: | + cat labels_added.json + curl -X POST \ + "https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/labels" \ + -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ + -d @labels_added.json + - name: Check delete label file existence + id: check_delete_label_file + uses: andstor/file-existence-action@v3 with: - labels: release-version-block + files: "./labels_removed.txt" - name: Remove block release label - uses: mondeja/remove-labels-gh-action@v2 - if: ${{ steps.get_comment_message.outputs.BlockPR == 0 }} - with: - token: ${{ secrets.GITHUB_TOKEN }} - labels: release-version-block \ No newline at end of file + if: steps.check_delete_label_file.outputs.files_exists == 'true' + run: | + for del_lab in `sed 's/[^a-zA-Z0-9_ \-]//g' labels_removed.txt | sort | uniq | xargs` + do + curl -X DELETE \ + "https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/labels/${del_lab}" \ + -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" + done \ No newline at end of file diff --git a/scripts/ci/release_version_cal.py b/scripts/ci/release_version_cal.py index fc3cc4a0f19..65179a378e6 100644 --- a/scripts/ci/release_version_cal.py +++ b/scripts/ci/release_version_cal.py @@ -18,7 +18,10 @@ base_meta_path = os.environ.get('base_meta_path', None) diff_meta_path = os.environ.get('diff_meta_path', None) +result_path = os.environ.get('result_path', None) output_file = os.environ.get('output_file', None) +add_labels_file = os.environ.get('add_labels_file', None) +remove_labels_file = os.environ.get('remove_labels_file', None) changed_module_list = os.environ.get('changed_module_list', "").split() diff_code_file = os.environ.get('diff_code_file', "") @@ -28,6 +31,7 @@ DEFAULT_VERSION = "0.0.0" INIT_RELEASE_VERSION = "1.0.0b1" +DEFAULT_MESSAGE = " - For more info about extension versioning, please refer to [Extension version schema](https://github.com/Azure/azure-cli/blob/release/doc/extensions/versioning_guidelines.md)" block_pr = 0 cli_ext_path = get_ext_repo_paths()[0] @@ -292,18 +296,31 @@ def add_label_hint_message(comment_message): comment_message.append(" - Major/minor/patch/pre increment of version number is calculated by pull request " "code changes automatically. " "If needed, please add `major`/`minor`/`patch`/`pre` label to adjust it.") - comment_message.append(" - For more info about extension versioning, please refer to [Extension version schema](https://github.com/Azure/azure-cli/blob/release/doc/extensions/versioning_guidelines.md)") + comment_message.append(DEFAULT_MESSAGE) -def save_comment_message(file_name, comment_message): - with open(os.path.join(cli_ext_path, file_name), "w") as f: +def save_comment_message(comment_message): + with open(result_path + "/" + output_file, "w") as f: for line in comment_message: f.write(line + "\n") -def save_gh_output(): +def save_label_output(): with open(os.environ['GITHUB_OUTPUT'], 'a') as fh: print(f'BlockPR={block_pr}', file=fh) + add_label_dict = { + "labels": ["release-version-block"] + } + removed_label = "release-version-block" + if block_pr == 0: + with open(result_path + "/" + remove_labels_file, "w") as f: + f.write(removed_label + "\n") + else: + # add block label and empty release label file + with open(result_path + "/" + add_labels_file, "w") as f: + json.dump(add_label_dict, f) + with open(result_path + "/" + remove_labels_file, "w") as f: + pass def main(): @@ -316,15 +333,15 @@ def main(): comment_message = [] modules_update_info = {} if len(changed_module_list) == 0: - comment_message.append("For more info about extension versioning, please refer to [Extension version schema](https://github.com/Azure/azure-cli/blob/release/doc/extensions/versioning_guidelines.md)") - save_comment_message(output_file, comment_message) - save_gh_output() + comment_message.append(DEFAULT_MESSAGE) + save_comment_message(comment_message) + save_label_output() return fill_module_update_info(modules_update_info) if len(modules_update_info) == 0: - comment_message.append("For more info about extension versioning, please refer to [Extension version schema](https://github.com/Azure/azure-cli/blob/release/doc/extensions/versioning_guidelines.md)") - save_comment_message(output_file, comment_message) - save_gh_output() + comment_message.append(DEFAULT_MESSAGE) + save_comment_message(comment_message) + save_label_output() return for mod, update_info in modules_update_info.items(): gen_comment_message(mod, update_info, comment_message) @@ -332,12 +349,12 @@ def main(): add_suggest_header(comment_message) add_label_hint_message(comment_message) else: - comment_message.append("For more info about extension versioning, please refer to [Extension version schema](https://github.com/Azure/azure-cli/blob/release/doc/extensions/versioning_guidelines.md)") + comment_message.append(DEFAULT_MESSAGE) print("comment_message:") print(comment_message) print("block_pr:", block_pr) - save_comment_message(output_file, comment_message) - save_gh_output() + save_comment_message(comment_message) + save_label_output() if __name__ == '__main__':