- Add lint, formatting, vet, and publish workflow checks - Run Go database tests with PostgreSQL and add Java tests - Make consumer sync opt-in; update docs and Go dependency
82 lines
3.1 KiB
YAML
82 lines
3.1 KiB
YAML
name: Publish Python package
|
|
|
|
on:
|
|
push:
|
|
tags:
|
|
- 'v*'
|
|
release:
|
|
types:
|
|
- published
|
|
|
|
jobs:
|
|
publish:
|
|
name: Publish shared Python package
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: read
|
|
steps:
|
|
- name: Checkout source
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Set up Python
|
|
uses: actions/setup-python@v5
|
|
with:
|
|
python-version: '3.12'
|
|
|
|
- name: Run the lint and test checks that gate pull requests
|
|
run: |
|
|
set -euo pipefail
|
|
python -m pip install --disable-pip-version-check --upgrade pip ruff -e "packages/python-backend[fastapi]"
|
|
ruff check packages/python-backend/src packages/python-backend/tests
|
|
python -m unittest discover -s packages/python-backend/tests -p 'test_*.py'
|
|
|
|
- name: Build and publish package
|
|
env:
|
|
PACKAGE_REGISTRY_USERNAME: ${{ secrets.PACKAGE_REGISTRY_USERNAME }}
|
|
PACKAGE_REGISTRY_TOKEN: ${{ secrets.PACKAGE_REGISTRY_TOKEN }}
|
|
TWINE_REPOSITORY_URL: https://repos.gfranz.ch/api/packages/Gabriel20xx/pypi
|
|
run: |
|
|
set -euo pipefail
|
|
if [ -z "$PACKAGE_REGISTRY_USERNAME" ] || [ -z "$PACKAGE_REGISTRY_TOKEN" ]; then
|
|
echo 'PACKAGE_REGISTRY_USERNAME and PACKAGE_REGISTRY_TOKEN secrets are required.' >&2
|
|
exit 1
|
|
fi
|
|
python -m pip install --disable-pip-version-check --no-cache-dir build twine
|
|
package_directory="$RUNNER_TEMP/gitea-pypi-package"
|
|
python -m build packages/python-backend --outdir "$package_directory"
|
|
package_index_url="${TWINE_REPOSITORY_URL%/}/simple/gabriel20xx-shared-backend/"
|
|
package_index_file="$(mktemp)"
|
|
package_index_status="$(curl --silent --show-error --fail-with-body \
|
|
--user "$PACKAGE_REGISTRY_USERNAME:$PACKAGE_REGISTRY_TOKEN" \
|
|
--output "$package_index_file" \
|
|
--write-out '%{http_code}' \
|
|
"$package_index_url" || true)"
|
|
package_files=("$package_directory"/*)
|
|
files_to_upload=()
|
|
case "$package_index_status" in
|
|
200)
|
|
for package_file in "${package_files[@]}"; do
|
|
if ! grep -Fq "$(basename "$package_file")" "$package_index_file"; then
|
|
files_to_upload+=("$package_file")
|
|
fi
|
|
done
|
|
;;
|
|
404)
|
|
files_to_upload=("${package_files[@]}")
|
|
;;
|
|
*)
|
|
cat "$package_index_file" >&2
|
|
echo "Gitea PyPI package lookup failed with HTTP status $package_index_status." >&2
|
|
exit 1
|
|
;;
|
|
esac
|
|
if [ "${#files_to_upload[@]}" -eq 0 ]; then
|
|
echo 'Python package version already exists with all build artifacts; leaving it unchanged.'
|
|
exit 0
|
|
fi
|
|
TWINE_USERNAME="$PACKAGE_REGISTRY_USERNAME" \
|
|
TWINE_PASSWORD="$PACKAGE_REGISTRY_TOKEN" \
|
|
python -m twine upload --non-interactive \
|
|
--repository-url "$TWINE_REPOSITORY_URL" \
|
|
"${files_to_upload[@]}"
|