heliophysicsPy / pyhc-core

A package to install all PyHC core packages.
https://pypi.org/project/pyhc-core/
MIT License
1 stars 0 forks source link

Set up publishing to PyPI with GitHub Actions #7

Closed sapols closed 3 months ago

sapols commented 5 months ago

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

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