Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: doc-changelog conventional commits #515

Merged
merged 53 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from 50 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
c98b8b2
test conventional commits
klmcadams Jul 5, 2024
2f30057
reorder conventional commit checks
klmcadams Jul 5, 2024
5806c13
remove failure condition
klmcadams Jul 5, 2024
6967d44
check outcomes of steps
klmcadams Jul 5, 2024
f4feb38
add shell line
klmcadams Jul 5, 2024
a4668e3
set changelog section based on conventional commit type
klmcadams Jul 5, 2024
54b3bef
add quotes around pr_title
klmcadams Jul 5, 2024
05c6fe7
add print statements, fix syntax, and make cc_type lowercase
klmcadams Jul 5, 2024
184952d
fix cc_type?
klmcadams Jul 5, 2024
ece8be8
double quotes around cc_type env var
klmcadams Jul 5, 2024
a54e98c
fix quotes
klmcadams Jul 5, 2024
026b5b8
fix boolean
klmcadams Jul 5, 2024
eed2cb3
move quotes
klmcadams Jul 5, 2024
58f8eaa
call env var directly
klmcadams Jul 5, 2024
101b42c
double curly brackets
klmcadams Jul 5, 2024
3e3b9e9
test
klmcadams Jul 5, 2024
c9032c0
use cut command instead
klmcadams Jul 5, 2024
3283fd1
pr title directly in bash
klmcadams Jul 5, 2024
9c497e7
change bash to python for the env step
klmcadams Jul 5, 2024
98f412a
change to colon_index
klmcadams Jul 5, 2024
760cc02
wrap in double quotes
klmcadams Jul 5, 2024
c077b26
wrap string in bool
klmcadams Jul 5, 2024
6539c90
use colon_index
klmcadams Jul 5, 2024
6c77a94
add print statements
klmcadams Jul 5, 2024
e121d16
remove print statements
klmcadams Jul 5, 2024
a29eb8d
remove colon
klmcadams Jul 5, 2024
502cbc4
update sections and doc-changelog docs
klmcadams Jul 8, 2024
07b2b52
add use-labels to doc-changelog example yml file
klmcadams Jul 8, 2024
32c6eff
use python script in action
klmcadams Jul 9, 2024
e825200
add backslashes to pr_title
klmcadams Jul 9, 2024
026c3b3
import os
klmcadams Jul 9, 2024
e53b485
import functions from python script
klmcadams Jul 9, 2024
3ffa3fe
add doc-changelog to path
klmcadams Jul 9, 2024
127fda5
add sys path to all python sections
klmcadams Jul 9, 2024
92a7169
remove quotes around labels and cc_type
klmcadams Jul 9, 2024
f8a05ff
fix import statement
klmcadams Jul 9, 2024
b09e253
add quotes around use_labels
klmcadams Jul 9, 2024
6090532
remove argparse
klmcadams Jul 9, 2024
a8e5c6c
add towncrier config template, use-conventional-commits, and web-rele…
klmcadams Jul 10, 2024
b950aaa
add docstrings & separate function into smaller functions
klmcadams Jul 11, 2024
5bc1ffc
remove if statement
klmcadams Jul 11, 2024
8004d85
simplify logic
klmcadams Jul 11, 2024
b2546f2
pip install toml
klmcadams Jul 11, 2024
fc6f7ec
quotes around env
klmcadams Jul 11, 2024
68d1da7
add quotes
klmcadams Jul 11, 2024
cc91e0e
fix repo owner?
klmcadams Jul 11, 2024
f616d52
only write [tool.towncrier] section under certain conditions
klmcadams Jul 11, 2024
f3832c7
replace use-labels with use-conventional-commits
klmcadams Jul 11, 2024
c9eff2d
always check for existing types
klmcadams Jul 11, 2024
9b34ce0
check if towncrier is not DNE
klmcadams Jul 11, 2024
c67525c
Merge branch 'main' into feat/doc-changelog-cc
klmcadams Jul 29, 2024
9b98932
Merge branch 'main' into feat/doc-changelog-cc
RobPasMue Jul 31, 2024
14b9fba
feat: doc-changelog allow breaking changes symbol in conventional com…
klmcadams Aug 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
153 changes: 104 additions & 49 deletions doc-changelog/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -65,6 +72,20 @@ inputs:
default: true
type: boolean

