Skip to content

Add support for backtick quotes and multi-quote strings with escaping (fixes #142) #110

Add support for backtick quotes and multi-quote strings with escaping (fixes #142)

Add support for backtick quotes and multi-quote strings with escaping (fixes #142) #110

Workflow file for this run

name: python
on:
push:
branches: main
paths:
- 'python/**'
- '.github/workflows/python.yml'
pull_request:
paths:
- 'python/**'
- '.github/workflows/python.yml'
env:
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
defaults:
run:
working-directory: python
jobs:
findChangedPythonFiles:
runs-on: ubuntu-latest
timeout-minutes: 10
outputs:
isPythonFilesChanged: ${{ steps.setIsPythonFilesChangedOutput.outputs.isPythonFilesChanged }}
steps:
- uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v47
- name: Set output isPythonFilesChanged
id: setIsPythonFilesChangedOutput
run: |
isPythonFilesChanged='false'
echo "Changed files: ${{ steps.changed-files.outputs.all_changed_files }}"
for changedFile in ${{ steps.changed-files.outputs.all_changed_files }}; do
if [[ $changedFile == python/*.py ]] || [[ $changedFile == python/pyproject.toml ]] || [[ $changedFile == python/setup.py ]] || [[ $changedFile == python/* ]] || [[ $changedFile == .github/workflows/python.yml ]]; then
echo "isPythonFilesChanged='true'"
isPythonFilesChanged='true'
break
fi
done
echo "isPythonFilesChanged=${isPythonFilesChanged}" >> $GITHUB_OUTPUT
echo "isPythonFilesChanged: ${isPythonFilesChanged}"
lint:
needs: [findChangedPythonFiles]
if: ${{ needs.findChangedPythonFiles.outputs.isPythonFilesChanged == 'true' }}
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v5
with:
submodules: true
- name: Set up Python 3.13
uses: actions/setup-python@v6
with:
python-version: '3.13'
- name: Install linting tools
run: |
python -m pip install --upgrade pip
pip install black isort flake8
- name: Check formatting with Black
run: black --check --diff .
- name: Check import sorting with isort
run: isort --check-only --diff .
- name: Lint with flake8
run: flake8 --max-line-length=120
test:
needs: [findChangedPythonFiles, lint]
if: ${{ needs.findChangedPythonFiles.outputs.isPythonFilesChanged == 'true' }}
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v5
with:
submodules: true
- name: Set up Python 3.13
uses: actions/setup-python@v6
with:
python-version: '3.13'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytest pytest-timeout build twine
- name: Build package
run: python -m build
- name: Run tests
run: pytest -v
publishToPyPI:
needs: [test, findChangedPythonFiles]
if: ${{ needs.findChangedPythonFiles.outputs.isPythonFilesChanged == 'true' && github.event_name == 'push' && github.ref == 'refs/heads/main' }}
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v5
with:
submodules: true
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.13'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build twine
- name: Build package
run: python -m build
- name: Check if version already published
id: version-check
run: |
PACKAGE_VERSION=$(python -c "import tomli; f = open('pyproject.toml', 'rb'); data = tomli.load(f); print(data['project']['version'])" 2>/dev/null || grep "^version" pyproject.toml | sed 's/version = "\(.*\)"/\1/')
PACKAGE_NAME=$(python -c "import tomli; f = open('pyproject.toml', 'rb'); data = tomli.load(f); print(data['project']['name'])" 2>/dev/null || grep "^name" pyproject.toml | sed 's/name = "\(.*\)"/\1/')
echo "Package: $PACKAGE_NAME@$PACKAGE_VERSION"
# Check if version exists on PyPI
if pip index versions $PACKAGE_NAME 2>/dev/null | grep -q "$PACKAGE_VERSION"; then
echo "Version $PACKAGE_VERSION already exists on PyPI"
echo "should_publish=false" >> $GITHUB_OUTPUT
else
echo "Version $PACKAGE_VERSION does not exist on PyPI"
echo "should_publish=true" >> $GITHUB_OUTPUT
fi
- name: Publish to PyPI
if: steps.version-check.outputs.should_publish == 'true'
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
run: |
twine upload dist/*
publishRelease:
runs-on: ubuntu-latest
timeout-minutes: 10
needs: [publishToPyPI]
if: ${{ needs.findChangedPythonFiles.outputs.isPythonFilesChanged == 'true' && needs.publishToPyPI.result == 'success' && github.event_name == 'push' && github.ref == 'refs/heads/main' }}
steps:
- uses: actions/checkout@v5
with:
submodules: true
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.13'
- name: Check if GitHub release already exists
id: release-check
run: |
PACKAGE_VERSION=$(grep "^version" pyproject.toml | sed 's/version = "\(.*\)"/\1/')
TAG_NAME="python_$PACKAGE_VERSION"
echo "Checking if release $TAG_NAME already exists"
# Check if release exists
if gh release view "$TAG_NAME" >/dev/null 2>&1; then
echo "Release $TAG_NAME already exists"
echo "should_create_release=false" >> $GITHUB_OUTPUT
else
echo "Release $TAG_NAME does not exist"
echo "should_create_release=true" >> $GITHUB_OUTPUT
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create GitHub release
if: steps.release-check.outputs.should_create_release == 'true'
run: |
PACKAGE_VERSION=$(grep "^version" pyproject.toml | sed 's/version = "\(.*\)"/\1/')
PACKAGE_NAME=$(grep "^name" pyproject.toml | sed 's/name = "\(.*\)"/\1/')
# Create release with consistent tag format: python_version
gh release create "python_${PACKAGE_VERSION}" \
--title "[Python] $PACKAGE_VERSION" \
--notes "https://pypi.org/project/$PACKAGE_NAME/"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}