Skip to content

Clean up package structure + add new update functionality #39

Clean up package structure + add new update functionality

Clean up package structure + add new update functionality #39

# This workflow will upload a Python Package using Twine when a release is created
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
name: Upload Python Package
on:
release:
types: [published]
pull_request:
permissions:
contents: read
id-token: write
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: "3.10"
- name: Install uv
uses: astral-sh/setup-uv@v5
with:
enable-cache: true
cache-dependency-glob: uv.lock
- name: Update version in pyproject.toml
run: |
echo "Updating version in pyproject.toml"
LAST_RELEASE=$(pip index \
-i https://test.pypi.org/simple/ \
versions adaptive-cards-py 2>/dev/null \
| egrep -o '([0-9]+\.){2}[0-9]+' | head -n 1)
NEW_RELEASE=$(echo "$LAST_RELEASE" | awk -F. -v OFS=. '{$NF += 1; print}')
sed -i "s/version = \".*\"/version = \"${NEW_RELEASE}\"/" pyproject.toml
if: github.event_name == 'pull_request'
- name: Update version in pyproject.toml
run: |
echo "Updating version in pyproject.toml"
TAG_NAME=${GITHUB_REF##*/} # Get the tag name from GITHUB_REF
# Optionally, you may want to sanitize TAG_NAME (remove 'v' prefix, etc.)
sed -i "s/version = \".*\"/version = \"${TAG_NAME}\"/" pyproject.toml
if: github.event_name == 'release'
- name: Build package
run: uv build
- uses: actions/upload-artifact@v4
with:
name: build-artifacts
path: dist/
deploy-test:
if: github.event_name == 'pull_request'
needs: build
runs-on: ubuntu-latest
environment: test
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: "3.10"
- name: Install uv
uses: astral-sh/setup-uv@v5
with:
enable-cache: true
cache-dependency-glob: uv.lock
- uses: actions/download-artifact@v4
with:
name: build-artifacts
path: dist/
- name: Publish package
run: |
cat pyproject.toml
uv publish \
--check-url https://test.pypi.org/simple/ \
--publish-url https://test.pypi.org/legacy/ \
--trusted-publishing always
deploy-release:
if: github.event_name == 'release'
needs: build
runs-on: ubuntu-latest
environment: release
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: "3.10"
- name: Install uv
uses: astral-sh/setup-uv@v5
with:
enable-cache: true
cache-dependency-glob: uv.lock
- uses: actions/download-artifact@v4
with:
name: build-artifacts
path: dist/
- name: Publish package
run: uv publish --trusted-publishing always