91 lines
3.1 KiB
YAML
91 lines
3.1 KiB
YAML
name: Publish
|
|
|
|
on:
|
|
push:
|
|
tags:
|
|
- "foreignthon-v*"
|
|
- "foreignthon-*-v*"
|
|
|
|
jobs:
|
|
publish:
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Set up Python
|
|
uses: actions/setup-python@v5
|
|
with:
|
|
python-version: "3.11"
|
|
|
|
- name: Install build tools
|
|
run: pip install build twine
|
|
|
|
- name: Determine what to build
|
|
id: target
|
|
run: |
|
|
TAG=${GITHUB_REF#refs/tags/}
|
|
echo "Full tag: $TAG"
|
|
|
|
if [[ "$TAG" == "foreignthon-v"* ]]; then
|
|
# Core package: foreignthon-v0.2.0
|
|
echo "type=core" >> $GITHUB_OUTPUT
|
|
echo "path=packages/foreignthon" >> $GITHUB_OUTPUT
|
|
echo "name=foreignthon" >> $GITHUB_OUTPUT
|
|
elif [[ "$TAG" == "foreignthon-"*"-v"* ]]; then
|
|
# Lang pack: foreignthon-es-v0.1.0 → lang code is "es"
|
|
LANG=$(echo $TAG | sed 's/foreignthon-\(.*\)-v.*/\1/')
|
|
echo "type=lang" >> $GITHUB_OUTPUT
|
|
echo "path=packages/langs/$LANG" >> $GITHUB_OUTPUT
|
|
echo "name=foreignthon-$LANG" >> $GITHUB_OUTPUT
|
|
fi
|
|
|
|
- name: Build package
|
|
run: python -m build ${{ steps.target.outputs.path }}
|
|
|
|
- name: Publish to PyPI
|
|
env:
|
|
TWINE_USERNAME: __token__
|
|
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
|
|
run: twine upload --skip-existing ${{ steps.target.outputs.path }}/dist/*
|
|
|
|
- name: Create Gitea release with assets
|
|
env:
|
|
GIT_RELEASE_TOKEN: ${{ secrets.GIT_RELEASE_TOKEN }}
|
|
run: |
|
|
TAG=${GITHUB_REF#refs/tags/}
|
|
|
|
EXISTING=$(curl -s \
|
|
-H "Authorization: token $GIT_RELEASE_TOKEN" \
|
|
"${{ github.server_url }}/api/v1/repos/${{ github.repository }}/releases/tags/$TAG")
|
|
EXISTING_ID=$(echo $EXISTING | python -c \
|
|
"import sys,json; d=json.load(sys.stdin); print(d.get('id',''))" 2>/dev/null || echo "")
|
|
|
|
if [ -n "$EXISTING_ID" ]; then
|
|
curl -s -X DELETE \
|
|
-H "Authorization: token $GIT_RELEASE_TOKEN" \
|
|
"${{ github.server_url }}/api/v1/repos/${{ github.repository }}/releases/$EXISTING_ID"
|
|
fi
|
|
|
|
RELEASE=$(curl -s -X POST \
|
|
-H "Authorization: token $GIT_RELEASE_TOKEN" \
|
|
-H "Content-Type: application/json" \
|
|
-d "{
|
|
\"tag_name\": \"$TAG\",
|
|
\"name\": \"${{ steps.target.outputs.name }} ${TAG##*-v}\",
|
|
\"body\": \"Release of ${{ steps.target.outputs.name }} ${TAG##*-v}\",
|
|
\"draft\": false,
|
|
\"prerelease\": false
|
|
}" \
|
|
"${{ github.server_url }}/api/v1/repos/${{ github.repository }}/releases")
|
|
|
|
RELEASE_ID=$(echo $RELEASE | python -c "import sys,json; print(json.load(sys.stdin)['id'])")
|
|
|
|
for FILE in ${{ steps.target.outputs.path }}/dist/*; do
|
|
echo "Uploading $FILE"
|
|
curl -s -X POST \
|
|
-H "Authorization: token $GIT_RELEASE_TOKEN" \
|
|
-F "attachment=@$FILE" \
|
|
"${{ github.server_url }}/api/v1/repos/${{ github.repository }}/releases/$RELEASE_ID/assets"
|
|
done
|