Skip to content

Commit 8a8d3e9

Browse files
add PyPI publishing workflow
1 parent 81b472b commit 8a8d3e9

File tree

3 files changed

+71
-24
lines changed

3 files changed

+71
-24
lines changed
Lines changed: 68 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,80 @@
1-
name: Release to PyPI
1+
name: Publish to PyPI
22

33
on:
4-
push:
5-
tags:
6-
- '*'
4+
release:
5+
types: [published]
6+
workflow_dispatch:
77

88
jobs:
9-
deploy:
10-
9+
publish:
1110
runs-on: ubuntu-latest
11+
permissions:
12+
contents: read
13+
id-token: write
1214

1315
steps:
14-
- uses: actions/checkout@v2
15-
- name: Set up Python 3.9
16-
uses: actions/setup-python@v2
16+
- name: Checkout repository
17+
uses: actions/checkout@v4
18+
19+
- name: Set up Python
20+
uses: actions/setup-python@v5
1721
with:
18-
python-version: 3.9
19-
- name: Install dependencies for testing
22+
python-version: "3.11"
23+
24+
- name: Install build and test dependencies
2025
run: |
21-
pip install pytest
22-
pip install zarr
23-
pip install setuptools wheel twine
24-
pip install .
25-
- name: Test core with pytest
26+
python -m pip install --upgrade pip
27+
python -m pip install hatch twine
28+
29+
- name: Run tests
30+
run: hatch run test:pytest -v
31+
32+
- name: Build artifacts
33+
run: hatch build
34+
35+
- name: Configure publish credentials
36+
id: publish-config
37+
env:
38+
EVENT_NAME: ${{ github.event_name }}
39+
RELEASE_NAME: ${{ github.event.release.name }}
40+
DEFAULT_USERNAME: ${{ secrets.twine_username }}
41+
DEFAULT_PASSWORD: ${{ secrets.twine_password }}
42+
TEST_USERNAME: ${{ secrets.twine_test_username }}
43+
TEST_PASSWORD: ${{ secrets.twine_test_password }}
2644
run: |
27-
pytest -v
28-
- name: Publish on PyPI
45+
set -euo pipefail
46+
47+
repository="pypi"
48+
username="$DEFAULT_USERNAME"
49+
password="$DEFAULT_PASSWORD"
50+
51+
if [[ "${EVENT_NAME}" == "release" && -n "${RELEASE_NAME}" ]]; then
52+
if [[ "${RELEASE_NAME}" =~ ^[Tt]est ]]; then
53+
if [[ -z "${TEST_USERNAME}" || -z "${TEST_PASSWORD}" ]]; then
54+
echo "::error::Test PyPI credentials are required for releases starting with 'Test'"
55+
exit 1
56+
fi
57+
repository="testpypi"
58+
username="$TEST_USERNAME"
59+
password="$TEST_PASSWORD"
60+
fi
61+
fi
62+
63+
if [[ -z "${username}" || -z "${password}" ]]; then
64+
echo "::error::PyPI credentials are not configured"
65+
exit 1
66+
fi
67+
68+
{
69+
echo "repository=${repository}"
70+
echo "username=${username}"
71+
echo "password=${password}"
72+
} >> "$GITHUB_OUTPUT"
73+
74+
- name: Publish distribution to PyPI
2975
env:
30-
TWINE_USERNAME: __token__
31-
TWINE_PASSWORD: ${{ secrets.AIND_PYPI_TOKEN }}
76+
TWINE_USERNAME: ${{ steps.publish-config.outputs.username }}
77+
TWINE_PASSWORD: ${{ steps.publish-config.outputs.password }}
78+
TWINE_REPOSITORY: ${{ steps.publish-config.outputs.repository }}
3279
run: |
33-
python setup.py sdist
34-
twine upload dist/*
80+
twine upload --repository "${TWINE_REPOSITORY}" dist/*

LICENSE

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
MIT License
22

3-
Copyright (c) 2024, Allen Institute for Neural Dynamics, DataJoint Inc, CatalystNeuro, and contributors
3+
Copyright (c) 2024, Allen Institute for Neural Dynamics, DataJoint Inc., CatalystNeuro, and contributors
4+
Copyright (c) 2025, DataJoint Inc.
45

56
Permission is hereby granted, free of charge, to any person obtaining a copy
67
of this software and associated documentation files (the "Software"), to deal

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,4 +206,4 @@ checks = [
206206
]
207207

208208
[tool.codespell]
209-
ignore-words-list = "Nd"
209+
ignore-words-list = "Nd"

0 commit comments

Comments
 (0)