Skip to content

Commit

Permalink
Merge pull request #7 from i-dot-ai/EN-623/package_hosting
Browse files Browse the repository at this point in the history
Add PyPI package hosting
  • Loading branch information
RyanWhite25 authored Oct 16, 2024
2 parents 405e615 + 9912cac commit c33d64f
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 39 deletions.
82 changes: 82 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
---
name: Publish
run-name: Publish ${{ inputs.tag }} to PyPI ${{ inputs.tag }}

on:
workflow_call:
inputs:
stage:
type: string
required: true
tag:
type: string
required: true

jobs:
build-and-publish:
runs-on: ubuntu-latest
environment: release
permissions:
id-token: write
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install poetry
run: pipx install poetry

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: "poetry"

- name: Install dependencies
run: |
poetry env use "3.12"
poetry install
- name: Bump version number
run: poetry version ${{ inputs.tag }}

- name: Build package
run: poetry build

- name: Publish to test pypi
if: inputs.stage == 'test'
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: 'https://test.pypi.org/legacy/'

- name: Publish to prod pypi
if: inputs.stage == 'prod'
uses: pypa/gh-action-pypi-publish@release/v1

determine-success:
needs:
- build-and-publish
runs-on: ubuntu-latest
if: always()
outputs:
success: ${{ steps.success.outputs.success }}
steps:
- id: success
run: |
if [[ "${{ needs.build-and-publish.result }}" == "success" ]]; then
echo "success=true" >> $GITHUB_OUTPUT
else
echo "success=false" >> $GITHUB_OUTPUT
fi
notify-slack:
if: inputs.stage == 'prod' && always()
uses: i-dot-ai/i-dot-ai-core-github-actions/.github/workflows/slack-notify.yml@main
needs:
- build-and-publish
- determine-success
with:
WORKFLOW_PASSED: ${{ needs.determine-success.outputs.success == 'true' }}
SUCCESS_PAYLOAD: "{\"blocks\":[{\"type\":\"header\",\"text\":{\"type\":\"plain_text\",\"text\":\":airplane: ${{ github.repository }} - Successfully deployed ${{ inputs.tag }} :large_green_circle:\"}},{\"type\":\"section\",\"text\":{\"type\":\"mrkdwn\",\"text\":\"Package published to PyPi successfully\"}}]}"
FAILURE_PAYLOAD: "{\"blocks\":[{\"type\":\"header\",\"text\":{\"type\":\"plain_text\",\"text\":\":x: ${{ github.repository }} - Failed to deploy ${{ inputs.tag }} :x:\"}},{\"type\":\"section\",\"text\":{\"type\":\"mrkdwn\",\"text\":\"Failed to publish package to PyPi\"}}]}"
secrets:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
37 changes: 0 additions & 37 deletions .github/workflows/pypi_publish.yml

This file was deleted.

15 changes: 15 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
name: Release
run-name: Release version ${{ github.event.release.tag_name }}

on:
release:
types: [released]

jobs:
publish:
name: Publish
uses: i-dot-ai/cruft-iai/.github/workflows/publish.yml@main
with:
stage: prod
tag: ${{ github.event.release.tag_name }}
12 changes: 11 additions & 1 deletion .github/workflows/run_tests.yml → .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
name: Run tests
on:
push:
workflow_call:

jobs:
test:
test-code:
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -30,3 +32,11 @@ jobs:
- name: Run Checks
run: |
bash scripts/test.sh --ci
test-publish:
needs:
- test-code
uses: i-dot-ai/cruft-iai/.github/workflows/publish.yml@main
with:
stage: test
tag: "0.0.0"
11 changes: 10 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
[tool.poetry]
name = "cruft-iai"
version = "0.0.0"
description = "Allows you to maintain all the necessary cruft for packaging and building projects separate from the code you intentionally write. Built on-top of CookieCutter."
description = "A fork of cruft maintained by i.AI. Allows you to maintain all the necessary cruft for packaging and building projects separate from the code you intentionally write. Built on-top of CookieCutter."
authors = ["Timothy Crosley <[email protected]>", "Sambhav Kothari <[email protected]>"]
maintainers = ["i.AI <[email protected]>"]
license = "MIT"
readme = "README.md"
packages = [{ include = "cruft" }]
classifiers = [
"Development Status :: 2 - Pre-Alpha",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3.12",
]

[tool.poetry.dependencies]
python = ">=3.12"
Expand Down

0 comments on commit c33d64f

Please sign in to comment.