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

fix: allow backtick, single, and double quotes for PR titles in the doc-changelog action #484

Merged
merged 16 commits into from
May 8, 2024
Merged
29 changes: 24 additions & 5 deletions doc-changelog/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -160,23 +160,42 @@ runs:
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('"', '\\"')
klmcadams marked this conversation as resolved.
Show resolved Hide resolved

# 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_TITLE: '${{ github.event.pull_request.title }}'
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"

# Remove extra whitespace from PR title
clean_title=$(echo '${{ env.PR_TITLE }}' | xargs)

# Create changelog fragment with towncrier
# Fragment file contains the title of the PR
towncrier create -c "$clean_title" $fragment
towncrier create -c "${{ env.CLEAN_TITLE }}" $fragment

# Configure git username & email
git config user.name 'pyansys-ci-bot'
Expand Down
Loading