Compare commits
2 Commits
0cac2e0a47
...
0.2.3
| Author | SHA1 | Date | |
|---|---|---|---|
| 178496582c | |||
| b4c4cec883 |
70
.gitea/workflows/release.yml
Normal file
70
.gitea/workflows/release.yml
Normal file
@ -0,0 +1,70 @@
|
||||
name: Release
|
||||
|
||||
on:
|
||||
push:
|
||||
tags: ["*"]
|
||||
|
||||
jobs:
|
||||
release:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Python
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: "3.13"
|
||||
|
||||
- name: Install build
|
||||
run: python -m pip install --upgrade pip build
|
||||
|
||||
- name: Verify tag matches package version
|
||||
run: |
|
||||
set -euo pipefail
|
||||
VERSION="${{ gitea.ref_name }}"
|
||||
PKG_VERSION=$(python -c "import configparser; c = configparser.ConfigParser(); c.read('setup.cfg'); print(c['metadata']['version'].strip())")
|
||||
echo "Tag: ${VERSION}, setup.cfg: ${PKG_VERSION}"
|
||||
test "${VERSION}" = "${PKG_VERSION}"
|
||||
|
||||
- name: Build sdist and wheel
|
||||
run: python -m build
|
||||
|
||||
- name: Publish to Gitea release
|
||||
env:
|
||||
GITEA_TOKEN: ${{ secrets.GITEA }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
VERSION="${{ gitea.ref_name }}"
|
||||
API="http://gitea.service:3000/api/v1/repos/${{ gitea.repository }}"
|
||||
AUTH="Authorization: token ${GITEA_TOKEN}"
|
||||
|
||||
RELEASE_ID=$(curl -sf "${API}/releases/tags/${VERSION}" -H "${AUTH}" \
|
||||
| python3 -c "import sys, json; print(json.load(sys.stdin).get('id', ''))" || true)
|
||||
|
||||
if [ -z "${RELEASE_ID}" ]; then
|
||||
echo "Creating release ${VERSION}"
|
||||
RELEASE_ID=$(curl -f -X POST "${API}/releases" \
|
||||
-H "${AUTH}" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "{\"tag_name\": \"${VERSION}\", \"name\": \"${VERSION}\", \"target_commitish\": \"${{ gitea.sha }}\"}" \
|
||||
| python3 -c "import sys, json; print(json.load(sys.stdin)['id'])")
|
||||
else
|
||||
echo "Using existing release ${RELEASE_ID}"
|
||||
fi
|
||||
|
||||
for ASSET in dist/*; do
|
||||
NAME=$(basename "${ASSET}")
|
||||
OLD_ID=$(curl -sf "${API}/releases/${RELEASE_ID}/assets" -H "${AUTH}" \
|
||||
| python3 -c "import sys, json; print(next((a['id'] for a in json.load(sys.stdin) if a['name'] == '${NAME}'), ''))" || true)
|
||||
if [ -n "${OLD_ID}" ]; then
|
||||
echo "Deleting existing asset ${NAME} (id ${OLD_ID})"
|
||||
curl -f -X DELETE "${API}/releases/assets/${OLD_ID}" -H "${AUTH}"
|
||||
fi
|
||||
echo "Uploading ${NAME}"
|
||||
curl -f -X POST "${API}/releases/${RELEASE_ID}/assets?name=${NAME}" \
|
||||
-H "${AUTH}" \
|
||||
-F "attachment=@${ASSET}"
|
||||
done
|
||||
|
||||
echo "Released ${VERSION} with $(ls dist | wc -l) asset(s)"
|
||||
Reference in New Issue
Block a user