Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set up publishing to PyPI with GitHub Actions #7

Open
sapols opened this issue Jun 20, 2024 · 0 comments
Open

Set up publishing to PyPI with GitHub Actions #7

sapols opened this issue Jun 20, 2024 · 0 comments

Comments

@sapols
Copy link
Contributor

sapols commented Jun 20, 2024

We can make this a one-button-click thing with GitHub Actions.

Instructions according to ChatGPT:

Automate Publishing to PyPI with GitHub Actions

Overview

Set up GitHub Actions to automate the process of building and publishing the pyhc-core package to PyPI whenever a new release is created. This will make publishing a new version as simple as clicking a button.

Steps

Step 1: Create a GitHub Actions Workflow

  1. Create a new workflow file:

    • Create a file at .github/workflows/publish.yml in your repository.
  2. Add the following content to the workflow file:

    name: Publish to PyPI
    
    on:
      release:
        types: [created]
    
    jobs:
      build-and-publish:
        runs-on: ubuntu-latest
    
        steps:
        - uses: actions/checkout@v2
    
        - name: Set up Python
          uses: actions/setup-python@v2
          with:
            python-version: '3.x'
    
        - name: Install dependencies
          run: |
            python -m pip install --upgrade pip
            pip install build twine
    
        - name: Build package
          run: python -m build
    
        - name: Publish package to PyPI
          env:
            TWINE_USERNAME: __token__
            TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
          run: python -m twine upload dist/*

Step 2: Create a PyPI API Token

  1. Log in to your PyPI account:

  2. Create an API token:

    • Click on your username in the top-right corner and select "Account settings".
    • Scroll down to the "API tokens" section.
    • Click "Add API token".
    • Provide a name for your token (e.g., "GitHub Actions token").
    • Set the scope to "Entire account" or specify a project if you want to limit the token's access.
    • Copy the generated token.

Step 3: Add the API Token to GitHub Secrets

  1. Go to your GitHub repository:

    • Navigate to the repository where you want to set up the workflow.
  2. Go to Settings:

    • Click on "Settings" in the repository menu.
  3. Add a new secret:

    • In the "Secrets and variables" section, click on "Actions".
    • Click on "New repository secret".
    • Name the secret PYPI_API_TOKEN.
    • Paste the API token you copied from PyPI.
    • Click "Add secret".

Step 4: Create a New Release

  1. Go to the Releases page of your repository:

    • Click on "Releases" in the right-hand sidebar of your repository's main page.
  2. Create a new release:

    • Click on "Draft a new release".
    • Fill in the "Tag version" and "Release title".
    • Add any release notes if needed.
    • Click "Publish release".

What Happens Next

  • When you publish a new release, the GitHub Actions workflow will be triggered.
  • The workflow will check out the code, set up Python, install the necessary build tools, build the package, and upload it to PyPI using the provided API token.

This setup ensures that publishing a new version to PyPI is as simple as creating a new release on GitHub.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant