From 0e2e1ba14e0dfdbf21e2a512159682cfe6995660 Mon Sep 17 00:00:00 2001
From: jtyoung84 <104453205+jtyoung84@users.noreply.github.com>
Date: Wed, 27 Mar 2024 18:00:57 -0700
Subject: [PATCH] ci: publish to pypi (#2)

---
 .github/workflows/init.yml            | 52 ---------------------------
 .github/workflows/tag_and_publish.yml | 21 +++++++++++
 2 files changed, 21 insertions(+), 52 deletions(-)
 delete mode 100644 .github/workflows/init.yml

diff --git a/.github/workflows/init.yml b/.github/workflows/init.yml
deleted file mode 100644
index 0336013..0000000
--- a/.github/workflows/init.yml
+++ /dev/null
@@ -1,52 +0,0 @@
-# Workflow runs only once when the template is first used.
-# File can be safely deleted after repo is initialized.
-name: Initialize repository
-on:
-  push:
-    branches:
-      - main
-
-jobs:
-  initialize-package:
-    name: Initialize the package
-    if: ${{github.event.repository.name != 'aind-library-template'}}
-    runs-on: ubuntu-latest
-    env:
-      REPO_NAME: ${{ github.event.repository.name }}
-      GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
-    steps:
-    - name: Checkout
-      uses: actions/checkout@v3
-    - name: Rename package
-      run: |
-        pkg_name=$(echo "${REPO_NAME}" | tr - _)
-        current_description='description = "Prints messages to stdout. Simple boilerplate for libraries."'
-        new_description='description = "Generated from aind-library-template"'
-        readme_description='Template for a minimal, basic repository for an AIND library.'
-        new_readme_description='Generated from aind-library-template'
-        echo "Package Name ${pkg_name}"
-        mkdir src/${pkg_name}
-        touch src/${pkg_name}/__init__.py
-        echo '"""Init package"""' >> src/${pkg_name}/__init__.py
-        echo '__version__ = "0.0.0"' >> src/${pkg_name}/__init__.py
-        sed -i "s/aind_library_template/${pkg_name}/" pyproject.toml
-        sed -i "s/aind-library-template/${REPO_NAME}/" pyproject.toml
-        sed -i "s/aind_library_template/${pkg_name}/" doc_template/source/conf.py
-        sed -i "s/${current_description}/${new_description}/" pyproject.toml
-        sed -i "/pandas/d" pyproject.toml
-        sed -i "s/aind-library-template/${REPO_NAME}/" README.md
-        sed -i "s/${readme_description}/${new_readme_description}/" README.md
-    - name: Commit changes
-      uses: EndBug/add-and-commit@v9
-      with:
-        default_author: github_actions
-        message: "ci: version bump [skip actions]"
-        add: '["pyproject.toml", "README.md", "src/*", "doc_template/source/conf.py"]'
-        remove: '["-r src/aind_library_template", "tests/test_message_handler.py"]'
-    - name: Add first tag
-      run: |
-        git tag v0.0.0
-        git push origin v0.0.0
-    - name: Disable workflow
-      run: |
-        gh workflow disable -R $GITHUB_REPOSITORY "${{ github.workflow }}"
diff --git a/.github/workflows/tag_and_publish.yml b/.github/workflows/tag_and_publish.yml
index 1bc02e0..ff6a30f 100644
--- a/.github/workflows/tag_and_publish.yml
+++ b/.github/workflows/tag_and_publish.yml
@@ -88,3 +88,24 @@ jobs:
           tags: |
             ghcr.io/allenneuraldynamics/aind-airflow-jobs:${{ needs.tag.outputs.new_version }}
             ghcr.io/allenneuraldynamics/aind-airflow-jobs:latest
+
+  pypi:
+    runs-on: ubuntu-latest
+    needs: tag
+    steps:
+      - uses: actions/checkout@v3
+      - name: Pull latest changes
+        run: git pull origin main
+      - name: Set up Python 3.10
+        uses: actions/setup-python@v3
+        with:
+          python-version: '3.10'
+      - name: Install dependencies
+        run: |
+          pip install --upgrade setuptools wheel twine build
+          python -m build
+          twine check dist/*
+      - name: Publish on PyPI
+        uses: pypa/gh-action-pypi-publish@release/v1.5
+        with:
+          password: ${{ secrets.AIND_PYPI_TOKEN }}