cyrusyc's picture
change .pypirc path
2449c37
raw
history blame
2.72 kB
name: Publish Release
on:
push:
branches:
- main # Trigger on push to main branch
permissions:
contents: write # Ensure write access to push tags
jobs:
release:
name: Create GitHub Release
runs-on: ubuntu-latest
steps:
# Step 1: Checkout the code
- name: Checkout code
uses: actions/checkout@v3
# Step 2: Set up Python
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
# Step 3: Install dependencies
- name: Install dependencies
run: pip install toml
# Step 4: Extract version from pyproject.toml
- name: Extract version
id: get_version
run: |
VERSION=$(python -c "import toml; print(toml.load('pyproject.toml')['project']['version'])")
echo "VERSION=$VERSION" >> $GITHUB_ENV
# Step 5: Check if tag exists on remote
- name: Check if tag exists on remote
id: check_tag
run: |
if git ls-remote --tags origin | grep "refs/tags/v${{ env.VERSION }}"; then
echo "Tag v${{ env.VERSION }} already exists on remote."
echo "tag_exists=true" >> $GITHUB_ENV
else
echo "tag_exists=false" >> $GITHUB_ENV
fi
# Step 6: Create and push a new tag (if it doesn't exist)
- name: Create Git tag
if: env.tag_exists == 'false'
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git tag -a "v${{ env.VERSION }}" -m "Release v${{ env.VERSION }}"
git push origin "v${{ env.VERSION }}"
# Step 7: Create GitHub release (if tag didn't exist)
- name: Create GitHub Release
if: env.tag_exists == 'false'
uses: softprops/action-gh-release@v1
with:
tag_name: "v${{ env.VERSION }}"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
pypi:
name: Publish to PyPI
runs-on: ubuntu-latest
needs: release # This job runs after the release job
steps:
# Step 1: Checkout the code
- name: Checkout code
uses: actions/checkout@v3
# Step 2: Set up Python
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
# Step 3: Install Flit
- name: Install Flit
run: pip install flit
# Step 4: Create .pypirc file
- name: Create .pypirc file
run: |
echo "[pypi]" > ~/.pypirc
echo "username = __token__" >> ~/.pypirc
echo "password = ${{ secrets.PYPI_API_TOKEN }}" >> ~/.pypirc
# Step 5: Build and publish package
- name: Build and Publish Package
run: |
flit build
flit publish