Add CI workflow for Python build + publish

This commit is contained in:
Justin Spahr-Summers 2024-11-21 20:52:40 +00:00
commit d144a53b25
No known key found for this signature in database
2 changed files with 82 additions and 0 deletions

80
.github/workflows/python.yml vendored Normal file
View file

@ -0,0 +1,80 @@
name: Python
on:
push:
branches:
- main
pull_request:
release:
types: [published]
jobs:
detect-packages:
runs-on: ubuntu-latest
outputs:
packages: ${{ steps.find-packages.outputs.packages }}
steps:
- uses: actions/checkout@v4
- name: Find Python packages
id: find-packages
run: |
PACKAGES=$(find src -name pyproject.toml -exec dirname {} \; | jq -R -s -c 'split("\n")[:-1]')
echo "packages=$PACKAGES" >> $GITHUB_OUTPUT
build:
needs: [detect-packages]
strategy:
matrix:
package: ${{ fromJson(needs.detect-packages.outputs.packages) }}
name: Build ${{ matrix.package }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v3
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version-file: "${{ matrix.package }}/.python-version"
- name: Install dependencies
working-directory: ${{ matrix.package }}
run: uv sync --frozen --all-extras --dev
- name: Run pyright
working-directory: ${{ matrix.package }}
run: uv run --frozen pyright
- name: Build package
working-directory: ${{ matrix.package }}
run: uv build
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: dist-${{ matrix.package }}
path: ${{ matrix.package }}/dist/
publish:
needs: [build, detect-packages]
strategy:
matrix:
package: ${{ fromJson(needs.detect-packages.outputs.packages) }}
name: Publish ${{ matrix.package }}
runs-on: ubuntu-latest
environment: release
permissions:
id-token: write # Required for trusted publishing
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: dist-${{ matrix.package }}
path: dist/
- name: Publish package to PyPI
uses: pypa/gh-action-pypi-publish@release/v1

49
.github/workflows/typescript.yml vendored Normal file
View file

@ -0,0 +1,49 @@
name: TypeScript
on:
push:
branches:
- main
pull_request:
release:
types: [published]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 18
cache: npm
- run: npm ci
- run: npm run build
publish:
runs-on: ubuntu-latest
if: github.event_name == 'release'
environment: release
needs: build
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 18
cache: npm
registry-url: "https://registry.npmjs.org"
- run: npm ci
# TODO: Add --provenance once the repo is public
- run: npm run publish-all
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}