Skip to content

Upload Python Package #58

Upload Python Package

Upload Python Package #58

name: Upload Python Package
on:
workflow_dispatch: {}
schedule:
- cron: '0 5 * * 0'
permissions:
contents: read
jobs:
check-versions:
runs-on: ubuntu-latest
outputs:
update: ${{ steps.check.outputs.update }}
steps:
- uses: actions/checkout@v4
- name: Check versions
id: check
run: |
v1=$(curl https://pypi.org/pypi/ast-tool-py/json | jq '.info | .version')
echo "Published version: $v1"
v2=$(cat ast-tool-py/src/main.py | grep "^__version__" | sed -e 's/__version__ = //')
echo "Current version: $v2"
if [ "$v1" != "$v2" ]; then
echo "update=proceed" | tee -a "$GITHUB_OUTPUT";
else
echo "update=skip" | tee -a "$GITHUB_OUTPUT";
fi
release-build:
if: ${{ needs.check-versions.outputs.update == 'proceed' }}
runs-on: ubuntu-latest
needs:
- check-versions
steps:
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@master
- name: Build release distributions
run: |
cd ast-tool-py
nix-shell
python -m pip install build
python -m build
- name: Upload distributions
uses: actions/upload-artifact@v4
with:
name: release-dists
path: ast-tool-py/dist/
pypi-publish:
runs-on: ubuntu-latest
needs:
- release-build
permissions:
id-token: write
steps:
- name: Retrieve release distributions
uses: actions/download-artifact@v4
with:
name: release-dists
path: dist/
- name: Publish release distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://upload.pypi.org/legacy/
packages-dir: dist/