Debugging #11
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Publish Python Package | |
on: | |
push: | |
branches: | |
- fix/add-publish-package-workflow | |
workflow_dispatch: | |
permissions: | |
contents: write | |
packages: write | |
jobs: | |
build-and-publish: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.x' | |
- name: Install dependencies | |
run: | | |
pip install --upgrade setuptools wheel twine | |
- name: Extract version from setup.py | |
id: get_version | |
run: | | |
version=$(python -c "import re; print(re.search(r'version=\\'([0-9]+\\.[0-9]+\\.[0-9]+)\\'', open('setup.py').read()).group(1))") | |
echo "version=$version" >> $GITHUB_ENV | |
- name: Build wheel | |
run: | | |
python setup.py bdist_wheel | |
- name: Check if Git tag exists | |
id: check_tag | |
run: | | |
git fetch --tags | |
if git rev-parse "v${{ env.version }}" >/dev/null 2>&1; then | |
echo "Tag Exists!" | |
echo "TAG_EXISTS=1" >> $GITHUB_ENV | |
else | |
echo "Tag does not exist!" | |
echo "TAG_EXISTS=0" >> $GITHUB_ENV | |
fi | |
- name: Delete existing Git tag (if exists) | |
if: env.TAG_EXISTS == '1' | |
run: | | |
git tag -d "v${{ env.version }}" | |
git push origin --delete "v${{ env.version }}" | |
env: | |
TAG_EXISTS: ${{ env.TAG_EXISTS }} | |
- name: Create Git tag | |
run: | | |
git config user.name "github-actions[bot]" | |
git config user.email "github-actions[bot]@users.noreply.github.com" | |
git tag -a "v${{ env.version }}" -m "Release v${{ env.version }}" | |
git push origin fix/add-publish-package-workflow --tags | |
- name: Release | |
uses: softprops/action-gh-release@v2 | |
if: startsWith(github.ref, 'refs/tags/') | |
with: | |
files: dist/geoip2fast-${{ env.version }}-py3-none-any.whl |