From c98b8b26ce0c316596309183134d1a331e4ae236 Mon Sep 17 00:00:00 2001 From: klmcadams <58492561+klmcadams@users.noreply.github.com> Date: Fri, 5 Jul 2024 09:04:22 -0400 Subject: [PATCH 01/51] test conventional commits --- doc-changelog/action.yml | 279 ++++++++++++++++++++++----------------- 1 file changed, 160 insertions(+), 119 deletions(-) diff --git a/doc-changelog/action.yml b/doc-changelog/action.yml index 2173c398c..6a185d800 100644 --- a/doc-changelog/action.yml +++ b/doc-changelog/action.yml @@ -65,6 +65,14 @@ inputs: default: true type: boolean + use-labels: + description: > + Whether to use labels to categorize towncrier fragments or conventional + commits. + required: false + default: false + type: boolean + runs: using: "composite" steps: @@ -91,126 +99,159 @@ runs: run: | python -m pip install --upgrade pip towncrier==${{ inputs.towncrier-version }} - - name: "Get labels in the pull request" - env: - OWNER: ${{ github.repository_owner }} - REPO_NAME: ${{ github.event.repository.name }} - PR_NUMBER: ${{ github.event.number }} - GH_TOKEN: ${{ inputs.token }} - shell: bash - run: | - # Get the labels in the pull request - pr_labels=$(gh api repos/${{ env.OWNER }}/${{ env.REPO_NAME }}/pulls/${{ env.PR_NUMBER }} --jq '.labels.[].name') - - # Save the labels to an environment variable - # For example, LABELS="enhancement maintenance" - echo LABELS='"'$pr_labels'"' >> $GITHUB_ENV - - - name: "Set PR label environment variable" - shell: python - run: | - import os - - # Create a list of labels found in the pull request - # For example, "enhancement maintenance".split() -> ["enhancement", "maintenance"] - existing_labels = ${{ env.LABELS }}.split() - - # Dictionary with the key as a label from .github/workflows/label.yml and - # value as the corresponding section in the changelog - pr_labels = { - "enhancement": "added", - "bug": "fixed", - "dependencies": "dependencies", - "maintenance": "changed" - } - - def get_changelog_section(pr_labels, existing_labels): - """Find the changelog section corresponding to the label in the PR.""" - label_type = "" - - for key, value in pr_labels.items(): - if key in existing_labels: - label_type = value - return label_type - - # If no labels are in the PR, it goes into the miscellaneous category - label_type = "miscellaneous" - return label_type - - # Get the GITHUB_ENV variable - github_env = os.getenv('GITHUB_ENV') - - # Append the PR_LABEL with its value to GITHUB_ENV - # For example, PR_LABEL="added" if the PR had an "enhancement" label - with open(github_env, "a") as f: - f.write(f"PR_LABEL={get_changelog_section(pr_labels, existing_labels)}") - - - name: "Remove PR fragment file if it already exists" - env: - PR_NUMBER: ${{ github.event.number }} - shell: bash - run: | - # Find files containing the PR number - # For example, 20.*.md - file=`find . -type f -name "${{ env.PR_NUMBER }}.*.md"` - - # If the fragment file exists, then delete the file - if [ ! -z "$file" ]; then - echo "Removing $file" - rm $file - fi + # - name: "Run commit style checks" + # if: ${{ inputs.use-labels == 'false' }} + # uses: ansys/actions/commit-style@v6 + # with: + # token: ${{ inputs.token }} - - name: "Clean PR title" + - name: "Check pull-request title follows conventional commits style" + if: ${{ inputs.use-labels == 'false' && ((github.event_name == 'pull_request_target') || (github.event_name == 'pull_request')) }} + uses: amannn/action-semantic-pull-request@v5 env: - PR_TITLE: ${{ github.event.pull_request.title }} - shell: python - run: | - import os - - # Retrieve title - clean_title = os.getenv('PR_TITLE') - - # Remove extra whitespace - clean_title = clean_title.strip() - - # Add backslash in front of backtick and double quote - clean_title = clean_title.replace("`", "\`").replace('"', '\\"') + GITHUB_TOKEN: ${{ inputs.token }} - # Get the GITHUB_ENV variable - github_env = os.getenv('GITHUB_ENV') - - # Append the CLEAN_TITLE with its value to GITHUB_ENV - with open(github_env, "a") as f: - f.write(f"CLEAN_TITLE={clean_title}") - - - name: "Create and commit towncrier fragment" + - name: "Check pull-request title follows conventional commits style with upper case" + if: ${{ inputs.use-labels == 'false' && ((github.event_name == 'pull_request_target') || (github.event_name == 'pull_request')) && failure() }} + uses: amannn/action-semantic-pull-request@v5 env: - PR_BRANCH: ${{ github.event.pull_request.head.ref }} - PR_NUMBER: ${{ github.event.number }} - shell: bash - run: | - # Changelog fragment file in the following format - # For example, 20.added.md - fragment="${{ env.PR_NUMBER }}.${{ env.PR_LABEL }}.md" - - # Create changelog fragment with towncrier - # Fragment file contains the title of the PR - towncrier create -c "${{ env.CLEAN_TITLE }}" $fragment - - # Configure git username & email - git config user.name 'pyansys-ci-bot' - git config user.email '92810346+pyansys-ci-bot@users.noreply.github.com' - - # Add towncrier fragment - git add . - - # Check if file was modified - modified=`git diff HEAD --name-only` - - # If the file was modified, commit & push it to the branch - if [ ! -z "$modified" ]; then - echo "modified: $modified" - # Commit and push fragment - git commit -m "chore: adding changelog file $fragment" - git push - fi + GITHUB_TOKEN: ${{ inputs.token }} + with: + types: | + BUILD + CHORE + CI + DOCS + FEAT + FIX + PERF + REFACTOR + REVERT + STYLE + TEST + + # - name: "Get labels in the pull request" + # if: ${{ inputs.use-labels == 'true' }} + # env: + # OWNER: ${{ github.repository_owner }} + # REPO_NAME: ${{ github.event.repository.name }} + # PR_NUMBER: ${{ github.event.number }} + # GH_TOKEN: ${{ inputs.token }} + # shell: bash + # run: | + # # Get the labels in the pull request + # pr_labels=$(gh api repos/${{ env.OWNER }}/${{ env.REPO_NAME }}/pulls/${{ env.PR_NUMBER }} --jq '.labels.[].name') + + # # Save the labels to an environment variable + # # For example, LABELS="enhancement maintenance" + # echo LABELS='"'$pr_labels'"' >> $GITHUB_ENV + + # - name: "Set PR label environment variable" + # if: ${{ inputs.use-labels == 'true' }} + # shell: python + # run: | + # import os + + # # Create a list of labels found in the pull request + # # For example, "enhancement maintenance".split() -> ["enhancement", "maintenance"] + # existing_labels = ${{ env.LABELS }}.split() + + # # Dictionary with the key as a label from .github/workflows/label.yml and + # # value as the corresponding section in the changelog + # pr_labels = { + # "enhancement": "added", + # "bug": "fixed", + # "dependencies": "dependencies", + # "maintenance": "changed" + # } + + # def get_changelog_section(pr_labels, existing_labels): + # """Find the changelog section corresponding to the label in the PR.""" + # label_type = "" + + # for key, value in pr_labels.items(): + # if key in existing_labels: + # label_type = value + # return label_type + + # # If no labels are in the PR, it goes into the miscellaneous category + # label_type = "miscellaneous" + # return label_type + + # # Get the GITHUB_ENV variable + # github_env = os.getenv('GITHUB_ENV') + + # # Append the PR_LABEL with its value to GITHUB_ENV + # # For example, PR_LABEL="added" if the PR had an "enhancement" label + # with open(github_env, "a") as f: + # f.write(f"PR_LABEL={get_changelog_section(pr_labels, existing_labels)}") + + # - name: "Remove PR fragment file if it already exists" + # env: + # PR_NUMBER: ${{ github.event.number }} + # shell: bash + # run: | + # # Find files containing the PR number + # # For example, 20.*.md + # file=`find . -type f -name "${{ env.PR_NUMBER }}.*.md"` + + # # If the fragment file exists, then delete the file + # if [ ! -z "$file" ]; then + # echo "Removing $file" + # rm $file + # fi + + # - name: "Clean PR title" + # env: + # PR_TITLE: ${{ github.event.pull_request.title }} + # shell: python + # run: | + # import os + + # # Retrieve title + # clean_title = os.getenv('PR_TITLE') + + # # Remove extra whitespace + # clean_title = clean_title.strip() + + # # Add backslash in front of backtick and double quote + # clean_title = clean_title.replace("`", "\`").replace('"', '\\"') + + # # Get the GITHUB_ENV variable + # github_env = os.getenv('GITHUB_ENV') + + # # Append the CLEAN_TITLE with its value to GITHUB_ENV + # with open(github_env, "a") as f: + # f.write(f"CLEAN_TITLE={clean_title}") + + # - name: "Create and commit towncrier fragment" + # env: + # PR_BRANCH: ${{ github.event.pull_request.head.ref }} + # PR_NUMBER: ${{ github.event.number }} + # shell: bash + # run: | + # # Changelog fragment file in the following format + # # For example, 20.added.md + # fragment="${{ env.PR_NUMBER }}.${{ env.PR_LABEL }}.md" + + # # Create changelog fragment with towncrier + # # Fragment file contains the title of the PR + # towncrier create -c "${{ env.CLEAN_TITLE }}" $fragment + + # # Configure git username & email + # git config user.name 'pyansys-ci-bot' + # git config user.email '92810346+pyansys-ci-bot@users.noreply.github.com' + + # # Add towncrier fragment + # git add . + + # # Check if file was modified + # modified=`git diff HEAD --name-only` + + # # If the file was modified, commit & push it to the branch + # if [ ! -z "$modified" ]; then + # echo "modified: $modified" + # # Commit and push fragment + # git commit -m "chore: adding changelog file $fragment" + # git push + # fi From 2f30057c12df5a8b473f44d706529befa59a5e05 Mon Sep 17 00:00:00 2001 From: klmcadams <58492561+klmcadams@users.noreply.github.com> Date: Fri, 5 Jul 2024 09:25:52 -0400 Subject: [PATCH 02/51] reorder conventional commit checks --- doc-changelog/action.yml | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/doc-changelog/action.yml b/doc-changelog/action.yml index 6a185d800..7557f45be 100644 --- a/doc-changelog/action.yml +++ b/doc-changelog/action.yml @@ -105,14 +105,8 @@ runs: # with: # token: ${{ inputs.token }} - - name: "Check pull-request title follows conventional commits style" - if: ${{ inputs.use-labels == 'false' && ((github.event_name == 'pull_request_target') || (github.event_name == 'pull_request')) }} - uses: amannn/action-semantic-pull-request@v5 - env: - GITHUB_TOKEN: ${{ inputs.token }} - - name: "Check pull-request title follows conventional commits style with upper case" - if: ${{ inputs.use-labels == 'false' && ((github.event_name == 'pull_request_target') || (github.event_name == 'pull_request')) && failure() }} + if: ${{ inputs.use-labels == 'false' && ((github.event_name == 'pull_request_target') || (github.event_name == 'pull_request')) }} uses: amannn/action-semantic-pull-request@v5 env: GITHUB_TOKEN: ${{ inputs.token }} @@ -129,6 +123,13 @@ runs: REVERT STYLE TEST + continue-on-error: true + + - name: "Check pull-request title follows conventional commits style" + if: ${{ inputs.use-labels == 'false' && ((github.event_name == 'pull_request_target') || (github.event_name == 'pull_request')) && failure() }} + uses: amannn/action-semantic-pull-request@v5 + env: + GITHUB_TOKEN: ${{ inputs.token }} # - name: "Get labels in the pull request" # if: ${{ inputs.use-labels == 'true' }} From 5806c13a754d4c46b37eaf21bd9e355d38d6c080 Mon Sep 17 00:00:00 2001 From: klmcadams <58492561+klmcadams@users.noreply.github.com> Date: Fri, 5 Jul 2024 09:30:32 -0400 Subject: [PATCH 03/51] remove failure condition --- doc-changelog/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc-changelog/action.yml b/doc-changelog/action.yml index 7557f45be..2ca5a93dc 100644 --- a/doc-changelog/action.yml +++ b/doc-changelog/action.yml @@ -126,7 +126,7 @@ runs: continue-on-error: true - name: "Check pull-request title follows conventional commits style" - if: ${{ inputs.use-labels == 'false' && ((github.event_name == 'pull_request_target') || (github.event_name == 'pull_request')) && failure() }} + if: ${{ inputs.use-labels == 'false' && ((github.event_name == 'pull_request_target') || (github.event_name == 'pull_request')) }} uses: amannn/action-semantic-pull-request@v5 env: GITHUB_TOKEN: ${{ inputs.token }} From 6967d44583f4aa6156b1f623e8ed31b32f091668 Mon Sep 17 00:00:00 2001 From: klmcadams <58492561+klmcadams@users.noreply.github.com> Date: Fri, 5 Jul 2024 09:42:39 -0400 Subject: [PATCH 04/51] check outcomes of steps --- doc-changelog/action.yml | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/doc-changelog/action.yml b/doc-changelog/action.yml index 2ca5a93dc..ea2bc4369 100644 --- a/doc-changelog/action.yml +++ b/doc-changelog/action.yml @@ -105,7 +105,16 @@ runs: # with: # token: ${{ inputs.token }} + - name: "Check pull-request title follows conventional commits style" + id: lowercase + if: ${{ inputs.use-labels == 'false' && ((github.event_name == 'pull_request_target') || (github.event_name == 'pull_request')) }} + uses: amannn/action-semantic-pull-request@v5 + env: + GITHUB_TOKEN: ${{ inputs.token }} + continue-on-error: true + - name: "Check pull-request title follows conventional commits style with upper case" + id: caps if: ${{ inputs.use-labels == 'false' && ((github.event_name == 'pull_request_target') || (github.event_name == 'pull_request')) }} uses: amannn/action-semantic-pull-request@v5 env: @@ -125,11 +134,9 @@ runs: TEST continue-on-error: true - - name: "Check pull-request title follows conventional commits style" - if: ${{ inputs.use-labels == 'false' && ((github.event_name == 'pull_request_target') || (github.event_name == 'pull_request')) }} - uses: amannn/action-semantic-pull-request@v5 - env: - GITHUB_TOKEN: ${{ inputs.token }} + - name: "Check failures" + if: steps.lowercase.outcome == 'failure' && steps.caps.outcome == 'failure' + run: exit 1 # - name: "Get labels in the pull request" # if: ${{ inputs.use-labels == 'true' }} From f4feb38b0c13931baa046a214777e7569929cded Mon Sep 17 00:00:00 2001 From: klmcadams <58492561+klmcadams@users.noreply.github.com> Date: Fri, 5 Jul 2024 09:45:20 -0400 Subject: [PATCH 05/51] add shell line --- doc-changelog/action.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/doc-changelog/action.yml b/doc-changelog/action.yml index ea2bc4369..c4234b05d 100644 --- a/doc-changelog/action.yml +++ b/doc-changelog/action.yml @@ -136,8 +136,15 @@ runs: - name: "Check failures" if: steps.lowercase.outcome == 'failure' && steps.caps.outcome == 'failure' + shell: bash run: exit 1 + - name: "Print good statement" + if: ${{ inputs.use-labels == 'true' }} + shell: bash + run: echo "good!" + + # - name: "Get labels in the pull request" # if: ${{ inputs.use-labels == 'true' }} # env: From a4668e367009804d1ec0deb6953edb90c593f4d5 Mon Sep 17 00:00:00 2001 From: klmcadams <58492561+klmcadams@users.noreply.github.com> Date: Fri, 5 Jul 2024 14:09:45 -0400 Subject: [PATCH 06/51] set changelog section based on conventional commit type --- doc-changelog/action.yml | 310 ++++++++++++++++++++++----------------- 1 file changed, 175 insertions(+), 135 deletions(-) diff --git a/doc-changelog/action.yml b/doc-changelog/action.yml index c4234b05d..4d9fea3b5 100644 --- a/doc-changelog/action.yml +++ b/doc-changelog/action.yml @@ -99,12 +99,6 @@ runs: run: | python -m pip install --upgrade pip towncrier==${{ inputs.towncrier-version }} - # - name: "Run commit style checks" - # if: ${{ inputs.use-labels == 'false' }} - # uses: ansys/actions/commit-style@v6 - # with: - # token: ${{ inputs.token }} - - name: "Check pull-request title follows conventional commits style" id: lowercase if: ${{ inputs.use-labels == 'false' && ((github.event_name == 'pull_request_target') || (github.event_name == 'pull_request')) }} @@ -139,134 +133,180 @@ runs: shell: bash run: exit 1 - - name: "Print good statement" + - name: "Get conventional commit type from title" + if: ${{ inputs.use-labels == 'false' }} + env: + PR_TITLE: ${{ github.event.pull_request.title }} + shell: bash + run: | + pr_title=${{ env.PR_TITLE }} + echo "${pr_title%%:*}" + echo CC_TYPE='"${pr_title%%:*}"' >> $GITHUB_ENV + + - name: "Get labels in the pull request" + if: ${{ inputs.use-labels == 'true' }} + env: + OWNER: ${{ github.repository_owner }} + REPO_NAME: ${{ github.event.repository.name }} + PR_NUMBER: ${{ github.event.number }} + GH_TOKEN: ${{ inputs.token }} + shell: bash + run: | + # Get the labels in the pull request + pr_labels=$(gh api repos/${{ env.OWNER }}/${{ env.REPO_NAME }}/pulls/${{ env.PR_NUMBER }} --jq '.labels.[].name') + + # Save the labels to an environment variable + # For example, LABELS="enhancement maintenance" + echo LABELS='"'$pr_labels'"' >> $GITHUB_ENV + + - name: "Set CHANGELOG category based on conventional commit type" + if: ${{ inputs.use-labels == 'false' }} + shell: python + run: | + import os + + # Get conventional commit type from env variable + cc_type = ${{ env.CC_TYPE }} + + cc_type_changelog_dict = { + "feat": "added", + "fix": "fixed", + "revert": "changed", + "style": "changed", + "refactor": "changed", + "test": "tests", + "chore": "changed", + "perf": "changed", + "ci": "changed", + "docs": "documentation" + "build": "dependencies" + } + + changelog_section = cc_type_changelog_dict[cc_type] + + # Get the GITHUB_ENV variable + github_env = os.getenv('GITHUB_ENV') + + # Append the CHANGELOG_SECTION with its value to GITHUB_ENV + # For example, CHANGELOG_SECTION="added" if the conventional commit title was "feat" + with open(github_env, "a") as f: + f.write(f"CHANGELOG_SECTION={changelog_section}") + + - name: "Set PR label environment variable" if: ${{ inputs.use-labels == 'true' }} + shell: python + run: | + import os + + # Create a list of labels found in the pull request + # For example, "enhancement maintenance".split() -> ["enhancement", "maintenance"] + existing_labels = ${{ env.LABELS }}.split() + + # Dictionary with the key as a label from .github/workflows/label.yml and + # value as the corresponding section in the changelog + pr_labels = { + "enhancement": "added", + "bug": "fixed", + "documentation": "documentation", + "tests": "tests", + "dependencies": "dependencies", + "maintenance": "changed" + } + + def get_changelog_section(pr_labels, existing_labels): + """Find the changelog section corresponding to the label in the PR.""" + label_type = "" + + for key, value in pr_labels.items(): + if key in existing_labels: + label_type = value + return label_type + + # If no labels are in the PR, it goes into the miscellaneous category + label_type = "miscellaneous" + return label_type + + # Get the GITHUB_ENV variable + github_env = os.getenv('GITHUB_ENV') + + # Append the CHANGELOG_SECTION with its value to GITHUB_ENV + # For example, CHANGELOG_SECTION="added" if the PR had an "enhancement" label + with open(github_env, "a") as f: + f.write(f"CHANGELOG_SECTION={get_changelog_section(pr_labels, existing_labels)}") + + - name: "Remove PR fragment file if it already exists" + env: + PR_NUMBER: ${{ github.event.number }} shell: bash - run: echo "good!" - - - # - name: "Get labels in the pull request" - # if: ${{ inputs.use-labels == 'true' }} - # env: - # OWNER: ${{ github.repository_owner }} - # REPO_NAME: ${{ github.event.repository.name }} - # PR_NUMBER: ${{ github.event.number }} - # GH_TOKEN: ${{ inputs.token }} - # shell: bash - # run: | - # # Get the labels in the pull request - # pr_labels=$(gh api repos/${{ env.OWNER }}/${{ env.REPO_NAME }}/pulls/${{ env.PR_NUMBER }} --jq '.labels.[].name') - - # # Save the labels to an environment variable - # # For example, LABELS="enhancement maintenance" - # echo LABELS='"'$pr_labels'"' >> $GITHUB_ENV - - # - name: "Set PR label environment variable" - # if: ${{ inputs.use-labels == 'true' }} - # shell: python - # run: | - # import os - - # # Create a list of labels found in the pull request - # # For example, "enhancement maintenance".split() -> ["enhancement", "maintenance"] - # existing_labels = ${{ env.LABELS }}.split() - - # # Dictionary with the key as a label from .github/workflows/label.yml and - # # value as the corresponding section in the changelog - # pr_labels = { - # "enhancement": "added", - # "bug": "fixed", - # "dependencies": "dependencies", - # "maintenance": "changed" - # } - - # def get_changelog_section(pr_labels, existing_labels): - # """Find the changelog section corresponding to the label in the PR.""" - # label_type = "" - - # for key, value in pr_labels.items(): - # if key in existing_labels: - # label_type = value - # return label_type - - # # If no labels are in the PR, it goes into the miscellaneous category - # label_type = "miscellaneous" - # return label_type - - # # Get the GITHUB_ENV variable - # github_env = os.getenv('GITHUB_ENV') - - # # Append the PR_LABEL with its value to GITHUB_ENV - # # For example, PR_LABEL="added" if the PR had an "enhancement" label - # with open(github_env, "a") as f: - # f.write(f"PR_LABEL={get_changelog_section(pr_labels, existing_labels)}") - - # - name: "Remove PR fragment file if it already exists" - # env: - # PR_NUMBER: ${{ github.event.number }} - # shell: bash - # run: | - # # Find files containing the PR number - # # For example, 20.*.md - # file=`find . -type f -name "${{ env.PR_NUMBER }}.*.md"` - - # # If the fragment file exists, then delete the file - # if [ ! -z "$file" ]; then - # echo "Removing $file" - # rm $file - # fi - - # - name: "Clean PR title" - # env: - # PR_TITLE: ${{ github.event.pull_request.title }} - # shell: python - # run: | - # import os - - # # Retrieve title - # clean_title = os.getenv('PR_TITLE') - - # # Remove extra whitespace - # clean_title = clean_title.strip() - - # # Add backslash in front of backtick and double quote - # clean_title = clean_title.replace("`", "\`").replace('"', '\\"') - - # # Get the GITHUB_ENV variable - # github_env = os.getenv('GITHUB_ENV') - - # # Append the CLEAN_TITLE with its value to GITHUB_ENV - # with open(github_env, "a") as f: - # f.write(f"CLEAN_TITLE={clean_title}") - - # - name: "Create and commit towncrier fragment" - # env: - # PR_BRANCH: ${{ github.event.pull_request.head.ref }} - # PR_NUMBER: ${{ github.event.number }} - # shell: bash - # run: | - # # Changelog fragment file in the following format - # # For example, 20.added.md - # fragment="${{ env.PR_NUMBER }}.${{ env.PR_LABEL }}.md" - - # # Create changelog fragment with towncrier - # # Fragment file contains the title of the PR - # towncrier create -c "${{ env.CLEAN_TITLE }}" $fragment - - # # Configure git username & email - # git config user.name 'pyansys-ci-bot' - # git config user.email '92810346+pyansys-ci-bot@users.noreply.github.com' - - # # Add towncrier fragment - # git add . - - # # Check if file was modified - # modified=`git diff HEAD --name-only` - - # # If the file was modified, commit & push it to the branch - # if [ ! -z "$modified" ]; then - # echo "modified: $modified" - # # Commit and push fragment - # git commit -m "chore: adding changelog file $fragment" - # git push - # fi + run: | + # Find files containing the PR number + # For example, 20.*.md + file=`find . -type f -name "${{ env.PR_NUMBER }}.*.md"` + + # If the fragment file exists, then delete the file + if [ ! -z "$file" ]; then + echo "Removing $file" + rm $file + fi + + - name: "Clean PR title" + env: + PR_TITLE: ${{ github.event.pull_request.title }} + shell: python + run: | + import os + + # Retrieve title + clean_title = os.getenv('PR_TITLE') + + # If not using label, remove conventional commit type from title + if not ${{ inputs.use-labels }}: + colon_index = clean_title.index(":") + clean_title = clean_title[4:] + + print(clean_title) + + # Remove extra whitespace + clean_title = clean_title.strip() + + # Add backslash in front of backtick and double quote + clean_title = clean_title.replace("`", "\`").replace('"', '\\"') + + # Get the GITHUB_ENV variable + github_env = os.getenv('GITHUB_ENV') + + # Append the CLEAN_TITLE with its value to GITHUB_ENV + with open(github_env, "a") as f: + f.write(f"CLEAN_TITLE={clean_title}") + + - name: "Create and commit towncrier fragment" + env: + PR_BRANCH: ${{ github.event.pull_request.head.ref }} + PR_NUMBER: ${{ github.event.number }} + shell: bash + run: | + # Changelog fragment file in the following format + # For example, 20.added.md + fragment="${{ env.PR_NUMBER }}.${{ env.CHANGELOG_SECTION }}.md" + + # Create changelog fragment with towncrier + # Fragment file contains the title of the PR + towncrier create -c "${{ env.CLEAN_TITLE }}" $fragment + + # Configure git username & email + git config user.name 'pyansys-ci-bot' + git config user.email '92810346+pyansys-ci-bot@users.noreply.github.com' + + # Add towncrier fragment + git add . + + # Check if file was modified + modified=`git diff HEAD --name-only` + + # If the file was modified, commit & push it to the branch + if [ ! -z "$modified" ]; then + echo "modified: $modified" + # Commit and push fragment + git commit -m "chore: adding changelog file $fragment" + git push + fi From 54b3befca0dbadc71501cbc52c06da0c2bf18aea Mon Sep 17 00:00:00 2001 From: klmcadams <58492561+klmcadams@users.noreply.github.com> Date: Fri, 5 Jul 2024 14:15:57 -0400 Subject: [PATCH 07/51] add quotes around pr_title --- doc-changelog/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc-changelog/action.yml b/doc-changelog/action.yml index 4d9fea3b5..5393ad93f 100644 --- a/doc-changelog/action.yml +++ b/doc-changelog/action.yml @@ -139,7 +139,7 @@ runs: PR_TITLE: ${{ github.event.pull_request.title }} shell: bash run: | - pr_title=${{ env.PR_TITLE }} + pr_title="${{ env.PR_TITLE }}" echo "${pr_title%%:*}" echo CC_TYPE='"${pr_title%%:*}"' >> $GITHUB_ENV From 05c6fe7184b37daca7f9ef9493a3109113fb94ee Mon Sep 17 00:00:00 2001 From: klmcadams <58492561+klmcadams@users.noreply.github.com> Date: Fri, 5 Jul 2024 14:18:52 -0400 Subject: [PATCH 08/51] add print statements, fix syntax, and make cc_type lowercase --- doc-changelog/action.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/doc-changelog/action.yml b/doc-changelog/action.yml index 5393ad93f..ff7aad5e9 100644 --- a/doc-changelog/action.yml +++ b/doc-changelog/action.yml @@ -166,7 +166,9 @@ runs: import os # Get conventional commit type from env variable - cc_type = ${{ env.CC_TYPE }} + cc_type = "${{ env.CC_TYPE }}".lower() + + print(cc_type) cc_type_changelog_dict = { "feat": "added", @@ -178,8 +180,8 @@ runs: "chore": "changed", "perf": "changed", "ci": "changed", - "docs": "documentation" - "build": "dependencies" + "docs": "documentation", + "build": "dependencies", } changelog_section = cc_type_changelog_dict[cc_type] From 184952d66ceeb6b517a68bf427948e7970765e12 Mon Sep 17 00:00:00 2001 From: klmcadams <58492561+klmcadams@users.noreply.github.com> Date: Fri, 5 Jul 2024 14:21:57 -0400 Subject: [PATCH 09/51] fix cc_type? --- doc-changelog/action.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc-changelog/action.yml b/doc-changelog/action.yml index ff7aad5e9..5faf68d74 100644 --- a/doc-changelog/action.yml +++ b/doc-changelog/action.yml @@ -140,8 +140,8 @@ runs: shell: bash run: | pr_title="${{ env.PR_TITLE }}" - echo "${pr_title%%:*}" - echo CC_TYPE='"${pr_title%%:*}"' >> $GITHUB_ENV + cc_type="${pr_title%%:*}" + echo CC_TYPE=$cc_type >> $GITHUB_ENV - name: "Get labels in the pull request" if: ${{ inputs.use-labels == 'true' }} @@ -166,7 +166,7 @@ runs: import os # Get conventional commit type from env variable - cc_type = "${{ env.CC_TYPE }}".lower() + cc_type = ${{ env.CC_TYPE }}.lower() print(cc_type) From ece8be86bbc9c3842086d4046decac71b2629c2c Mon Sep 17 00:00:00 2001 From: klmcadams <58492561+klmcadams@users.noreply.github.com> Date: Fri, 5 Jul 2024 14:23:28 -0400 Subject: [PATCH 10/51] double quotes around cc_type env var --- doc-changelog/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc-changelog/action.yml b/doc-changelog/action.yml index 5faf68d74..cc91045ea 100644 --- a/doc-changelog/action.yml +++ b/doc-changelog/action.yml @@ -141,7 +141,7 @@ runs: run: | pr_title="${{ env.PR_TITLE }}" cc_type="${pr_title%%:*}" - echo CC_TYPE=$cc_type >> $GITHUB_ENV + echo CC_TYPE='"$cc_type"' >> $GITHUB_ENV - name: "Get labels in the pull request" if: ${{ inputs.use-labels == 'true' }} From a54e98c68c38954ff806bb80feb7742b32f00784 Mon Sep 17 00:00:00 2001 From: klmcadams <58492561+klmcadams@users.noreply.github.com> Date: Fri, 5 Jul 2024 14:24:36 -0400 Subject: [PATCH 11/51] fix quotes --- doc-changelog/action.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc-changelog/action.yml b/doc-changelog/action.yml index cc91045ea..b911eac35 100644 --- a/doc-changelog/action.yml +++ b/doc-changelog/action.yml @@ -141,7 +141,7 @@ runs: run: | pr_title="${{ env.PR_TITLE }}" cc_type="${pr_title%%:*}" - echo CC_TYPE='"$cc_type"' >> $GITHUB_ENV + echo CC_TYPE=$cc_type >> $GITHUB_ENV - name: "Get labels in the pull request" if: ${{ inputs.use-labels == 'true' }} @@ -166,7 +166,7 @@ runs: import os # Get conventional commit type from env variable - cc_type = ${{ env.CC_TYPE }}.lower() + cc_type = "${{ env.CC_TYPE }}".lower() print(cc_type) From 026b5b856a8589fa12cfec96cb79c64847049108 Mon Sep 17 00:00:00 2001 From: klmcadams <58492561+klmcadams@users.noreply.github.com> Date: Fri, 5 Jul 2024 14:29:42 -0400 Subject: [PATCH 12/51] fix boolean --- doc-changelog/action.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/doc-changelog/action.yml b/doc-changelog/action.yml index b911eac35..e053a7686 100644 --- a/doc-changelog/action.yml +++ b/doc-changelog/action.yml @@ -261,8 +261,14 @@ runs: # Retrieve title clean_title = os.getenv('PR_TITLE') + # Retrieve use-labels boolean + use_labels = "${{ inputs.use-labels }}" + + # Capitalize first letter of string, so it becomes True or False + use_labels = use_labels[0].upper() + use_labels[1:] + # If not using label, remove conventional commit type from title - if not ${{ inputs.use-labels }}: + if not use_labels: colon_index = clean_title.index(":") clean_title = clean_title[4:] From eed2cb3a9dedfa5551f3f203a383327c14099868 Mon Sep 17 00:00:00 2001 From: klmcadams <58492561+klmcadams@users.noreply.github.com> Date: Fri, 5 Jul 2024 14:47:31 -0400 Subject: [PATCH 13/51] move quotes --- doc-changelog/action.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc-changelog/action.yml b/doc-changelog/action.yml index e053a7686..0ea8ef9fb 100644 --- a/doc-changelog/action.yml +++ b/doc-changelog/action.yml @@ -141,7 +141,7 @@ runs: run: | pr_title="${{ env.PR_TITLE }}" cc_type="${pr_title%%:*}" - echo CC_TYPE=$cc_type >> $GITHUB_ENV + echo CC_TYPE='"'$cc_type'"' >> $GITHUB_ENV - name: "Get labels in the pull request" if: ${{ inputs.use-labels == 'true' }} @@ -166,7 +166,7 @@ runs: import os # Get conventional commit type from env variable - cc_type = "${{ env.CC_TYPE }}".lower() + cc_type = ${{ env.CC_TYPE }}.lower() print(cc_type) From 58f8eaaf77548f9b517129fc6e26d92ae2278984 Mon Sep 17 00:00:00 2001 From: klmcadams <58492561+klmcadams@users.noreply.github.com> Date: Fri, 5 Jul 2024 14:57:24 -0400 Subject: [PATCH 14/51] call env var directly --- doc-changelog/action.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc-changelog/action.yml b/doc-changelog/action.yml index 0ea8ef9fb..a0e738c48 100644 --- a/doc-changelog/action.yml +++ b/doc-changelog/action.yml @@ -139,8 +139,8 @@ runs: PR_TITLE: ${{ github.event.pull_request.title }} shell: bash run: | - pr_title="${{ env.PR_TITLE }}" - cc_type="${pr_title%%:*}" + # pr_title=${{ env.PR_TITLE }} + cc_type="${env.PR_TITLE%%:*}" echo CC_TYPE='"'$cc_type'"' >> $GITHUB_ENV - name: "Get labels in the pull request" From 101b42c193e8cffb40e5efa23b6992deda1fca76 Mon Sep 17 00:00:00 2001 From: klmcadams <58492561+klmcadams@users.noreply.github.com> Date: Fri, 5 Jul 2024 14:58:20 -0400 Subject: [PATCH 15/51] double curly brackets --- doc-changelog/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc-changelog/action.yml b/doc-changelog/action.yml index a0e738c48..84b93125c 100644 --- a/doc-changelog/action.yml +++ b/doc-changelog/action.yml @@ -140,7 +140,7 @@ runs: shell: bash run: | # pr_title=${{ env.PR_TITLE }} - cc_type="${env.PR_TITLE%%:*}" + cc_type="${{env.PR_TITLE%%:*}}" echo CC_TYPE='"'$cc_type'"' >> $GITHUB_ENV - name: "Get labels in the pull request" From 3e3b9e9a91f3a93c355737e889a182c5e015cf3c Mon Sep 17 00:00:00 2001 From: klmcadams <58492561+klmcadams@users.noreply.github.com> Date: Fri, 5 Jul 2024 15:12:26 -0400 Subject: [PATCH 16/51] test --- doc-changelog/action.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/doc-changelog/action.yml b/doc-changelog/action.yml index 84b93125c..bdec74493 100644 --- a/doc-changelog/action.yml +++ b/doc-changelog/action.yml @@ -139,8 +139,9 @@ runs: PR_TITLE: ${{ github.event.pull_request.title }} shell: bash run: | - # pr_title=${{ env.PR_TITLE }} - cc_type="${{env.PR_TITLE%%:*}}" + pr_title=${{ env.PR_TITLE }} + cc_type="${ ${{ env.PR_TITLE }}%%:* }" + # "${pr_title%%:*}" echo CC_TYPE='"'$cc_type'"' >> $GITHUB_ENV - name: "Get labels in the pull request" From c9032c01718a199e23074b9083e8fa785e2acbc0 Mon Sep 17 00:00:00 2001 From: klmcadams <58492561+klmcadams@users.noreply.github.com> Date: Fri, 5 Jul 2024 15:17:30 -0400 Subject: [PATCH 17/51] use cut command instead --- doc-changelog/action.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/doc-changelog/action.yml b/doc-changelog/action.yml index bdec74493..335b74184 100644 --- a/doc-changelog/action.yml +++ b/doc-changelog/action.yml @@ -140,8 +140,7 @@ runs: shell: bash run: | pr_title=${{ env.PR_TITLE }} - cc_type="${ ${{ env.PR_TITLE }}%%:* }" - # "${pr_title%%:*}" + cc_type=$(echo $pr_title | cut -d: -f1) echo CC_TYPE='"'$cc_type'"' >> $GITHUB_ENV - name: "Get labels in the pull request" From 3283fd17e5646f94cbac5905452768798caae943 Mon Sep 17 00:00:00 2001 From: klmcadams <58492561+klmcadams@users.noreply.github.com> Date: Fri, 5 Jul 2024 15:18:56 -0400 Subject: [PATCH 18/51] pr title directly in bash --- doc-changelog/action.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/doc-changelog/action.yml b/doc-changelog/action.yml index 335b74184..3dc934cad 100644 --- a/doc-changelog/action.yml +++ b/doc-changelog/action.yml @@ -139,8 +139,7 @@ runs: PR_TITLE: ${{ github.event.pull_request.title }} shell: bash run: | - pr_title=${{ env.PR_TITLE }} - cc_type=$(echo $pr_title | cut -d: -f1) + cc_type=$(echo ${{ env.PR_TITLE }} | cut -d: -f1) echo CC_TYPE='"'$cc_type'"' >> $GITHUB_ENV - name: "Get labels in the pull request" From 9c497e7ab6fe14e8aeda076f96d5d8aadea3605b Mon Sep 17 00:00:00 2001 From: klmcadams <58492561+klmcadams@users.noreply.github.com> Date: Fri, 5 Jul 2024 15:39:08 -0400 Subject: [PATCH 19/51] change bash to python for the env step --- doc-changelog/action.yml | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/doc-changelog/action.yml b/doc-changelog/action.yml index 3dc934cad..3d58ca96b 100644 --- a/doc-changelog/action.yml +++ b/doc-changelog/action.yml @@ -137,10 +137,20 @@ runs: if: ${{ inputs.use-labels == 'false' }} env: PR_TITLE: ${{ github.event.pull_request.title }} - shell: bash + shell: python run: | - cc_type=$(echo ${{ env.PR_TITLE }} | cut -d: -f1) - echo CC_TYPE='"'$cc_type'"' >> $GITHUB_ENV + import os + + pr_title = f"""{os.environ.get('PR_TITLE')}""" + colon_index = pr_title.index(":") + cc_type = pr_title[:4] + print(cc_type) + + # Get the GITHUB_ENV variable + github_env = os.getenv('GITHUB_ENV') + + with open(github_env, "a") as f: + f.write(f"CC_TYPE={cc_type}") - name: "Get labels in the pull request" if: ${{ inputs.use-labels == 'true' }} From 98f412add0fdaf15c75e1882527bd5bc968210e8 Mon Sep 17 00:00:00 2001 From: klmcadams <58492561+klmcadams@users.noreply.github.com> Date: Fri, 5 Jul 2024 15:41:06 -0400 Subject: [PATCH 20/51] change to colon_index --- doc-changelog/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc-changelog/action.yml b/doc-changelog/action.yml index 3d58ca96b..23121f1bb 100644 --- a/doc-changelog/action.yml +++ b/doc-changelog/action.yml @@ -143,7 +143,7 @@ runs: pr_title = f"""{os.environ.get('PR_TITLE')}""" colon_index = pr_title.index(":") - cc_type = pr_title[:4] + cc_type = pr_title[:colon_index] print(cc_type) # Get the GITHUB_ENV variable From 760cc02ef975140e06d723fd814ba84c02b0a3fe Mon Sep 17 00:00:00 2001 From: klmcadams <58492561+klmcadams@users.noreply.github.com> Date: Fri, 5 Jul 2024 15:44:24 -0400 Subject: [PATCH 21/51] wrap in double quotes --- doc-changelog/action.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/doc-changelog/action.yml b/doc-changelog/action.yml index 23121f1bb..3efa07d4c 100644 --- a/doc-changelog/action.yml +++ b/doc-changelog/action.yml @@ -143,14 +143,13 @@ runs: pr_title = f"""{os.environ.get('PR_TITLE')}""" colon_index = pr_title.index(":") - cc_type = pr_title[:colon_index] - print(cc_type) + cc_type = '"'+pr_title[:colon_index]+'"' # Get the GITHUB_ENV variable github_env = os.getenv('GITHUB_ENV') with open(github_env, "a") as f: - f.write(f"CC_TYPE={cc_type}") + f.write(f'CC_TYPE={cc_type}') - name: "Get labels in the pull request" if: ${{ inputs.use-labels == 'true' }} From c077b264ec243a22a7f8d8906d8c7ef01557de49 Mon Sep 17 00:00:00 2001 From: klmcadams <58492561+klmcadams@users.noreply.github.com> Date: Fri, 5 Jul 2024 15:48:47 -0400 Subject: [PATCH 22/51] wrap string in bool --- doc-changelog/action.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/doc-changelog/action.yml b/doc-changelog/action.yml index 3efa07d4c..103db30b7 100644 --- a/doc-changelog/action.yml +++ b/doc-changelog/action.yml @@ -273,7 +273,9 @@ runs: use_labels = "${{ inputs.use-labels }}" # Capitalize first letter of string, so it becomes True or False - use_labels = use_labels[0].upper() + use_labels[1:] + use_labels = bool(use_labels[0].upper() + use_labels[1:]) + + print(use_labels) # If not using label, remove conventional commit type from title if not use_labels: From 6539c903b5e9b6911d2d501c2b8cdd044525263a Mon Sep 17 00:00:00 2001 From: klmcadams <58492561+klmcadams@users.noreply.github.com> Date: Fri, 5 Jul 2024 15:53:14 -0400 Subject: [PATCH 23/51] use colon_index --- doc-changelog/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc-changelog/action.yml b/doc-changelog/action.yml index 103db30b7..c879ca114 100644 --- a/doc-changelog/action.yml +++ b/doc-changelog/action.yml @@ -280,7 +280,7 @@ runs: # If not using label, remove conventional commit type from title if not use_labels: colon_index = clean_title.index(":") - clean_title = clean_title[4:] + clean_title = clean_title[colon_index:] print(clean_title) From 6c77a94b6150c6251d71f5eda4ceea7b00dc54ae Mon Sep 17 00:00:00 2001 From: klmcadams <58492561+klmcadams@users.noreply.github.com> Date: Fri, 5 Jul 2024 15:58:55 -0400 Subject: [PATCH 24/51] add print statements --- doc-changelog/action.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/doc-changelog/action.yml b/doc-changelog/action.yml index c879ca114..9f82421d7 100644 --- a/doc-changelog/action.yml +++ b/doc-changelog/action.yml @@ -273,10 +273,12 @@ runs: use_labels = "${{ inputs.use-labels }}" # Capitalize first letter of string, so it becomes True or False - use_labels = bool(use_labels[0].upper() + use_labels[1:]) + use_labels = use_labels[0].upper() + use_labels[1:] print(use_labels) + print(bool(use_labels)) + # If not using label, remove conventional commit type from title if not use_labels: colon_index = clean_title.index(":") From e121d16b3df6b74cf601845388a83f29bc1a54e3 Mon Sep 17 00:00:00 2001 From: klmcadams <58492561+klmcadams@users.noreply.github.com> Date: Fri, 5 Jul 2024 16:02:40 -0400 Subject: [PATCH 25/51] remove print statements --- doc-changelog/action.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/doc-changelog/action.yml b/doc-changelog/action.yml index 9f82421d7..8feef090f 100644 --- a/doc-changelog/action.yml +++ b/doc-changelog/action.yml @@ -275,12 +275,8 @@ runs: # Capitalize first letter of string, so it becomes True or False use_labels = use_labels[0].upper() + use_labels[1:] - print(use_labels) - - print(bool(use_labels)) - # If not using label, remove conventional commit type from title - if not use_labels: + if use_labels == "False": colon_index = clean_title.index(":") clean_title = clean_title[colon_index:] From a29eb8d959c95cb7eb94f811f29c3a79d84b764d Mon Sep 17 00:00:00 2001 From: klmcadams <58492561+klmcadams@users.noreply.github.com> Date: Fri, 5 Jul 2024 16:04:53 -0400 Subject: [PATCH 26/51] remove colon --- doc-changelog/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc-changelog/action.yml b/doc-changelog/action.yml index 8feef090f..3be9fdf28 100644 --- a/doc-changelog/action.yml +++ b/doc-changelog/action.yml @@ -278,7 +278,7 @@ runs: # If not using label, remove conventional commit type from title if use_labels == "False": colon_index = clean_title.index(":") - clean_title = clean_title[colon_index:] + clean_title = clean_title[colon_index+1:] print(clean_title) From 502cbc48bd2e6046456ca975e9307a695ddf31e8 Mon Sep 17 00:00:00 2001 From: klmcadams <58492561+klmcadams@users.noreply.github.com> Date: Mon, 8 Jul 2024 09:48:34 -0400 Subject: [PATCH 27/51] update sections and doc-changelog docs --- doc-changelog/action.yml | 19 ++++++++++--------- .../migrations/docs-changelog-setup.rst | 18 ++++++++++++++---- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/doc-changelog/action.yml b/doc-changelog/action.yml index 3be9fdf28..a1b281675 100644 --- a/doc-changelog/action.yml +++ b/doc-changelog/action.yml @@ -181,15 +181,15 @@ runs: cc_type_changelog_dict = { "feat": "added", "fix": "fixed", - "revert": "changed", - "style": "changed", - "refactor": "changed", - "test": "tests", - "chore": "changed", - "perf": "changed", - "ci": "changed", "docs": "documentation", "build": "dependencies", + "revert": "miscellaneous", + "style": "miscellaneous", + "refactor": "miscellaneous", + "perf": "miscellaneous", + "test": "test", + "chore": "maintenance", + "ci": "maintenance", } changelog_section = cc_type_changelog_dict[cc_type] @@ -218,9 +218,10 @@ runs: "enhancement": "added", "bug": "fixed", "documentation": "documentation", - "tests": "tests", + "testing": "test", "dependencies": "dependencies", - "maintenance": "changed" + "CI/CD": "maintenance", + "maintenance": "maintenance" } def get_changelog_section(pr_labels, existing_labels): diff --git a/doc/source/migrations/docs-changelog-setup.rst b/doc/source/migrations/docs-changelog-setup.rst index d0be79216..740d86c9c 100644 --- a/doc/source/migrations/docs-changelog-setup.rst +++ b/doc/source/migrations/docs-changelog-setup.rst @@ -247,8 +247,13 @@ Also, replace ``ansys..`` with the name under ``tool.flit.modu showcontent = true [[tool.towncrier.type]] - directory = "changed" - name = "Changed" + directory = "dependencies" + name = "Dependencies" + showcontent = true + + [[tool.towncrier.type]] + directory = "documentation" + name = "Documentation" showcontent = true [[tool.towncrier.type]] @@ -257,8 +262,8 @@ Also, replace ``ansys..`` with the name under ``tool.flit.modu showcontent = true [[tool.towncrier.type]] - directory = "dependencies" - name = "Dependencies" + directory = "maintenance" + name = "Maintenance" showcontent = true [[tool.towncrier.type]] @@ -266,6 +271,11 @@ Also, replace ``ansys..`` with the name under ``tool.flit.modu name = "Miscellaneous" showcontent = true + [[tool.towncrier.type]] + directory = "test" + name = "Test" + showcontent = true + A reference pull request for these changes can be found in the `PyAnsys Geometry #1023 `_ pull request. From 07b2b529a33099abf8f6333bbbf32adf54b0ff20 Mon Sep 17 00:00:00 2001 From: klmcadams <58492561+klmcadams@users.noreply.github.com> Date: Mon, 8 Jul 2024 10:38:13 -0400 Subject: [PATCH 28/51] add use-labels to doc-changelog example yml file --- doc/source/doc-actions/examples/doc-changelog-basic.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/doc-actions/examples/doc-changelog-basic.yml b/doc/source/doc-actions/examples/doc-changelog-basic.yml index db1db3166..f7a7b2e9b 100644 --- a/doc/source/doc-actions/examples/doc-changelog-basic.yml +++ b/doc/source/doc-actions/examples/doc-changelog-basic.yml @@ -20,3 +20,4 @@ changelog-fragment: - uses: ansys/actions/doc-changelog@{{ version }} with: token: ${{ '{{ secrets.PYANSYS_CI_BOT_TOKEN }}' }} + # use-labels: true # uncomment this line to use labels instead of conventional commits From 32c6effe9fe754be11817c4d8ac0ddfa3d35f70d Mon Sep 17 00:00:00 2001 From: klmcadams <58492561+klmcadams@users.noreply.github.com> Date: Tue, 9 Jul 2024 11:36:02 -0400 Subject: [PATCH 29/51] use python script in action --- doc-build/parse_pr_title.py | 180 ++++++++++++++++++++++++++++++++++++ doc-changelog/action.yml | 164 +++++--------------------------- 2 files changed, 205 insertions(+), 139 deletions(-) create mode 100644 doc-build/parse_pr_title.py diff --git a/doc-build/parse_pr_title.py b/doc-build/parse_pr_title.py new file mode 100644 index 000000000..dbe9bb726 --- /dev/null +++ b/doc-build/parse_pr_title.py @@ -0,0 +1,180 @@ +import argparse +import os + + +def save_env_variable(env_var_name, env_var_value): + # Get the GITHUB_ENV variable + github_env = os.getenv("GITHUB_ENV") + + # Save environment variable with its value + with open(github_env, "a") as f: + f.write(f"{env_var_name}={env_var_value}") + + +def get_first_letter_case(pr_title): + pr_title = f"""{pr_title}""" + index = 0 + first_letter = pr_title[index] + + while first_letter == " ": + index += 1 + try: + first_letter = pr_title[index] + except IndexError: + print("Pull request title is blank") + exit(1) + + if first_letter.islower(): + save_env_variable("FIRST_LETTER", "lowercase") + else: + save_env_variable("FIRST_LETTER", "uppercase") + + +def get_conventional_commit_type(pr_title): + pr_title = f"""{pr_title}""" + colon_index = pr_title.index(":") + cc_type = '"' + pr_title[:colon_index] + '"' + save_env_variable("CC_TYPE", cc_type) + + +def changelog_category_cc(cc_type): + # Get conventional commit type from env variable + cc_type = cc_type.lower() + + print(cc_type) + + cc_type_changelog_dict = { + "feat": "added", + "fix": "fixed", + "docs": "documentation", + "build": "dependencies", + "revert": "miscellaneous", + "style": "miscellaneous", + "refactor": "miscellaneous", + "perf": "miscellaneous", + "test": "test", + "chore": "maintenance", + "ci": "maintenance", + } + + changelog_section = cc_type_changelog_dict[cc_type] + + save_env_variable("CHANGELOG_SECTION", changelog_section) + + +def changelog_cateogry_labels(labels): + # Create a list of labels found in the pull request + # For example, "enhancement maintenance".split() -> ["enhancement", "maintenance"] + existing_labels = labels.split() + + # Dictionary with the key as a label from .github/workflows/label.yml and + # value as the corresponding section in the changelog + pr_labels = { + "enhancement": "added", + "bug": "fixed", + "documentation": "documentation", + "testing": "test", + "dependencies": "dependencies", + "CI/CD": "maintenance", + "maintenance": "maintenance", + } + + def get_changelog_section(pr_labels, existing_labels): + """Find the changelog section corresponding to the label in the PR.""" + label_type = "" + + for key, value in pr_labels.items(): + if key in existing_labels: + label_type = value + return label_type + + # If no labels are in the PR, it goes into the miscellaneous category + label_type = "miscellaneous" + return label_type + + save_env_variable( + "CHANGELOG_SECTION", get_changelog_section(pr_labels, existing_labels) + ) + + +def clean_pr_title(use_labels: bool): + # Retrieve title + clean_title = os.getenv("PR_TITLE") + + # Capitalize first letter of string, so it becomes True or False + use_labels = use_labels[0].upper() + use_labels[1:] + + # If not using label, remove conventional commit type from title + if use_labels == "False": + colon_index = clean_title.index(":") + clean_title = clean_title[colon_index + 1 :] + + print(clean_title) + + # Remove extra whitespace + clean_title = clean_title.strip() + + # Add backslash in front of backtick and double quote + clean_title = clean_title.replace("`", "\\`").replace('"', '\\"') + + save_env_variable("CLEAN_TITLE", clean_title) + + +def main(): + parser = argparse.ArgumentParser(description="Parse pull request title.") + parser.add_argument( + "--get-cc-type", action=argparse.BooleanOptionalAction, default=False + ) + parser.add_argument( + "--get-first-letter-case", action=argparse.BooleanOptionalAction, default=False + ) + parser.add_argument( + "--changelog-category-cc", action=argparse.BooleanOptionalAction, default=False + ) + parser.add_argument( + "--changelog-category-labels", + action=argparse.BooleanOptionalAction, + default=False, + ) + parser.add_argument( + "--clean_pr_title", action=argparse.BooleanOptionalAction, default=False + ) + parser.add_argument( + "--use-labels", action=argparse.BooleanOptionalAction, default=True + ) + parser.add_argument( + "--pr-title", + type=str, + help="The pull request title", + ) + parser.add_argument( + "--cc-type", + type=str, + help="The pull request title", + ) + parser.add_argument( + "--labels", + type=str, + help="The pull request title", + ) + + args = parser.parse_args() + pr_title = f"""{args.pr_title}""" + cc_type = args.cc_type + labels = args.labels + use_labels = args.use_labels + + if args.get_cc_type: + get_conventional_commit_type(pr_title) + if args.get_first_letter_case: + get_first_letter_case(pr_title) + if args.changelog_category_cc: + changelog_category_cc(cc_type) + if args.changelog_category_labels: + changelog_cateogry_labels(labels) + if args.clean_pr_title: + clean_pr_title(use_labels) + + +if __name__ == "__main__": + main() diff --git a/doc-changelog/action.yml b/doc-changelog/action.yml index a1b281675..d33bde3a0 100644 --- a/doc-changelog/action.yml +++ b/doc-changelog/action.yml @@ -99,39 +99,26 @@ runs: run: | python -m pip install --upgrade pip towncrier==${{ inputs.towncrier-version }} - - name: "Check pull-request title follows conventional commits style" - id: lowercase - if: ${{ inputs.use-labels == 'false' && ((github.event_name == 'pull_request_target') || (github.event_name == 'pull_request')) }} - uses: amannn/action-semantic-pull-request@v5 + - name: "Get first letter of conventional commit type" + if: ${{ inputs.use-labels == 'false' }} env: - GITHUB_TOKEN: ${{ inputs.token }} - continue-on-error: true + PR_TITLE: ${{ github.event.pull_request.title }} + shell: python + run: | + python ${{ github.action_path }}/../doc-build/parse_pr_title.py --get-first-letter-case --pr-title ${{ env.PR_TITLE }} - - name: "Check pull-request title follows conventional commits style with upper case" - id: caps - if: ${{ inputs.use-labels == 'false' && ((github.event_name == 'pull_request_target') || (github.event_name == 'pull_request')) }} - uses: amannn/action-semantic-pull-request@v5 - env: - GITHUB_TOKEN: ${{ inputs.token }} + - name: "Check pull-request title follows conventional commits style" + if: ${{ env.FIRST_LETTER == 'lowercase' }} + uses: ansys/actions/commit-style@v6 with: - types: | - BUILD - CHORE - CI - DOCS - FEAT - FIX - PERF - REFACTOR - REVERT - STYLE - TEST - continue-on-error: true + token: ${{ inputs.token }} - - name: "Check failures" - if: steps.lowercase.outcome == 'failure' && steps.caps.outcome == 'failure' - shell: bash - run: exit 1 + - name: "Check pull-request title follows conventional commits style with upper case" + if: ${{ env.FIRST_LETTER == 'uppercase' }} + uses: ansys/actions/commit-style@v6 + with: + token: ${{ inputs.token }} + use-upper-case: true - name: "Get conventional commit type from title" if: ${{ inputs.use-labels == 'false' }} @@ -139,17 +126,7 @@ runs: PR_TITLE: ${{ github.event.pull_request.title }} shell: python run: | - import os - - pr_title = f"""{os.environ.get('PR_TITLE')}""" - colon_index = pr_title.index(":") - cc_type = '"'+pr_title[:colon_index]+'"' - - # Get the GITHUB_ENV variable - github_env = os.getenv('GITHUB_ENV') - - with open(github_env, "a") as f: - f.write(f'CC_TYPE={cc_type}') + python ${{ github.action_path }}/../doc-build/parse_pr_title.py --get-cc-type --pr-title ${{ env.PR_TITLE }} - name: "Get labels in the pull request" if: ${{ inputs.use-labels == 'true' }} @@ -171,79 +148,13 @@ runs: if: ${{ inputs.use-labels == 'false' }} shell: python run: | - import os - - # Get conventional commit type from env variable - cc_type = ${{ env.CC_TYPE }}.lower() - - print(cc_type) - - cc_type_changelog_dict = { - "feat": "added", - "fix": "fixed", - "docs": "documentation", - "build": "dependencies", - "revert": "miscellaneous", - "style": "miscellaneous", - "refactor": "miscellaneous", - "perf": "miscellaneous", - "test": "test", - "chore": "maintenance", - "ci": "maintenance", - } - - changelog_section = cc_type_changelog_dict[cc_type] - - # Get the GITHUB_ENV variable - github_env = os.getenv('GITHUB_ENV') - - # Append the CHANGELOG_SECTION with its value to GITHUB_ENV - # For example, CHANGELOG_SECTION="added" if the conventional commit title was "feat" - with open(github_env, "a") as f: - f.write(f"CHANGELOG_SECTION={changelog_section}") + python ${{ github.action_path }}/../doc-build/parse_pr_title.py --changelog-category-cc --cc-type ${{ env.CC_TYPE }} - name: "Set PR label environment variable" if: ${{ inputs.use-labels == 'true' }} shell: python run: | - import os - - # Create a list of labels found in the pull request - # For example, "enhancement maintenance".split() -> ["enhancement", "maintenance"] - existing_labels = ${{ env.LABELS }}.split() - - # Dictionary with the key as a label from .github/workflows/label.yml and - # value as the corresponding section in the changelog - pr_labels = { - "enhancement": "added", - "bug": "fixed", - "documentation": "documentation", - "testing": "test", - "dependencies": "dependencies", - "CI/CD": "maintenance", - "maintenance": "maintenance" - } - - def get_changelog_section(pr_labels, existing_labels): - """Find the changelog section corresponding to the label in the PR.""" - label_type = "" - - for key, value in pr_labels.items(): - if key in existing_labels: - label_type = value - return label_type - - # If no labels are in the PR, it goes into the miscellaneous category - label_type = "miscellaneous" - return label_type - - # Get the GITHUB_ENV variable - github_env = os.getenv('GITHUB_ENV') - - # Append the CHANGELOG_SECTION with its value to GITHUB_ENV - # For example, CHANGELOG_SECTION="added" if the PR had an "enhancement" label - with open(github_env, "a") as f: - f.write(f"CHANGELOG_SECTION={get_changelog_section(pr_labels, existing_labels)}") + python ${{ github.action_path }}/../doc-build/parse_pr_title.py --changelog-category-labels --labels ${{ env.LABELS }} - name: "Remove PR fragment file if it already exists" env: @@ -263,38 +174,13 @@ runs: - name: "Clean PR title" env: PR_TITLE: ${{ github.event.pull_request.title }} - shell: python + shell: bash run: | - import os - - # Retrieve title - clean_title = os.getenv('PR_TITLE') - - # Retrieve use-labels boolean - use_labels = "${{ inputs.use-labels }}" - - # Capitalize first letter of string, so it becomes True or False - use_labels = use_labels[0].upper() + use_labels[1:] - - # If not using label, remove conventional commit type from title - if use_labels == "False": - colon_index = clean_title.index(":") - clean_title = clean_title[colon_index+1:] - - print(clean_title) - - # Remove extra whitespace - clean_title = clean_title.strip() - - # Add backslash in front of backtick and double quote - clean_title = clean_title.replace("`", "\`").replace('"', '\\"') - - # Get the GITHUB_ENV variable - github_env = os.getenv('GITHUB_ENV') - - # Append the CLEAN_TITLE with its value to GITHUB_ENV - with open(github_env, "a") as f: - f.write(f"CLEAN_TITLE={clean_title}") + if [[ ${{ inputs.use-labels }} == "true" ]]; then + python ${{ github.action_path }}/../doc-build/parse_pr_title.py --clean-pr-title --use-labels + else + python ${{ github.action_path }}/../doc-build/parse_pr_title.py --clean-pr-title --no-use-labels + fi - name: "Create and commit towncrier fragment" env: From e825200abdf19dfb5cde07497cbd1dbe7edb227f Mon Sep 17 00:00:00 2001 From: klmcadams <58492561+klmcadams@users.noreply.github.com> Date: Tue, 9 Jul 2024 11:53:09 -0400 Subject: [PATCH 30/51] add backslashes to pr_title --- doc-build/parse_pr_title.py | 2 ++ doc-changelog/action.yml | 24 ++++++++++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/doc-build/parse_pr_title.py b/doc-build/parse_pr_title.py index dbe9bb726..dd9fc4998 100644 --- a/doc-build/parse_pr_title.py +++ b/doc-build/parse_pr_title.py @@ -16,6 +16,8 @@ def get_first_letter_case(pr_title): index = 0 first_letter = pr_title[index] + print(pr_title) + while first_letter == " ": index += 1 try: diff --git a/doc-changelog/action.yml b/doc-changelog/action.yml index d33bde3a0..f35c0283c 100644 --- a/doc-changelog/action.yml +++ b/doc-changelog/action.yml @@ -99,13 +99,33 @@ runs: run: | python -m pip install --upgrade pip towncrier==${{ inputs.towncrier-version }} + - name: "Add backslashes to PR_TITLE" + env: + PR_TITLE: ${{ github.event.pull_request.title }} + shell: python + run: | + pr_title = """${{ env.PR_TITLE }}""" + + # Add backslashes in front of double quotes + pr_title = pr_title.replace('"', '\\"') + + # Add backslashes in front of backticks + pr_title = pr_title.replace("`", "\`") + + # Get the GITHUB_ENV variable + github_env = os.getenv("GITHUB_ENV") + + # Save environment variable with its value + with open(github_env, "a") as f: + f.write(f"PR_TITLE={pr_title}") + - name: "Get first letter of conventional commit type" if: ${{ inputs.use-labels == 'false' }} env: PR_TITLE: ${{ github.event.pull_request.title }} - shell: python + shell: bash run: | - python ${{ github.action_path }}/../doc-build/parse_pr_title.py --get-first-letter-case --pr-title ${{ env.PR_TITLE }} + python ${{ github.action_path }}/../doc-build/parse_pr_title.py --get-first-letter-case --pr-title "${{ env.PR_TITLE }}" - name: "Check pull-request title follows conventional commits style" if: ${{ env.FIRST_LETTER == 'lowercase' }} From 026c3b369951e0cb272d6768edaaf6226eddb576 Mon Sep 17 00:00:00 2001 From: klmcadams <58492561+klmcadams@users.noreply.github.com> Date: Tue, 9 Jul 2024 11:55:28 -0400 Subject: [PATCH 31/51] import os --- doc-changelog/action.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/doc-changelog/action.yml b/doc-changelog/action.yml index f35c0283c..51ce05152 100644 --- a/doc-changelog/action.yml +++ b/doc-changelog/action.yml @@ -104,6 +104,7 @@ runs: PR_TITLE: ${{ github.event.pull_request.title }} shell: python run: | + import os pr_title = """${{ env.PR_TITLE }}""" # Add backslashes in front of double quotes From e53b485bd5a881e4f2b2b2acb757389452aa6674 Mon Sep 17 00:00:00 2001 From: klmcadams <58492561+klmcadams@users.noreply.github.com> Date: Tue, 9 Jul 2024 16:04:22 -0400 Subject: [PATCH 32/51] import functions from python script --- doc-changelog/action.yml | 60 +++++++++---------- .../parse_pr_title.py | 8 +-- 2 files changed, 31 insertions(+), 37 deletions(-) rename {doc-build => doc-changelog}/parse_pr_title.py (96%) diff --git a/doc-changelog/action.yml b/doc-changelog/action.yml index 51ce05152..10c5cf611 100644 --- a/doc-changelog/action.yml +++ b/doc-changelog/action.yml @@ -99,34 +99,16 @@ runs: run: | python -m pip install --upgrade pip towncrier==${{ inputs.towncrier-version }} - - name: "Add backslashes to PR_TITLE" - env: - PR_TITLE: ${{ github.event.pull_request.title }} - shell: python - run: | - import os - pr_title = """${{ env.PR_TITLE }}""" - - # Add backslashes in front of double quotes - pr_title = pr_title.replace('"', '\\"') - - # Add backslashes in front of backticks - pr_title = pr_title.replace("`", "\`") - - # Get the GITHUB_ENV variable - github_env = os.getenv("GITHUB_ENV") - - # Save environment variable with its value - with open(github_env, "a") as f: - f.write(f"PR_TITLE={pr_title}") - - name: "Get first letter of conventional commit type" if: ${{ inputs.use-labels == 'false' }} env: PR_TITLE: ${{ github.event.pull_request.title }} - shell: bash + shell: python run: | - python ${{ github.action_path }}/../doc-build/parse_pr_title.py --get-first-letter-case --pr-title "${{ env.PR_TITLE }}" + from parse_pr_title import get_first_letter_case + + pr_title = """${{ env.PR_TITLE }}""" + get_first_letter_case(pr_title) - name: "Check pull-request title follows conventional commits style" if: ${{ env.FIRST_LETTER == 'lowercase' }} @@ -147,7 +129,10 @@ runs: PR_TITLE: ${{ github.event.pull_request.title }} shell: python run: | - python ${{ github.action_path }}/../doc-build/parse_pr_title.py --get-cc-type --pr-title ${{ env.PR_TITLE }} + from parse_pr_title import get_conventional_commit_type + + pr_title = """${{ env.PR_TITLE }}""" + get_conventional_commit_type(pr_title) - name: "Get labels in the pull request" if: ${{ inputs.use-labels == 'true' }} @@ -169,13 +154,19 @@ runs: if: ${{ inputs.use-labels == 'false' }} shell: python run: | - python ${{ github.action_path }}/../doc-build/parse_pr_title.py --changelog-category-cc --cc-type ${{ env.CC_TYPE }} + from parse_pr_title import changelog_category_cc + + cc_type = "${{ env.CC_TYPE }}" + get_conventional_commit_type(cc_type) - name: "Set PR label environment variable" if: ${{ inputs.use-labels == 'true' }} shell: python run: | - python ${{ github.action_path }}/../doc-build/parse_pr_title.py --changelog-category-labels --labels ${{ env.LABELS }} + from parse_pr_title import changelog_cateogry_labels + + labels = "${{ env.LABELS }}" + changelog_cateogry_labels(labels) - name: "Remove PR fragment file if it already exists" env: @@ -195,13 +186,18 @@ runs: - name: "Clean PR title" env: PR_TITLE: ${{ github.event.pull_request.title }} - shell: bash + shell: python run: | - if [[ ${{ inputs.use-labels }} == "true" ]]; then - python ${{ github.action_path }}/../doc-build/parse_pr_title.py --clean-pr-title --use-labels - else - python ${{ github.action_path }}/../doc-build/parse_pr_title.py --clean-pr-title --no-use-labels - fi + from parse_pr_title import clean_pr_title + + pr_title = """${{ env.PR_TITLE }}""" + use_labels = ${{ inputs.use-labels }} + use_labels = use_labels[0].upper() + use_labels[1:] + + if use_labels == "True": + clean_pr_title(pr_title, use_labels) + else: + clean_pr_title(pr_title, use_labels) - name: "Create and commit towncrier fragment" env: diff --git a/doc-build/parse_pr_title.py b/doc-changelog/parse_pr_title.py similarity index 96% rename from doc-build/parse_pr_title.py rename to doc-changelog/parse_pr_title.py index dd9fc4998..6db7922ff 100644 --- a/doc-build/parse_pr_title.py +++ b/doc-changelog/parse_pr_title.py @@ -99,12 +99,9 @@ def get_changelog_section(pr_labels, existing_labels): ) -def clean_pr_title(use_labels: bool): +def clean_pr_title(pr_title, use_labels): # Retrieve title - clean_title = os.getenv("PR_TITLE") - - # Capitalize first letter of string, so it becomes True or False - use_labels = use_labels[0].upper() + use_labels[1:] + clean_title = pr_title # If not using label, remove conventional commit type from title if use_labels == "False": @@ -147,6 +144,7 @@ def main(): parser.add_argument( "--pr-title", type=str, + nargs="+", help="The pull request title", ) parser.add_argument( From 3ffa3fe9e46f122cb6ea7003104389da6015bf06 Mon Sep 17 00:00:00 2001 From: klmcadams <58492561+klmcadams@users.noreply.github.com> Date: Tue, 9 Jul 2024 16:10:24 -0400 Subject: [PATCH 33/51] add doc-changelog to path --- doc-changelog/action.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/doc-changelog/action.yml b/doc-changelog/action.yml index 10c5cf611..d64275f59 100644 --- a/doc-changelog/action.yml +++ b/doc-changelog/action.yml @@ -105,6 +105,10 @@ runs: PR_TITLE: ${{ github.event.pull_request.title }} shell: python run: | + import sys + # caution: path[0] is reserved for script path (or '' in REPL) + sys.path.insert(1, '${{ github.action_path }}/../doc-changelog/') + from parse_pr_title import get_first_letter_case pr_title = """${{ env.PR_TITLE }}""" From 127fda5ad0d296560422488e30723f7d1d2ade1a Mon Sep 17 00:00:00 2001 From: klmcadams <58492561+klmcadams@users.noreply.github.com> Date: Tue, 9 Jul 2024 16:23:25 -0400 Subject: [PATCH 34/51] add sys path to all python sections --- doc-changelog/action.yml | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/doc-changelog/action.yml b/doc-changelog/action.yml index d64275f59..6ad7056b7 100644 --- a/doc-changelog/action.yml +++ b/doc-changelog/action.yml @@ -106,7 +106,6 @@ runs: shell: python run: | import sys - # caution: path[0] is reserved for script path (or '' in REPL) sys.path.insert(1, '${{ github.action_path }}/../doc-changelog/') from parse_pr_title import get_first_letter_case @@ -133,6 +132,9 @@ runs: PR_TITLE: ${{ github.event.pull_request.title }} shell: python run: | + import sys + sys.path.insert(1, '${{ github.action_path }}/../doc-changelog/') + from parse_pr_title import get_conventional_commit_type pr_title = """${{ env.PR_TITLE }}""" @@ -158,6 +160,9 @@ runs: if: ${{ inputs.use-labels == 'false' }} shell: python run: | + import sys + sys.path.insert(1, '${{ github.action_path }}/../doc-changelog/') + from parse_pr_title import changelog_category_cc cc_type = "${{ env.CC_TYPE }}" @@ -167,6 +172,9 @@ runs: if: ${{ inputs.use-labels == 'true' }} shell: python run: | + import sys + sys.path.insert(1, '${{ github.action_path }}/../doc-changelog/') + from parse_pr_title import changelog_cateogry_labels labels = "${{ env.LABELS }}" @@ -192,6 +200,9 @@ runs: PR_TITLE: ${{ github.event.pull_request.title }} shell: python run: | + import sys + sys.path.insert(1, '${{ github.action_path }}/../doc-changelog/') + from parse_pr_title import clean_pr_title pr_title = """${{ env.PR_TITLE }}""" From 92a7169ab174d2c4d6baaf51f81a110e69969901 Mon Sep 17 00:00:00 2001 From: klmcadams <58492561+klmcadams@users.noreply.github.com> Date: Tue, 9 Jul 2024 16:25:21 -0400 Subject: [PATCH 35/51] remove quotes around labels and cc_type --- doc-changelog/action.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc-changelog/action.yml b/doc-changelog/action.yml index 6ad7056b7..e773326bc 100644 --- a/doc-changelog/action.yml +++ b/doc-changelog/action.yml @@ -165,7 +165,7 @@ runs: from parse_pr_title import changelog_category_cc - cc_type = "${{ env.CC_TYPE }}" + cc_type = ${{ env.CC_TYPE }} get_conventional_commit_type(cc_type) - name: "Set PR label environment variable" @@ -177,7 +177,7 @@ runs: from parse_pr_title import changelog_cateogry_labels - labels = "${{ env.LABELS }}" + labels = ${{ env.LABELS }} changelog_cateogry_labels(labels) - name: "Remove PR fragment file if it already exists" From f8a05ffa93bdee2dbbe4d893e7784992402c3023 Mon Sep 17 00:00:00 2001 From: klmcadams <58492561+klmcadams@users.noreply.github.com> Date: Tue, 9 Jul 2024 16:27:45 -0400 Subject: [PATCH 36/51] fix import statement --- doc-changelog/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc-changelog/action.yml b/doc-changelog/action.yml index e773326bc..a5b92530b 100644 --- a/doc-changelog/action.yml +++ b/doc-changelog/action.yml @@ -166,7 +166,7 @@ runs: from parse_pr_title import changelog_category_cc cc_type = ${{ env.CC_TYPE }} - get_conventional_commit_type(cc_type) + changelog_category_cc(cc_type) - name: "Set PR label environment variable" if: ${{ inputs.use-labels == 'true' }} From b09e253b43e59e76e00bf09972a97e7d65700fd2 Mon Sep 17 00:00:00 2001 From: klmcadams <58492561+klmcadams@users.noreply.github.com> Date: Tue, 9 Jul 2024 16:28:57 -0400 Subject: [PATCH 37/51] add quotes around use_labels --- doc-changelog/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc-changelog/action.yml b/doc-changelog/action.yml index a5b92530b..5ba396b9a 100644 --- a/doc-changelog/action.yml +++ b/doc-changelog/action.yml @@ -206,7 +206,7 @@ runs: from parse_pr_title import clean_pr_title pr_title = """${{ env.PR_TITLE }}""" - use_labels = ${{ inputs.use-labels }} + use_labels = "${{ inputs.use-labels }}" use_labels = use_labels[0].upper() + use_labels[1:] if use_labels == "True": From 6090532fdbdfbd7ffb6c66c5cb83137ff32a330b Mon Sep 17 00:00:00 2001 From: klmcadams <58492561+klmcadams@users.noreply.github.com> Date: Tue, 9 Jul 2024 16:35:53 -0400 Subject: [PATCH 38/51] remove argparse --- doc-changelog/parse_pr_title.py | 62 --------------------------------- 1 file changed, 62 deletions(-) diff --git a/doc-changelog/parse_pr_title.py b/doc-changelog/parse_pr_title.py index 6db7922ff..91aae1cb1 100644 --- a/doc-changelog/parse_pr_title.py +++ b/doc-changelog/parse_pr_title.py @@ -1,4 +1,3 @@ -import argparse import os @@ -117,64 +116,3 @@ def clean_pr_title(pr_title, use_labels): clean_title = clean_title.replace("`", "\\`").replace('"', '\\"') save_env_variable("CLEAN_TITLE", clean_title) - - -def main(): - parser = argparse.ArgumentParser(description="Parse pull request title.") - parser.add_argument( - "--get-cc-type", action=argparse.BooleanOptionalAction, default=False - ) - parser.add_argument( - "--get-first-letter-case", action=argparse.BooleanOptionalAction, default=False - ) - parser.add_argument( - "--changelog-category-cc", action=argparse.BooleanOptionalAction, default=False - ) - parser.add_argument( - "--changelog-category-labels", - action=argparse.BooleanOptionalAction, - default=False, - ) - parser.add_argument( - "--clean_pr_title", action=argparse.BooleanOptionalAction, default=False - ) - parser.add_argument( - "--use-labels", action=argparse.BooleanOptionalAction, default=True - ) - parser.add_argument( - "--pr-title", - type=str, - nargs="+", - help="The pull request title", - ) - parser.add_argument( - "--cc-type", - type=str, - help="The pull request title", - ) - parser.add_argument( - "--labels", - type=str, - help="The pull request title", - ) - - args = parser.parse_args() - pr_title = f"""{args.pr_title}""" - cc_type = args.cc_type - labels = args.labels - use_labels = args.use_labels - - if args.get_cc_type: - get_conventional_commit_type(pr_title) - if args.get_first_letter_case: - get_first_letter_case(pr_title) - if args.changelog_category_cc: - changelog_category_cc(cc_type) - if args.changelog_category_labels: - changelog_cateogry_labels(labels) - if args.clean_pr_title: - clean_pr_title(use_labels) - - -if __name__ == "__main__": - main() From a8e5c6cfc0dfc7f794c872bc682babec5e7e9297 Mon Sep 17 00:00:00 2001 From: klmcadams <58492561+klmcadams@users.noreply.github.com> Date: Wed, 10 Jul 2024 18:03:13 -0400 Subject: [PATCH 39/51] add towncrier config template, use-conventional-commits, and web-release-notes --- doc-changelog/action.yml | 46 +++++++++++++++--- doc-changelog/parse_pr_title.py | 86 +++++++++++++++++++++++++++++++++ 2 files changed, 125 insertions(+), 7 deletions(-) diff --git a/doc-changelog/action.yml b/doc-changelog/action.yml index 5ba396b9a..e897e51ee 100644 --- a/doc-changelog/action.yml +++ b/doc-changelog/action.yml @@ -67,12 +67,26 @@ inputs: use-labels: description: > - Whether to use labels to categorize towncrier fragments or conventional - commits. + Use labels to cateogrize towncrier fragments. + required: false + default: true + type: boolean + + use-conventional-commits: + description: > + Use conventional commits to categorize towncrier fragments. required: false default: false type: boolean + web-release-notes: + description: > + Whether or not your documentation uses the release notes in + the documentation, the changelog.rst file. + required: false + default: true + type: boolean + runs: using: "composite" steps: @@ -100,7 +114,7 @@ runs: python -m pip install --upgrade pip towncrier==${{ inputs.towncrier-version }} - name: "Get first letter of conventional commit type" - if: ${{ inputs.use-labels == 'false' }} + if: ${{ inputs.use-conventional-commits == 'true' }} env: PR_TITLE: ${{ github.event.pull_request.title }} shell: python @@ -114,20 +128,20 @@ runs: get_first_letter_case(pr_title) - name: "Check pull-request title follows conventional commits style" - if: ${{ env.FIRST_LETTER == 'lowercase' }} + if: ${{ (inputs.use-conventional-commits == 'true') && (env.FIRST_LETTER == 'lowercase') }} uses: ansys/actions/commit-style@v6 with: token: ${{ inputs.token }} - name: "Check pull-request title follows conventional commits style with upper case" - if: ${{ env.FIRST_LETTER == 'uppercase' }} + if: ${{ (inputs.use-conventional-commits == 'true') && (env.FIRST_LETTER == 'uppercase') }} uses: ansys/actions/commit-style@v6 with: token: ${{ inputs.token }} use-upper-case: true - name: "Get conventional commit type from title" - if: ${{ inputs.use-labels == 'false' }} + if: ${{ inputs.use-conventional-commits == 'true' }} env: PR_TITLE: ${{ github.event.pull_request.title }} shell: python @@ -157,7 +171,7 @@ runs: echo LABELS='"'$pr_labels'"' >> $GITHUB_ENV - name: "Set CHANGELOG category based on conventional commit type" - if: ${{ inputs.use-labels == 'false' }} + if: ${{ inputs.use-conventional-commits == 'true' }} shell: python run: | import sys @@ -214,6 +228,24 @@ runs: else: clean_pr_title(pr_title, use_labels) + - name: "Append towncrier categories to pyproject.toml" + env: + REPO_NAME: ${{ github.event.repository.name }} + ORG_NAME: ${{ github.event.repository.owner }} + shell: python + run: | + import sys + sys.path.insert(1, '${{ github.action_path }}/../doc-changelog/') + + from parse_pr_title import add_towncrier_config + + repo_name = ${{ env.REPO_NAME }} + org_name = ${{ env.ORG_NAME }} + + web_rel_notes = True if ${{ inputs.web-release-notes }} == "true" else False + + add_towncrier_config(org_name, repo_name, web_rel_notes) + - name: "Create and commit towncrier fragment" env: PR_BRANCH: ${{ github.event.pull_request.head.ref }} diff --git a/doc-changelog/parse_pr_title.py b/doc-changelog/parse_pr_title.py index 91aae1cb1..a47f778fa 100644 --- a/doc-changelog/parse_pr_title.py +++ b/doc-changelog/parse_pr_title.py @@ -1,5 +1,7 @@ import os +import toml + def save_env_variable(env_var_name, env_var_value): # Get the GITHUB_ENV variable @@ -116,3 +118,87 @@ def clean_pr_title(pr_title, use_labels): clean_title = clean_title.replace("`", "\\`").replace('"', '\\"') save_env_variable("CLEAN_TITLE", clean_title) + + +def add_towncrier_config(org_name, repo_name, web_release_notes): + # Load pyproject.toml file + with open("pyproject.toml", "a+") as file: + config = toml.load("pyproject.toml") + tool = config.get("tool", "DNE") + towncrier = tool.get("towncrier", "DNE") + changelog_sections = [ + "added", + "dependencies", + "documentation", + "fixed", + "maintenance", + "miscellaneous", + "test", + ] + + # Get the package name from [tool.flit.module] + flit = tool.get("flit", "DNE") + module = name = package = "" + if flit != "DNE": + module = flit.get("module", "DNE") + if module != ("DNE" or ""): + name = module.get("name", "DNE") + + # If [tool.flit.module] name exists, create the package string + if name != ("DNE" and ""): + package = f'package = "{name}"' + + # If the [tool.towncrier] section does not exist + if towncrier == "DNE": + # Append the tool.towncrier section + file.write("\n[tool.towncrier]\n") + + # Write the package line if [tool.flit.module] name exists + if package: + file.write(f"{package}\n") + + # Write general towncrier configuration + file.write( + """directory = "doc/changelog.d" +underlines = ["", "", ""] +template = "doc/changelog.d/changelog_template.jinja"\n""" + ) + + # Write configuration for changelog.rst release notes + if web_release_notes: + file.write( + f"""filename = "doc/source/changelog.rst" +start_string = ".. towncrier release notes start\\n" +title_format = "`{{version}} `_ - {{project_date}}" +issue_format = "`#{{issue}} `_"\n""" + ) + + # Write configuration for CHANGELOG.md release notes + else: + file.write( + f"""filename = "CHANGELOG.md" +start_string = "\\n" +title_format = "## [{{version}}](https://github.com/{org_name}/{repo_name}/releases/tag/v{{version}}) - {{project_date}}" +issue_format = "[#{{issue}}](https://github.com/{org_name}/{repo_name}/pull/{{issue}})"\n""" + ) + # If [tool.towncrier] exists + else: + # Get the [[tool.towncrier.type]] sections + types = towncrier.get("type", "DNE") + + # If the [[tool.towncrier.type]] sections exist + if types != "DNE": + for group in types: + # Remove changelog section if it exists under [[tool.towncrier.type]] so that + # only missing sections are appended to the pyproject.toml file + changelog_sections.remove(group["directory"]) + + # Write each missing section to the pyproject.toml file + for section in changelog_sections: + file.write( + f""" +[[tool.towncrier.type]] +directory = "{section}" +name = "{section.title()}" +showcontent = true\n""" + ) From b950aaa8701af3e01057f9f259d82d4bc5aaebf0 Mon Sep 17 00:00:00 2001 From: klmcadams <58492561+klmcadams@users.noreply.github.com> Date: Thu, 11 Jul 2024 12:08:14 -0400 Subject: [PATCH 40/51] add docstrings & separate function into smaller functions --- doc-changelog/parse_pr_title.py | 300 +++++++++++++----- .../examples/doc-changelog-basic.yml | 7 +- 2 files changed, 230 insertions(+), 77 deletions(-) diff --git a/doc-changelog/parse_pr_title.py b/doc-changelog/parse_pr_title.py index a47f778fa..08aea4706 100644 --- a/doc-changelog/parse_pr_title.py +++ b/doc-changelog/parse_pr_title.py @@ -3,49 +3,90 @@ import toml -def save_env_variable(env_var_name, env_var_value): +def save_env_variable(env_var_name: str, env_var_value: str): + """Save environment variable to the GITHUB_ENV file. + + Parameters + ---------- + env_var_name: str + The name of the environment variable. + env_var_value: str + The value of the environment variable. + """ # Get the GITHUB_ENV variable github_env = os.getenv("GITHUB_ENV") # Save environment variable with its value - with open(github_env, "a") as f: - f.write(f"{env_var_name}={env_var_value}") + with open(github_env, "a") as file: + file.write(f"{env_var_name}={env_var_value}") -def get_first_letter_case(pr_title): - pr_title = f"""{pr_title}""" +def get_first_letter_case(pr_title: str): + """Get the first letter of the pull request title and determine if it is uppercase or not. + + Parameters + ---------- + pr_title: str + The pull request title. + """ index = 0 + # Get the pull request title + pr_title = f"""{pr_title}""" + # Get the first letter of the pull request title first_letter = pr_title[index] - print(pr_title) - + # If the pull request title starts with a blank space, move to the next index + # until it finds a letter while first_letter == " ": index += 1 try: + # Set the first letter first_letter = pr_title[index] except IndexError: + # If the pull request title never finds a letter, the pull request title + # is blank print("Pull request title is blank") exit(1) + # If the first letter is lowercase, save the FIRST_LETTER environment variable + # as lowercase. Otherwise, save it as uppercase if first_letter.islower(): save_env_variable("FIRST_LETTER", "lowercase") else: save_env_variable("FIRST_LETTER", "uppercase") -def get_conventional_commit_type(pr_title): +def get_conventional_commit_type(pr_title: str): + """Get the conventional commit type from the pull request title. + + Parameters + ---------- + pr_title: str + The pull request title. + """ + # Get the pull request title pr_title = f"""{pr_title}""" + # Get the index where the first colon is found in the pull request title colon_index = pr_title.index(":") + # Get the conventional commit type from the pull request title (everything before the colon) cc_type = '"' + pr_title[:colon_index] + '"' + # Save the conventional commit type as an environment variable, CC_TYPE save_env_variable("CC_TYPE", cc_type) -def changelog_category_cc(cc_type): - # Get conventional commit type from env variable - cc_type = cc_type.lower() +def changelog_category_cc(cc_type: str): + """Get the changelog category based on the conventional commit type. - print(cc_type) + Parameters + ---------- + cc_type: str + The conventional commit type from the pull request title. + """ + # Get conventional commit type from the environment variable + cc_type = cc_type.lower() + # Dictionary whose keys are the conventional commit type and values are + # the changelog section cc_type_changelog_dict = { "feat": "added", "fix": "fixed", @@ -60,12 +101,21 @@ def changelog_category_cc(cc_type): "ci": "maintenance", } + # Get the changelog section based on the conventional commit type changelog_section = cc_type_changelog_dict[cc_type] + # Save the changelog section to the CHANGELOG_SECTION environment variable save_env_variable("CHANGELOG_SECTION", changelog_section) -def changelog_cateogry_labels(labels): +def changelog_cateogry_labels(labels: str): + """Get the changelog category based on the labels in the pull request. + + Parameters + ---------- + labels: str + String containing the labels in the pull request. + """ # Create a list of labels found in the pull request # For example, "enhancement maintenance".split() -> ["enhancement", "maintenance"] existing_labels = labels.split() @@ -82,25 +132,52 @@ def changelog_cateogry_labels(labels): "maintenance": "maintenance", } - def get_changelog_section(pr_labels, existing_labels): - """Find the changelog section corresponding to the label in the PR.""" - label_type = "" - - for key, value in pr_labels.items(): - if key in existing_labels: - label_type = value - return label_type - - # If no labels are in the PR, it goes into the miscellaneous category - label_type = "miscellaneous" - return label_type - + # Save the changelog section to the CHANGELOG_SECTION environment variable save_env_variable( "CHANGELOG_SECTION", get_changelog_section(pr_labels, existing_labels) ) -def clean_pr_title(pr_title, use_labels): +def get_changelog_section(pr_labels: dict, existing_labels: list) -> str: + """Find the changelog section corresponding to the label in the pull request. + + Parameters + ---------- + pr_labels: dict + Dictionary containing pull request labels and their corresponding changelog sections. + existing_labels: list + List of the labels that are in the pull request. + + Returns + ------- + str + The changelog section. + """ + changelog_section = "" + + # For each label key and changelog section value + for key, value in pr_labels.items(): + # If the label is in the existing_labels list + if key in existing_labels: + # Save the changelog section based on the label + changelog_section = value + return changelog_section + + # If no labels are in the PR, it goes into the miscellaneous category + changelog_section = "miscellaneous" + return changelog_section + + +def clean_pr_title(pr_title: str, use_labels: str): + """Clean the pull request title. + + Parameters + ---------- + pr_title: str + The pull request title. + use_labels: str + Whether or not to use labels to get the changelog section. + """ # Retrieve title clean_title = pr_title @@ -109,23 +186,35 @@ def clean_pr_title(pr_title, use_labels): colon_index = clean_title.index(":") clean_title = clean_title[colon_index + 1 :] - print(clean_title) - # Remove extra whitespace clean_title = clean_title.strip() # Add backslash in front of backtick and double quote clean_title = clean_title.replace("`", "\\`").replace('"', '\\"') + # Save the clean pull request title as the CLEAN_TITLE environment variable save_env_variable("CLEAN_TITLE", clean_title) -def add_towncrier_config(org_name, repo_name, web_release_notes): +def add_towncrier_config(org_name: str, repo_name: str, web_release_notes: bool): + """Append the missing towncrier information to the pyproject.toml file. + + Parameters + ---------- + org_name: str + The name of the organization. + repo_name: str + The name of the repository. + web_release_notes: bool + Whether or not the release notes are in the online documentation or the repository. + """ # Load pyproject.toml file with open("pyproject.toml", "a+") as file: config = toml.load("pyproject.toml") tool = config.get("tool", "DNE") towncrier = tool.get("towncrier", "DNE") + + # List containing changelog sections under each release changelog_sections = [ "added", "dependencies", @@ -138,67 +227,126 @@ def add_towncrier_config(org_name, repo_name, web_release_notes): # Get the package name from [tool.flit.module] flit = tool.get("flit", "DNE") - module = name = package = "" + module = name = "" if flit != "DNE": module = flit.get("module", "DNE") if module != ("DNE" or ""): name = module.get("name", "DNE") + # Dictionary containing [tool.towncrier] keys and values + towncrier_config_sections = { + "directory": '"doc/changelog.d"', + "template": '"doc/changelog.d/changelog_template.jinja"', + "filename": {"web": '"doc/source/changelog.rst"', "repo": '"CHANGELOG.md"'}, + "start_string": { + "web": '".. towncrier release notes start\\n"', + "repo": '"\\n"', + }, + "title_format": { + "web": f'"`{{version}} `_ - {{project_date}}"', + "repo": f'"## [{{version}}](https://github.com/{org_name}/{repo_name}/releases/tag/v{{version}}) - {{project_date}}"', + }, + "issue_format": { + "web": f'"`#{{issue}} `_"', + "repo": f'"[#{{issue}}](https://github.com/{org_name}/{repo_name}/pull/{{issue}})"', + }, + } + # If [tool.flit.module] name exists, create the package string if name != ("DNE" and ""): - package = f'package = "{name}"' + towncrier_config_sections["package"] = f'"{name}"' - # If the [tool.towncrier] section does not exist if towncrier == "DNE": - # Append the tool.towncrier section - file.write("\n[tool.towncrier]\n") - - # Write the package line if [tool.flit.module] name exists - if package: - file.write(f"{package}\n") - - # Write general towncrier configuration - file.write( - """directory = "doc/changelog.d" -underlines = ["", "", ""] -template = "doc/changelog.d/changelog_template.jinja"\n""" + # Write the [tool.towncrier] and [[tool.towncrier.type]] sections + write_towncrier_config_section( + file, towncrier_config_sections, web_release_notes ) - - # Write configuration for changelog.rst release notes - if web_release_notes: - file.write( - f"""filename = "doc/source/changelog.rst" -start_string = ".. towncrier release notes start\\n" -title_format = "`{{version}} `_ - {{project_date}}" -issue_format = "`#{{issue}} `_"\n""" - ) - - # Write configuration for CHANGELOG.md release notes - else: - file.write( - f"""filename = "CHANGELOG.md" -start_string = "\\n" -title_format = "## [{{version}}](https://github.com/{org_name}/{repo_name}/releases/tag/v{{version}}) - {{project_date}}" -issue_format = "[#{{issue}}](https://github.com/{org_name}/{repo_name}/pull/{{issue}})"\n""" - ) - # If [tool.towncrier] exists + write_missing_types(changelog_sections, file) else: # Get the [[tool.towncrier.type]] sections types = towncrier.get("type", "DNE") - # If the [[tool.towncrier.type]] sections exist - if types != "DNE": - for group in types: - # Remove changelog section if it exists under [[tool.towncrier.type]] so that - # only missing sections are appended to the pyproject.toml file - changelog_sections.remove(group["directory"]) - - # Write each missing section to the pyproject.toml file - for section in changelog_sections: - file.write( - f""" + # Add missing [[tool.towncrier.type]] sections and entire [tool.towncrier] section + if len(towncrier) == 1 and (types != "DNE"): + remove_existing_types(types, changelog_sections) + write_missing_types(changelog_sections, file) + write_towncrier_config_section( + file, towncrier_config_sections, web_release_notes + ) + else: + # Add missing [[tool.towncrier.type]] + remove_existing_types(types, changelog_sections) + write_missing_types(changelog_sections, file) + # Add missing lines of [tool.towncrier] section? + + +def write_towncrier_config_section( + file, towncrier_config_sections: dict, web_release_notes: bool +): + """Write the information in the [tool.towncrier] section. + + Parameters + ---------- + file: _io.TextIOWrapper + File to write to. + towncrier_config_sections: dict + Dictionary containing the [tool.towncrier] keys and values. + web_release_notes: bool + Whether or not the release notes are in the online documentation or the repository. + """ + # Append the tool.towncrier section + file.write("\n[tool.towncrier]\n") + + # For each key and value in the towncrier_config_sections dictionary + for key, value in towncrier_config_sections.items(): + # If the key has values that depend on the web_release_notes boolean + if ( + key == "filename" + or key == "start_string" + or key == "title_format" + or key == "issue_format" + ): + # Select the value based on the web_release_notes boolean + if web_release_notes: + file.write(f'{key} = {value["web"]}\n') + else: + file.write(f'{key} = {value["repo"]}\n') + else: + # Write the key and value from the towncrier_config_sections dictionary + file.write(f"{key} = {value}\n") + + +def remove_existing_types(types, changelog_sections: list): + """Remove the existing [[tool.towncrier.types]] from the changelog_sections list. + + Parameters + ---------- + types: list + List of dictionaries containing information under the [[tool.towncrier.types]] sections. + changelog_sections: list + List containing changelog sections under each release. + """ + for group in types: + # Remove changelog section if it exists under [[tool.towncrier.type]] so that + # only missing sections are appended to the pyproject.toml file + changelog_sections.remove(group["directory"]) + + +def write_missing_types(changelog_sections: list, file): + """Write the missing types in [[tool.towncrier.types]] + + Parameters + ---------- + changelog_sections: list + List containing changelog sections under each release. + file + """ + # Write each missing section to the pyproject.toml file + for section in changelog_sections: + file.write( + f""" [[tool.towncrier.type]] directory = "{section}" name = "{section.title()}" showcontent = true\n""" - ) + ) diff --git a/doc/source/doc-actions/examples/doc-changelog-basic.yml b/doc/source/doc-actions/examples/doc-changelog-basic.yml index f7a7b2e9b..649379f39 100644 --- a/doc/source/doc-actions/examples/doc-changelog-basic.yml +++ b/doc/source/doc-actions/examples/doc-changelog-basic.yml @@ -20,4 +20,9 @@ changelog-fragment: - uses: ansys/actions/doc-changelog@{{ version }} with: token: ${{ '{{ secrets.PYANSYS_CI_BOT_TOKEN }}' }} - # use-labels: true # uncomment this line to use labels instead of conventional commits + # uncomment this line to use conventional commits instead of labels + # use-conventional-commits: true + # uncomment this if your release notes are in your documentation (doc/source/changelog.rst) + # web-release-notes: true + # uncomment this if your release notes are in your repository (CHANGELOG.md) + # web-release-notes: false From 5bc1ffcb260d88072d1e5a3ecf7dbaec66fcceea Mon Sep 17 00:00:00 2001 From: klmcadams <58492561+klmcadams@users.noreply.github.com> Date: Thu, 11 Jul 2024 12:11:43 -0400 Subject: [PATCH 41/51] remove if statement --- doc-changelog/action.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/doc-changelog/action.yml b/doc-changelog/action.yml index e897e51ee..81fb1c037 100644 --- a/doc-changelog/action.yml +++ b/doc-changelog/action.yml @@ -223,10 +223,7 @@ runs: use_labels = "${{ inputs.use-labels }}" use_labels = use_labels[0].upper() + use_labels[1:] - if use_labels == "True": - clean_pr_title(pr_title, use_labels) - else: - clean_pr_title(pr_title, use_labels) + clean_pr_title(pr_title, use_labels) - name: "Append towncrier categories to pyproject.toml" env: From 8004d8507b527ae6e0b03164b503e3c63225b2e5 Mon Sep 17 00:00:00 2001 From: klmcadams <58492561+klmcadams@users.noreply.github.com> Date: Thu, 11 Jul 2024 13:40:37 -0400 Subject: [PATCH 42/51] simplify logic --- doc-changelog/action.yml | 11 ++-- doc-changelog/parse_pr_title.py | 51 ++++++++----------- .../examples/doc-changelog-basic.yml | 6 +-- 3 files changed, 27 insertions(+), 41 deletions(-) diff --git a/doc-changelog/action.yml b/doc-changelog/action.yml index 81fb1c037..86219dde0 100644 --- a/doc-changelog/action.yml +++ b/doc-changelog/action.yml @@ -79,12 +79,11 @@ inputs: default: false type: boolean - web-release-notes: + use-default-towncrier-config: description: > - Whether or not your documentation uses the release notes in - the documentation, the changelog.rst file. + Use the default towncrier configuration in the pyproject.toml file required: false - default: true + default: false type: boolean runs: @@ -239,9 +238,9 @@ runs: repo_name = ${{ env.REPO_NAME }} org_name = ${{ env.ORG_NAME }} - web_rel_notes = True if ${{ inputs.web-release-notes }} == "true" else False + default_config = True if ${{ inputs.use-default-towncrier-config }} == "true" else False - add_towncrier_config(org_name, repo_name, web_rel_notes) + add_towncrier_config(org_name, repo_name, default_config) - name: "Create and commit towncrier fragment" env: diff --git a/doc-changelog/parse_pr_title.py b/doc-changelog/parse_pr_title.py index 08aea4706..8fcaaef3b 100644 --- a/doc-changelog/parse_pr_title.py +++ b/doc-changelog/parse_pr_title.py @@ -196,7 +196,7 @@ def clean_pr_title(pr_title: str, use_labels: str): save_env_variable("CLEAN_TITLE", clean_title) -def add_towncrier_config(org_name: str, repo_name: str, web_release_notes: bool): +def add_towncrier_config(org_name: str, repo_name: str, default_config: bool): """Append the missing towncrier information to the pyproject.toml file. Parameters @@ -205,8 +205,8 @@ def add_towncrier_config(org_name: str, repo_name: str, web_release_notes: bool) The name of the organization. repo_name: str The name of the repository. - web_release_notes: bool - Whether or not the release notes are in the online documentation or the repository. + default_config: bool + Whether or not to use the default towncrier configuration for the pyproject.toml file. """ # Load pyproject.toml file with open("pyproject.toml", "a+") as file: @@ -225,14 +225,6 @@ def add_towncrier_config(org_name: str, repo_name: str, web_release_notes: bool) "test", ] - # Get the package name from [tool.flit.module] - flit = tool.get("flit", "DNE") - module = name = "" - if flit != "DNE": - module = flit.get("module", "DNE") - if module != ("DNE" or ""): - name = module.get("name", "DNE") - # Dictionary containing [tool.towncrier] keys and values towncrier_config_sections = { "directory": '"doc/changelog.d"', @@ -252,32 +244,28 @@ def add_towncrier_config(org_name: str, repo_name: str, web_release_notes: bool) }, } - # If [tool.flit.module] name exists, create the package string - if name != ("DNE" and ""): - towncrier_config_sections["package"] = f'"{name}"' + # Get the package name from [tool.flit.module] + flit = tool.get("flit", "DNE") + module = name = "" + if flit != "DNE": + module = flit.get("module", "DNE") + if module != ("DNE" or ""): + name = module.get("name", "DNE") + # If [tool.flit.module] name exists, create the package string + if name != ("DNE" and ""): + towncrier_config_sections["package"] = f'"{name}"' - if towncrier == "DNE": + if default_config: # Write the [tool.towncrier] and [[tool.towncrier.type]] sections - write_towncrier_config_section( - file, towncrier_config_sections, web_release_notes - ) + write_towncrier_config_section(file, towncrier_config_sections, True) write_missing_types(changelog_sections, file) else: # Get the [[tool.towncrier.type]] sections types = towncrier.get("type", "DNE") - - # Add missing [[tool.towncrier.type]] sections and entire [tool.towncrier] section - if len(towncrier) == 1 and (types != "DNE"): + if types != "DNE": remove_existing_types(types, changelog_sections) - write_missing_types(changelog_sections, file) - write_towncrier_config_section( - file, towncrier_config_sections, web_release_notes - ) - else: - # Add missing [[tool.towncrier.type]] - remove_existing_types(types, changelog_sections) - write_missing_types(changelog_sections, file) - # Add missing lines of [tool.towncrier] section? + # Add missing [[tool.towncrier.type]] sections + write_missing_types(changelog_sections, file) def write_towncrier_config_section( @@ -339,7 +327,8 @@ def write_missing_types(changelog_sections: list, file): ---------- changelog_sections: list List containing changelog sections under each release. - file + file: _io.TextIOWrapper + File to write to. """ # Write each missing section to the pyproject.toml file for section in changelog_sections: diff --git a/doc/source/doc-actions/examples/doc-changelog-basic.yml b/doc/source/doc-actions/examples/doc-changelog-basic.yml index 649379f39..9475ec142 100644 --- a/doc/source/doc-actions/examples/doc-changelog-basic.yml +++ b/doc/source/doc-actions/examples/doc-changelog-basic.yml @@ -22,7 +22,5 @@ changelog-fragment: token: ${{ '{{ secrets.PYANSYS_CI_BOT_TOKEN }}' }} # uncomment this line to use conventional commits instead of labels # use-conventional-commits: true - # uncomment this if your release notes are in your documentation (doc/source/changelog.rst) - # web-release-notes: true - # uncomment this if your release notes are in your repository (CHANGELOG.md) - # web-release-notes: false + # uncomment this if you don't have any towncrier configuration in your pyproject.toml file + # use-default-towncrier-config: true From b2546f2b1dfaa61898a999cb6241eb88c5863368 Mon Sep 17 00:00:00 2001 From: klmcadams <58492561+klmcadams@users.noreply.github.com> Date: Thu, 11 Jul 2024 13:50:35 -0400 Subject: [PATCH 43/51] pip install toml --- doc-changelog/action.yml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/doc-changelog/action.yml b/doc-changelog/action.yml index 86219dde0..f49c5d7cd 100644 --- a/doc-changelog/action.yml +++ b/doc-changelog/action.yml @@ -56,6 +56,13 @@ inputs: required: false type: string + toml-version: + description: > + Toml version used for retrieving the towncrier directory. + default: '0.10.2' + required: false + type: string + use-python-cache: description: > Whether to use the Python cache for installing previously downloaded @@ -81,7 +88,7 @@ inputs: use-default-towncrier-config: description: > - Use the default towncrier configuration in the pyproject.toml file + Use the default towncrier configuration in the pyproject.toml file. required: false default: false type: boolean @@ -110,7 +117,7 @@ runs: - name: "Install towncrier" shell: bash run: | - python -m pip install --upgrade pip towncrier==${{ inputs.towncrier-version }} + python -m pip install --upgrade pip towncrier==${{ inputs.towncrier-version }} toml==${{ inputs.toml-version }} - name: "Get first letter of conventional commit type" if: ${{ inputs.use-conventional-commits == 'true' }} From fc6f7ecbe5afdd42b41aaaa76168e4670efc94b1 Mon Sep 17 00:00:00 2001 From: klmcadams <58492561+klmcadams@users.noreply.github.com> Date: Thu, 11 Jul 2024 13:53:28 -0400 Subject: [PATCH 44/51] quotes around env --- doc-changelog/action.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc-changelog/action.yml b/doc-changelog/action.yml index f49c5d7cd..db2196b19 100644 --- a/doc-changelog/action.yml +++ b/doc-changelog/action.yml @@ -242,8 +242,8 @@ runs: from parse_pr_title import add_towncrier_config - repo_name = ${{ env.REPO_NAME }} - org_name = ${{ env.ORG_NAME }} + repo_name = "${{ env.REPO_NAME }}" + org_name = "${{ env.ORG_NAME }}" default_config = True if ${{ inputs.use-default-towncrier-config }} == "true" else False From 68d1da7df9af207619fec8802a04bb4340fc0799 Mon Sep 17 00:00:00 2001 From: klmcadams <58492561+klmcadams@users.noreply.github.com> Date: Thu, 11 Jul 2024 14:05:46 -0400 Subject: [PATCH 45/51] add quotes --- doc-changelog/action.yml | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/doc-changelog/action.yml b/doc-changelog/action.yml index db2196b19..694602a9e 100644 --- a/doc-changelog/action.yml +++ b/doc-changelog/action.yml @@ -232,9 +232,6 @@ runs: clean_pr_title(pr_title, use_labels) - name: "Append towncrier categories to pyproject.toml" - env: - REPO_NAME: ${{ github.event.repository.name }} - ORG_NAME: ${{ github.event.repository.owner }} shell: python run: | import sys @@ -242,10 +239,10 @@ runs: from parse_pr_title import add_towncrier_config - repo_name = "${{ env.REPO_NAME }}" - org_name = "${{ env.ORG_NAME }}" + repo_name = "${{ github.event.repository.name }}" + org_name = "${{ github.event.repository.owner }}" - default_config = True if ${{ inputs.use-default-towncrier-config }} == "true" else False + default_config = True if "${{ inputs.use-default-towncrier-config }}" == "true" else False add_towncrier_config(org_name, repo_name, default_config) From cc91e0e40efd53dfc67e780028ad0e71f5a0ba98 Mon Sep 17 00:00:00 2001 From: klmcadams <58492561+klmcadams@users.noreply.github.com> Date: Thu, 11 Jul 2024 14:12:56 -0400 Subject: [PATCH 46/51] fix repo owner? --- doc-changelog/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc-changelog/action.yml b/doc-changelog/action.yml index 694602a9e..e6f5e5e29 100644 --- a/doc-changelog/action.yml +++ b/doc-changelog/action.yml @@ -240,7 +240,7 @@ runs: from parse_pr_title import add_towncrier_config repo_name = "${{ github.event.repository.name }}" - org_name = "${{ github.event.repository.owner }}" + org_name = "${{ github.repository_owner }}" default_config = True if "${{ inputs.use-default-towncrier-config }}" == "true" else False From f616d5247b511271be1f70b258b7b86f82b90f23 Mon Sep 17 00:00:00 2001 From: klmcadams <58492561+klmcadams@users.noreply.github.com> Date: Thu, 11 Jul 2024 14:27:31 -0400 Subject: [PATCH 47/51] only write [tool.towncrier] section under certain conditions --- doc-changelog/parse_pr_title.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/doc-changelog/parse_pr_title.py b/doc-changelog/parse_pr_title.py index 8fcaaef3b..4b9b51a7c 100644 --- a/doc-changelog/parse_pr_title.py +++ b/doc-changelog/parse_pr_title.py @@ -256,8 +256,12 @@ def add_towncrier_config(org_name: str, repo_name: str, default_config: bool): towncrier_config_sections["package"] = f'"{name}"' if default_config: - # Write the [tool.towncrier] and [[tool.towncrier.type]] sections - write_towncrier_config_section(file, towncrier_config_sections, True) + # If there is no towncrier configuration information or if [[tool.towncrier.type]] + # is the only towncrier information in the pyproject.toml file + if towncrier == "DNE" or len(towncrier) == 1: + # Write the [tool.towncrier] section + write_towncrier_config_section(file, towncrier_config_sections, True) + # Write the [[tool.towncrier.type]] sections write_missing_types(changelog_sections, file) else: # Get the [[tool.towncrier.type]] sections From f3832c71a9d98bfd594411cbb6f040b39e161373 Mon Sep 17 00:00:00 2001 From: klmcadams <58492561+klmcadams@users.noreply.github.com> Date: Thu, 11 Jul 2024 14:40:39 -0400 Subject: [PATCH 48/51] replace use-labels with use-conventional-commits --- doc-changelog/action.yml | 18 +++++------------- doc-changelog/parse_pr_title.py | 10 +++++----- 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/doc-changelog/action.yml b/doc-changelog/action.yml index e6f5e5e29..a99aa3f96 100644 --- a/doc-changelog/action.yml +++ b/doc-changelog/action.yml @@ -72,16 +72,9 @@ inputs: default: true type: boolean - use-labels: - description: > - Use labels to cateogrize towncrier fragments. - required: false - default: true - type: boolean - use-conventional-commits: description: > - Use conventional commits to categorize towncrier fragments. + Use conventional commits to cateogrize towncrier fragments. required: false default: false type: boolean @@ -161,7 +154,7 @@ runs: get_conventional_commit_type(pr_title) - name: "Get labels in the pull request" - if: ${{ inputs.use-labels == 'true' }} + if: ${{ inputs.use-conventional-commits == 'false' }} env: OWNER: ${{ github.repository_owner }} REPO_NAME: ${{ github.event.repository.name }} @@ -189,7 +182,7 @@ runs: changelog_category_cc(cc_type) - name: "Set PR label environment variable" - if: ${{ inputs.use-labels == 'true' }} + if: ${{ inputs.use-conventional-commits == 'false' }} shell: python run: | import sys @@ -226,10 +219,9 @@ runs: from parse_pr_title import clean_pr_title pr_title = """${{ env.PR_TITLE }}""" - use_labels = "${{ inputs.use-labels }}" - use_labels = use_labels[0].upper() + use_labels[1:] + use_cc = True if "${{ inputs.use-conventional-commits }}" == "true" else False - clean_pr_title(pr_title, use_labels) + clean_pr_title(pr_title, use_cc) - name: "Append towncrier categories to pyproject.toml" shell: python diff --git a/doc-changelog/parse_pr_title.py b/doc-changelog/parse_pr_title.py index 4b9b51a7c..fc63393af 100644 --- a/doc-changelog/parse_pr_title.py +++ b/doc-changelog/parse_pr_title.py @@ -168,21 +168,21 @@ def get_changelog_section(pr_labels: dict, existing_labels: list) -> str: return changelog_section -def clean_pr_title(pr_title: str, use_labels: str): +def clean_pr_title(pr_title: str, use_cc: str): """Clean the pull request title. Parameters ---------- pr_title: str The pull request title. - use_labels: str - Whether or not to use labels to get the changelog section. + use_cc: str + Whether or not to use conventional commits to get the changelog section. """ # Retrieve title clean_title = pr_title - # If not using label, remove conventional commit type from title - if use_labels == "False": + # If using conventional commits, remove it from title + if use_cc: colon_index = clean_title.index(":") clean_title = clean_title[colon_index + 1 :] From c9eff2dc5b7443e78b248149391416aa78583029 Mon Sep 17 00:00:00 2001 From: klmcadams <58492561+klmcadams@users.noreply.github.com> Date: Thu, 11 Jul 2024 14:44:10 -0400 Subject: [PATCH 49/51] always check for existing types --- doc-changelog/parse_pr_title.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/doc-changelog/parse_pr_title.py b/doc-changelog/parse_pr_title.py index fc63393af..043fc8309 100644 --- a/doc-changelog/parse_pr_title.py +++ b/doc-changelog/parse_pr_title.py @@ -261,15 +261,13 @@ def add_towncrier_config(org_name: str, repo_name: str, default_config: bool): if towncrier == "DNE" or len(towncrier) == 1: # Write the [tool.towncrier] section write_towncrier_config_section(file, towncrier_config_sections, True) - # Write the [[tool.towncrier.type]] sections - write_missing_types(changelog_sections, file) - else: - # Get the [[tool.towncrier.type]] sections - types = towncrier.get("type", "DNE") - if types != "DNE": - remove_existing_types(types, changelog_sections) - # Add missing [[tool.towncrier.type]] sections - write_missing_types(changelog_sections, file) + + # Get the [[tool.towncrier.type]] sections + types = towncrier.get("type", "DNE") + if types != "DNE": + remove_existing_types(types, changelog_sections) + # Add missing [[tool.towncrier.type]] sections + write_missing_types(changelog_sections, file) def write_towncrier_config_section( From 9b34ce0680255f9f941b5bf0953261becbba296b Mon Sep 17 00:00:00 2001 From: klmcadams <58492561+klmcadams@users.noreply.github.com> Date: Thu, 11 Jul 2024 14:48:54 -0400 Subject: [PATCH 50/51] check if towncrier is not DNE --- doc-changelog/parse_pr_title.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/doc-changelog/parse_pr_title.py b/doc-changelog/parse_pr_title.py index 043fc8309..73cd7e7ff 100644 --- a/doc-changelog/parse_pr_title.py +++ b/doc-changelog/parse_pr_title.py @@ -262,10 +262,12 @@ def add_towncrier_config(org_name: str, repo_name: str, default_config: bool): # Write the [tool.towncrier] section write_towncrier_config_section(file, towncrier_config_sections, True) - # Get the [[tool.towncrier.type]] sections - types = towncrier.get("type", "DNE") - if types != "DNE": - remove_existing_types(types, changelog_sections) + if towncrier != "DNE": + # Get the existing [[tool.towncrier.type]] sections + types = towncrier.get("type", "DNE") + if types != "DNE": + remove_existing_types(types, changelog_sections) + # Add missing [[tool.towncrier.type]] sections write_missing_types(changelog_sections, file) From 14b9fbadecb374053c8160274b4a3158773e3dda Mon Sep 17 00:00:00 2001 From: Kerry McAdams <58492561+klmcadams@users.noreply.github.com> Date: Thu, 1 Aug 2024 09:51:22 -0400 Subject: [PATCH 51/51] feat: doc-changelog allow breaking changes symbol in conventional commit type (#529) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Roberto Pastor Muela <37798125+RobPasMue@users.noreply.github.com> Co-authored-by: Sébastien Morais <146729917+SMoraisAnsys@users.noreply.github.com> --- doc-changelog/parse_pr_title.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/doc-changelog/parse_pr_title.py b/doc-changelog/parse_pr_title.py index 73cd7e7ff..a6d1b28d8 100644 --- a/doc-changelog/parse_pr_title.py +++ b/doc-changelog/parse_pr_title.py @@ -101,8 +101,11 @@ def changelog_category_cc(cc_type: str): "ci": "maintenance", } - # Get the changelog section based on the conventional commit type - changelog_section = cc_type_changelog_dict[cc_type] + for key, value in cc_type_changelog_dict.items(): + if key in cc_type: + # Get the changelog section based on the conventional commit type + changelog_section = value + break # Save the changelog section to the CHANGELOG_SECTION environment variable save_env_variable("CHANGELOG_SECTION", changelog_section) @@ -308,7 +311,7 @@ def write_towncrier_config_section( file.write(f"{key} = {value}\n") -def remove_existing_types(types, changelog_sections: list): +def remove_existing_types(types: list, changelog_sections: list): """Remove the existing [[tool.towncrier.types]] from the changelog_sections list. Parameters @@ -321,7 +324,9 @@ def remove_existing_types(types, changelog_sections: list): for group in types: # Remove changelog section if it exists under [[tool.towncrier.type]] so that # only missing sections are appended to the pyproject.toml file - changelog_sections.remove(group["directory"]) + section = group.get("directory") + if section in changelog_sections: + changelog_sections.remove(section) def write_missing_types(changelog_sections: list, file):