blob: b2cfb54a8ea8c7b3243bc5144254695b69ce6dda [file]
name: release
# Releases are triggered manually by pushing a git tag:
# - v1.6.0-rc1 -> GitHub pre-release (the candidate used for the Apache vote)
# - v1.6.0 -> GitHub release + publish to PyPI
on:
push:
tags:
- "v*"
permissions:
contents: write
jobs:
release:
name: Release ${{ github.ref_name }}
if: github.repository == 'apache/casbin-python-redis-adapter'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Resolve version from tag
id: version
run: |
set -euo pipefail
TAG="${GITHUB_REF_NAME}"
# v1.6.0-rc1 -> 1.6.0-rc1, v1.6.0 -> 1.6.0
VERSION="${TAG#v}"
if ! echo "$VERSION" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+(-rc[0-9]+)?$'; then
echo "::error::Tag $TAG is not vX.Y.Z or vX.Y.Z-rcN."
exit 1
fi
# The release candidate is voted on as the final version, so strip "-rcN".
BASE_VERSION="${VERSION%%-rc*}"
if [ "$VERSION" != "$BASE_VERSION" ]; then
PRERELEASE=true
else
PRERELEASE=false
fi
# The source release must describe its own version, so setup.cfg
# has to be bumped and committed before the tag is pushed.
PROJECT_VERSION="$(python -c "import configparser; c = configparser.ConfigParser(); c.read('setup.cfg'); print(c['metadata']['version'])")"
if [ "$PROJECT_VERSION" != "$BASE_VERSION" ]; then
echo "::error::tag $TAG expects version $BASE_VERSION in setup.cfg, found $PROJECT_VERSION"
exit 1
fi
echo "base_version=$BASE_VERSION" >> "$GITHUB_OUTPUT"
echo "prerelease=$PRERELEASE" >> "$GITHUB_OUTPUT"
- name: Build Apache source release
env:
BASE_VERSION: ${{ steps.version.outputs.base_version }}
run: |
set -euo pipefail
NAME="apache-casbin-python-redis-adapter-${BASE_VERSION}-incubating-src"
git archive --format=tar.gz --prefix="${NAME}/" -o "${NAME}.tar.gz" HEAD
sha512sum "${NAME}.tar.gz" > "${NAME}.tar.gz.sha512"
- name: Build Python distributions
if: steps.version.outputs.prerelease == 'false'
run: |
python -m pip install --upgrade build twine
python -m build
twine check dist/*
- name: Create GitHub release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAG: ${{ github.ref_name }}
PRERELEASE: ${{ steps.version.outputs.prerelease }}
run: |
set -euo pipefail
if [ "$PRERELEASE" = "true" ]; then
FLAGS="--prerelease"
else
FLAGS="--latest"
fi
gh release create "$TAG" \
--title "$TAG" \
--generate-notes \
$FLAGS \
apache-casbin-python-redis-adapter-*-incubating-src.tar.gz \
apache-casbin-python-redis-adapter-*-incubating-src.tar.gz.sha512
- name: Publish to PyPI
if: steps.version.outputs.prerelease == 'false'
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
run: twine upload dist/*