From b4c4cec8830b775b9358e579c2d633be9d77b59d Mon Sep 17 00:00:00 2001 From: Colin Powell Date: Sun, 20 Sep 2026 11:18:24 -0400 Subject: [PATCH] Add Gitea Actions release workflow --- .gitea/workflows/release.yml | 70 ++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 .gitea/workflows/release.yml diff --git a/.gitea/workflows/release.yml b/.gitea/workflows/release.yml new file mode 100644 index 0000000..32c2174 --- /dev/null +++ b/.gitea/workflows/release.yml @@ -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)"