2023-02-15 02:47:42 +01:00
|
|
|
name: pypi
|
2022-08-03 20:57:27 +02:00
|
|
|
|
|
|
|
on:
|
2022-08-15 05:47:36 +02:00
|
|
|
push:
|
|
|
|
tags:
|
2023-01-05 00:46:48 +01:00
|
|
|
- "*"
|
2022-08-03 20:57:27 +02:00
|
|
|
branches:
|
|
|
|
- 'master'
|
|
|
|
paths:
|
2023-02-14 21:50:51 +01:00
|
|
|
- src/khoj/**
|
2022-08-04 02:49:32 +02:00
|
|
|
- setup.py
|
2023-02-15 02:47:42 +01:00
|
|
|
- .github/workflows/pypi.yml
|
2023-02-14 20:47:25 +01:00
|
|
|
pull_request:
|
|
|
|
branches:
|
|
|
|
- 'master'
|
|
|
|
paths:
|
2023-02-14 21:50:51 +01:00
|
|
|
- src/khoj/**
|
2023-02-14 20:47:25 +01:00
|
|
|
- setup.py
|
2023-02-15 02:47:42 +01:00
|
|
|
- .github/workflows/pypi.yml
|
2022-08-03 20:57:27 +02:00
|
|
|
|
|
|
|
jobs:
|
2022-08-04 02:49:32 +02:00
|
|
|
publish:
|
2023-02-15 02:47:42 +01:00
|
|
|
name: Publish Python Package to PyPI
|
2022-08-03 20:57:27 +02:00
|
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
|
|
- uses: actions/checkout@v3
|
2023-02-15 02:47:42 +01:00
|
|
|
with:
|
|
|
|
fetch-depth: 0
|
2022-08-03 20:57:27 +02:00
|
|
|
|
|
|
|
- name: Set up Python 3.10
|
|
|
|
uses: actions/setup-python@v4
|
|
|
|
with:
|
|
|
|
python-version: '3.10'
|
|
|
|
|
2022-08-03 21:37:16 +02:00
|
|
|
- name: Install Dependencies
|
2022-08-03 20:57:27 +02:00
|
|
|
run: |
|
|
|
|
python -m pip install --upgrade pip
|
2023-02-14 20:41:33 +01:00
|
|
|
pip install build twine check-wheel-contents
|
2022-08-03 21:37:16 +02:00
|
|
|
|
|
|
|
- name: Install Application
|
|
|
|
run: |
|
2022-08-03 20:57:27 +02:00
|
|
|
pip install --upgrade .
|
|
|
|
|
2023-02-15 02:47:42 +01:00
|
|
|
- name: 📝 Set Pre-Release Version for Master
|
2022-08-04 03:40:35 +02:00
|
|
|
if: github.ref == 'refs/heads/master'
|
2022-08-04 02:18:51 +02:00
|
|
|
run: |
|
2022-08-19 20:00:12 +02:00
|
|
|
# Set Pre-Release Version
|
2022-08-04 03:40:35 +02:00
|
|
|
sed -E -i "s/version=(.*)',/version=\1a$(date +%s)',/g" setup.py
|
2022-08-19 20:00:12 +02:00
|
|
|
|
2023-02-15 02:47:42 +01:00
|
|
|
- name: 📝 Set Development Version for PR
|
|
|
|
if: github.event_name == 'pull_request'
|
2022-08-04 02:49:32 +02:00
|
|
|
env:
|
|
|
|
PULL_REQUEST_NUMBER: ${{ github.event.number }}
|
|
|
|
run: |
|
2022-08-19 20:00:12 +02:00
|
|
|
# Set Development Release Version
|
2022-08-04 03:15:16 +02:00
|
|
|
sed -E -i "s/version=(.*)',/version=\1.dev$PULL_REQUEST_NUMBER$(date +%s)',/g" setup.py
|
2022-08-19 20:00:12 +02:00
|
|
|
|
2023-02-15 02:47:42 +01:00
|
|
|
- name: ⚙️ Build Python Package
|
|
|
|
run: |
|
2022-08-19 20:00:12 +02:00
|
|
|
# Setup Environment for Reproducible Builds
|
|
|
|
export PYTHONHASHSEED=42
|
|
|
|
export SOURCE_DATE_EPOCH=$(git log -1 --pretty=%ct)
|
|
|
|
|
2023-02-14 20:41:33 +01:00
|
|
|
# Build PyPi Package
|
2022-08-04 02:49:32 +02:00
|
|
|
rm -rf dist
|
|
|
|
python -m build
|
2023-02-14 20:41:33 +01:00
|
|
|
|
2023-02-15 02:47:42 +01:00
|
|
|
- name: 👀 Validate Python Package
|
|
|
|
run: |
|
2023-02-14 20:41:33 +01:00
|
|
|
# Validate PyPi Package
|
|
|
|
check-wheel-contents dist/*.whl
|
2022-08-04 02:49:32 +02:00
|
|
|
twine check dist/*
|
2023-02-14 20:41:33 +01:00
|
|
|
|
2023-02-15 02:47:42 +01:00
|
|
|
- name: ⏫ Upload Python Package Artifacts
|
|
|
|
- uses: actions/upload-artifact@v3
|
|
|
|
with:
|
|
|
|
path: dist/*
|
|
|
|
|
|
|
|
- name: 📦 Publish Python Package from Master or Release to PyPI
|
|
|
|
if: startsWith(github.ref, 'refs/tags') || github.ref == 'refs/heads/master'
|
|
|
|
uses: pypa/gh-action-pypi-publish@release/v1.6.4
|
|
|
|
with:
|
|
|
|
password: ${{ secrets.PYPI_API_KEY }}
|
|
|
|
|
|
|
|
- name: 📦 Publish Python Package from Repo PR to Test PyPI
|
|
|
|
if: ${{ github.event.pull_request.head.repo.full_name == github.repository }}
|
|
|
|
uses: pypa/gh-action-pypi-publish@release/v1.6.4
|
|
|
|
with:
|
|
|
|
password: ${{ secrets.PYPI_API_KEY }}
|
|
|
|
repository_url: https://test.pypi.org/legacy/
|