Sync shared snapshot from df68167
This commit is contained in:
1 parent
588ef139a6
commit
06efc832ca
79 files changed
+10035
-3
No files matched your search
@@ -0,0 +1,74 @@
|
||||
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: 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[@]}"
|
||||
Reference in new issue
Block a user