use-conventional-commits:
description: >
Use conventional commits to cateogrize towncrier fragments.
required: false
default: false
type: boolean

use-default-towncrier-config:
description: >
Use the default towncrier configuration in the pyproject.toml file.
required: false
default: false
type: boolean

runs:
using: "composite"
steps:
Expand All @@ -89,9 +110,51 @@ 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' }}
env:
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_first_letter_case

pr_title = """${{ env.PR_TITLE }}"""
get_first_letter_case(pr_title)
SMoraisAnsys marked this conversation as resolved.
Show resolved Hide resolved

- name: "Check pull-request title follows conventional commits style"
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: ${{ (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-conventional-commits == 'true' }}
env:
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 }}"""
get_conventional_commit_type(pr_title)

- name: "Get labels in the pull request"
if: ${{ inputs.use-conventional-commits == 'false' }}
env:
OWNER: ${{ github.repository_owner }}
REPO_NAME: ${{ github.event.repository.name }}
Expand All @@ -106,44 +169,29 @@ runs:
# For example, LABELS="enhancement maintenance"
echo LABELS='"'$pr_labels'"' >> $GITHUB_ENV

- name: "Set CHANGELOG category based on conventional commit type"
if: ${{ inputs.use-conventional-commits == 'true' }}
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 }}
changelog_category_cc(cc_type)

- name: "Set PR label environment variable"
if: ${{ inputs.use-conventional-commits == 'false' }}
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)}")
import sys
sys.path.insert(1, '${{ github.action_path }}/../doc-changelog/')

klmcadams marked this conversation as resolved.
Show resolved Hide resolved
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:
Expand All @@ -165,23 +213,30 @@ runs:
PR_TITLE: ${{ github.event.pull_request.title }}
shell: python
run: |
import os
import sys
sys.path.insert(1, '${{ github.action_path }}/../doc-changelog/')

# Retrieve title
clean_title = os.getenv('PR_TITLE')
from parse_pr_title import clean_pr_title

pr_title = """${{ env.PR_TITLE }}"""
use_cc = True if "${{ inputs.use-conventional-commits }}" == "true" else False

clean_pr_title(pr_title, use_cc)

- name: "Append towncrier categories to pyproject.toml"
shell: python
run: |
import sys
sys.path.insert(1, '${{ github.action_path }}/../doc-changelog/')

# Remove extra whitespace
clean_title = clean_title.strip()
from parse_pr_title import add_towncrier_config

# Add backslash in front of backtick and double quote
clean_title = clean_title.replace("`", "\`").replace('"', '\\"')
repo_name = "${{ github.event.repository.name }}"
org_name = "${{ github.repository_owner }}"

# Get the GITHUB_ENV variable
github_env = os.getenv('GITHUB_ENV')
default_config = True if "${{ inputs.use-default-towncrier-config }}" == "true" else False

# Append the CLEAN_TITLE with its value to GITHUB_ENV
with open(github_env, "a") as f:
f.write(f"CLEAN_TITLE={clean_title}")
add_towncrier_config(org_name, repo_name, default_config)

- name: "Create and commit towncrier fragment"
env:
Expand All @@ -191,7 +246,7 @@ runs:
run: |
# Changelog fragment file in the following format
# For example, 20.added.md
fragment="${{ env.PR_NUMBER }}.${{ env.PR_LABEL }}.md"
fragment="${{ env.PR_NUMBER }}.${{ env.CHANGELOG_SECTION }}.md"

# Create changelog fragment with towncrier
# Fragment file contains the title of the PR
Expand Down
Loading
Loading